Package tenapull.util

Class ReverseMap<K,​V>

java.lang.Object
tenapull.util.ReverseMap<K,​V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
java.util.Map<K,​java.util.Set<V>>

public class ReverseMap<K,​V>
extends java.lang.Object
implements java.util.Map<K,​java.util.Set<V>>
A map which reverses the roles of key and value, holding a set of "keys" as the value for each "value" key. Used by InstancesTracker to track the relationship between keys and instances
  • Nested Class Summary

    Nested classes/interfaces inherited from interface java.util.Map

    java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
  • Constructor Summary

    Constructors 
    Constructor Description
    ReverseMap()
    Instantiates a new Reverse map.
    ReverseMap​(java.lang.Class<? extends java.util.Map> mapType, java.lang.Class<? extends java.util.Set> setType)
    Instantiates a new Reverse map using the specified types for the key sets and backing map, e.g.
    ReverseMap​(java.lang.Class<? extends java.util.Map> mapType, java.lang.Class<? extends java.util.Set> setType, java.util.Map<V,​K> map)
    Instantiates a new Reverse map, copying the provided map, and using the specified types for the key sets and backing map, e.g.
    ReverseMap​(java.util.Map<V,​K> map)
    Instantiates a new Reverse map using the provided map
  • Method Summary

    Modifier and Type Method Description
    void clear()  
    boolean containsKey​(java.lang.Object key)  
    boolean containsValue​(java.lang.Object value)  
    java.util.Set<java.util.Map.Entry<K,​java.util.Set<V>>> entrySet()  
    java.util.Set<V> get​(java.lang.Object key)  
    boolean isEmpty()  
    java.util.Set<K> keySet()  
    protected java.util.Set<V> makeValueSet()
    Makes a set for the values
    java.util.Set<V> put​(K key, java.util.Set<V> value)  
    void putAll​(java.util.Map<? extends K,​? extends java.util.Set<V>> m)  
    void putAllForward​(java.util.Map<K,​V> map)
    Like a normal map put
    void putAllReverse​(java.util.Map<V,​K> map)
    Reverses the provided map, putting all of its values as keys into this map, and their respective keys as part of the value set
    void putOne​(K key, V value)
    Puts a single entry into the value set for the provided key
    java.util.Set<V> remove​(java.lang.Object key)  
    int size()  
    java.util.Collection<java.util.Set<V>> values()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Map

    compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
  • Constructor Details

    • ReverseMap

      public ReverseMap()
      Instantiates a new Reverse map.
    • ReverseMap

      public ReverseMap​(java.util.Map<V,​K> map)
      Instantiates a new Reverse map using the provided map
      Parameters:
      map - the map to copy
    • ReverseMap

      public ReverseMap​(java.lang.Class<? extends java.util.Map> mapType, java.lang.Class<? extends java.util.Set> setType) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
      Instantiates a new Reverse map using the specified types for the key sets and backing map, e.g. if you want to specify a TreeMap/TreeSet, or WeakHashMap, etc...
      Parameters:
      mapType - the map type
      setType - the set type
      Throws:
      java.lang.NoSuchMethodException - if there are problem instantiating the mapType or setType
      java.lang.reflect.InvocationTargetException - if there are problem instantiating the mapType or setType
      java.lang.InstantiationException - if there are problem instantiating the mapType or setType
      java.lang.IllegalAccessException - if there are problem instantiating the mapType or setType
    • ReverseMap

      public ReverseMap​(java.lang.Class<? extends java.util.Map> mapType, java.lang.Class<? extends java.util.Set> setType, java.util.Map<V,​K> map) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
      Instantiates a new Reverse map, copying the provided map, and using the specified types for the key sets and backing map, e.g. if you want to specify a TreeMap/TreeSet, or WeakHashMap, etc...
      Parameters:
      mapType - the map type
      setType - the set type
      map - the map to copy
      Throws:
      java.lang.NoSuchMethodException - if there are problem instantiating the mapType or setType
      java.lang.reflect.InvocationTargetException - if there are problem instantiating the mapType or setType
      java.lang.InstantiationException - if there are problem instantiating the mapType or setType
      java.lang.IllegalAccessException - if there are problem instantiating the mapType or setType
  • Method Details

    • makeValueSet

      protected java.util.Set<V> makeValueSet()
      Makes a set for the values
      Returns:
      the set
    • putOne

      public void putOne​(K key, V value)
      Puts a single entry into the value set for the provided key
      Parameters:
      key - the key
      value - the value
    • putAllReverse

      public void putAllReverse​(java.util.Map<V,​K> map)
      Reverses the provided map, putting all of its values as keys into this map, and their respective keys as part of the value set
      Parameters:
      map - the map to copy
    • putAllForward

      public void putAllForward​(java.util.Map<K,​V> map)
      Like a normal map put
      Parameters:
      map - the map to copy
    • size

      public int size()
      Specified by:
      size in interface java.util.Map<K,​V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface java.util.Map<K,​V>
    • containsKey

      public boolean containsKey​(java.lang.Object key)
      Specified by:
      containsKey in interface java.util.Map<K,​V>
    • containsValue

      public boolean containsValue​(java.lang.Object value)
      Specified by:
      containsValue in interface java.util.Map<K,​V>
    • get

      public java.util.Set<V> get​(java.lang.Object key)
      Specified by:
      get in interface java.util.Map<K,​V>
    • put

      public java.util.Set<V> put​(K key, java.util.Set<V> value)
      Specified by:
      put in interface java.util.Map<K,​V>
    • remove

      public java.util.Set<V> remove​(java.lang.Object key)
      Specified by:
      remove in interface java.util.Map<K,​V>
    • putAll

      public void putAll​(java.util.Map<? extends K,​? extends java.util.Set<V>> m)
      Specified by:
      putAll in interface java.util.Map<K,​V>
    • clear

      public void clear()
      Specified by:
      clear in interface java.util.Map<K,​V>
    • keySet

      public java.util.Set<K> keySet()
      Specified by:
      keySet in interface java.util.Map<K,​V>
    • values

      public java.util.Collection<java.util.Set<V>> values()
      Specified by:
      values in interface java.util.Map<K,​V>
    • entrySet

      public java.util.Set<java.util.Map.Entry<K,​java.util.Set<V>>> entrySet()
      Specified by:
      entrySet in interface java.util.Map<K,​V>