Package net.cscott.jutil
Class GenericMultiMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
net.cscott.jutil.AbstractMultiMap<K,V>
net.cscott.jutil.GenericMultiMap<K,V>
GenericMultiMap is a default implementation of a
MultiMap.
FSK: right now the implementation tries to preserve the property that if a key 'k' maps to an empty collection 'c' in some MultiMap 'mm', then users of 'mm' will not be able to see that 'k' is a member of the keySet for 'mm'. However, it does not preserve this property when mm.getValues(k) is used as a means to operate on the state of 'mm', and it is not clear to me whether one can even ensure that the property can be maintained if arbitrary operations on mm.getValues(k) are passed on to 'mm'.
- Author:
- Felix S. Klock II <pnkfelix@mit.edu>
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionGenericMultiMap(Map<? extends K, ? extends V> m) Creates aGenericMultiMapwith the mappings ofm, using aHashMapfor the map andHashSets for the value collections.Creates aMultiMapusing aHashMapfor the map and the specifiedCollectionFactoryto create the value collections.GenericMultiMap(GenericMultiMap<K, V> mm) Creates aGenericMultiMapwith the same mappings asmm, which uses the sameMapFactoryandCollectionFactoryasmm.GenericMultiMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf) Creates aMultiMapusing the specifiedMapFactoryto create the map and the specifiedCollectionFactoryto create the value collections.GenericMultiMap(MultiMap<? extends K, ? extends V> mm) Creates aGenericMultiMapwith the mappings ofmm, using aHashMapfor the map andHashSets for the value collections. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleanReturns true ifahas a mapping tobinthis.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()Returns a set view of the mappings contained in this map.Returns some arbitrary value from the set of values to which this map maps the specified key.Returns the collection of Values associated withkey.booleanisEmpty()keySet()Returns a set view of the keys in this map.Removes all mappings for this key from this map if present.booleanRemoves a mapping from key to value from this map if present.intsize()Returns the number of key-value mappings in this map (keys which map to multiple values count multiple times).values()Returns a collection view of the values contained in this map.Methods inherited from class net.cscott.jutil.AbstractMultiMap
add, addAll, addAll, equals, hashCode, put, putAll, removeAll, retainAll, toStringMethods inherited from class java.util.AbstractMap
cloneMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, replaceMethods inherited from interface net.cscott.jutil.MultiMap
replace, replaceAll
-
Constructor Details
-
GenericMultiMap
public GenericMultiMap()Creates aMultiMapusing aHashMapfor the map andHashSets for the value collections. To gain more control over the specific sets/map used in internal representation ofthis, use the more specificconstructorthat takesCollectionFactorys. -
GenericMultiMap
Creates aMultiMapusing aHashMapfor the map and the specifiedCollectionFactoryto create the value collections. -
GenericMultiMap
Creates aMultiMapusing the specifiedMapFactoryto create the map and the specifiedCollectionFactoryto create the value collections. -
GenericMultiMap
Creates aGenericMultiMapwith the same mappings asmm, which uses the sameMapFactoryandCollectionFactoryasmm. The copy has value collections of its own: a change to one map does not change the other.- Since:
- 2.0
-
GenericMultiMap
Creates aGenericMultiMapwith the mappings ofmm, using aHashMapfor the map andHashSets for the value collections.- Since:
- 2.0
-
GenericMultiMap
Creates aGenericMultiMapwith the mappings ofm, using aHashMapfor the map andHashSets for the value collections.- Since:
- 2.0
-
-
Method Details
-
size
public int size()Description copied from interface:MultiMapReturns the number of key-value mappings in this map (keys which map to multiple values count multiple times). -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMultiMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMultiMap<K,V>
-
get
Returns some arbitrary value from the set of values to which this map maps the specified key. Returnsnullif the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinquish these two cases. Note that if only theputmethod is used to modifythis, thengetwill operate just as it would in any otherMap. -
remove
Removes all mappings for this key from this map if present. Returns some previous value associated with specified key, ornullif there was no mapping for key.- Specified by:
removein interfaceMap<K,V> - Specified by:
removein interfaceMultiMap<K,V> - Specified by:
removein classAbstractMultiMap<K,V> - Returns:
- one of the previous values associated with the key,
or
nullifMapassociated no values with the key. Note that a zero-sized collection is not returned in the latter case, and that anullreturn value may be ambiguous if the map associatednullwith the given key (in addition to possibly other values).
-
remove
Removes a mapping from key to value from this map if present. Note that if multiple mappings from key to value are permitted by this map, then only one is guaranteed to be removed. Returns true ifthiswas modified as a result of this operation, else returns false. -
clear
public void clear() -
getValues
Returns the collection of Values associated withkey. Modifications to the returnedCollectionaffectthisas well. If there are no Values currently associated withkey, constructs a new, mutable, emptyCollectionand returns it. (MultiMapspecific operation). -
contains
-
keySet
Returns a set view of the keys in this map. -
values
Returns a collection view of the values contained in this map. -
entrySet
Returns a set view of the mappings contained in this map. This view is fully modifiable; the elements areMap.Entrys. The returned set is actually aMultiMapSet, from which you can get back the originalMultiMap.
-