Package tenapull.util
Class ReverseMap<K,V>
java.lang.Object
tenapull.util.ReverseMap<K,V>
- Type Parameters:
K- the key typeV- 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
-
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 voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(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)booleanisEmpty()java.util.Set<K>keySet()protected java.util.Set<V>makeValueSet()Makes a set for the valuesjava.util.Set<V>put(K key, java.util.Set<V> value)voidputAll(java.util.Map<? extends K,? extends java.util.Set<V>> m)voidputAllForward(java.util.Map<K,V> map)Like a normal map putvoidputAllReverse(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 setvoidputOne(K key, V value)Puts a single entry into the value set for the provided keyjava.util.Set<V>remove(java.lang.Object key)intsize()java.util.Collection<java.util.Set<V>>values()
-
Constructor Details
-
ReverseMap
public ReverseMap()Instantiates a new Reverse map. -
ReverseMap
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.IllegalAccessExceptionInstantiates 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 typesetType- the set type- Throws:
java.lang.NoSuchMethodException- if there are problem instantiating the mapType or setTypejava.lang.reflect.InvocationTargetException- if there are problem instantiating the mapType or setTypejava.lang.InstantiationException- if there are problem instantiating the mapType or setTypejava.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.IllegalAccessExceptionInstantiates 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 typesetType- the set typemap- the map to copy- Throws:
java.lang.NoSuchMethodException- if there are problem instantiating the mapType or setTypejava.lang.reflect.InvocationTargetException- if there are problem instantiating the mapType or setTypejava.lang.InstantiationException- if there are problem instantiating the mapType or setTypejava.lang.IllegalAccessException- if there are problem instantiating the mapType or setType
-
-
Method Details
-
makeValueSet
Makes a set for the values- Returns:
- the set
-
putOne
Puts a single entry into the value set for the provided key- Parameters:
key- the keyvalue- the value
-
putAllReverse
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
Like a normal map put- Parameters:
map- the map to copy
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
public boolean containsKey(java.lang.Object key) -
containsValue
public boolean containsValue(java.lang.Object value) -
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-