Package net.cscott.jutil
Class GenericInvertibleMultiMap<K,V>
java.lang.Object
net.cscott.jutil.GenericInvertibleMultiMap<K,V>
- All Implemented Interfaces:
Map<K,,V> InvertibleMap<K,,V> InvertibleMultiMap<K,,V> MultiMap<K,V>
GenericInvertibleMultiMap is a default implementation of
InvertibleMultiMap. It returns modifiable inverted
views of the mappings it maintains. Note that a
GenericInvertibleMultiMap can directly replace a
GenericInvertibleMap, because MultiMap
correctly extends Map.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionGenericInvertibleMultiMap(Map<? extends K, ? extends V> m) GenericInvertibleMultiMap(MapFactory<?, ?> mf, CollectionFactory<?> cf) GenericInvertibleMultiMap(MultiMap<? extends K, ? extends V> mm) GenericInvertibleMultiMap(MultiMapFactory<?, ?> mmf) -
Method Summary
Modifier and TypeMethodDescriptionbooleanEnsures thatthiscontains an association fromkeytovalue.booleanaddAll(K key, Collection<? extends V> values) Adds to the current mappings: associations forkeyto each value invalues.booleanAdds all mappings in the given multimap to this multimap.voidclear()booleanReturns true ifahas a mapping tobinthis.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()TheSetreturned by this method is actually an instance ofMultiMapSet.booleanReturns some arbitrary value from the collection of values to which this map maps the specified key.Returns the collection of Values associated withkey.inthashCode()invert()Returns an unmodifiable inverted view ofthis.booleanisEmpty()keySet()Associates the specified value with the specified key in this map, after removing all old values associated with the key.voidCopies the mappings from the specified map to this map, after removing all old values associated with the key.Removes mappings from key to all associated values from this map.booleanRemoves a mapping from key to value from this map if presentbooleanremoveAll(K key, Collection<?> values) Removes from the current mappings: associations forkeyto any value invalues.booleanretainAll(K key, Collection<?> values) Removes from the current mappings: associations forkeyto any value not invalues.intsize()Returns the number of key-value mappings in this map (keys which map to multiple values count multiple times).toString()values()Methods inherited from class java.lang.Object
clone, 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
-
GenericInvertibleMultiMap
-
GenericInvertibleMultiMap
-
GenericInvertibleMultiMap
-
GenericInvertibleMultiMap
public GenericInvertibleMultiMap() -
GenericInvertibleMultiMap
-
GenericInvertibleMultiMap
-
-
Method Details
-
invert
Returns an unmodifiable inverted view ofthis.- Specified by:
invertin interfaceInvertibleMap<K,V> - Specified by:
invertin interfaceInvertibleMultiMap<K,V>
-
add
Description copied from interface:MultiMap -
addAll
Description copied from interface:MultiMapAdds to the current mappings: associations forkeyto each value invalues. (MultiMapspecific operation). -
addAll
Description copied from interface:MultiMapAdds all mappings in the given multimap to this multimap. -
clear
public void clear() -
contains
Description copied from interface:MultiMap -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
entrySet
TheSetreturned by this method is actually an instance ofMultiMapSet. -
equals
-
get
Description copied from interface:MultiMapReturns some arbitrary value from the collection 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. -
getValues
Description copied from interface:MultiMapReturns the collection of Values associated withkey. Modifications to the returnedCollectionaffectthisas well. If there are no Values currently associated withkey, constructs a new, potentially mutable, emptyCollectionand returns it. (MultiMapspecific operation). -
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty() -
keySet
-
put
Description copied from interface:MultiMapAssociates the specified value with the specified key in this map, after removing all old values associated with the key. Returns some value that was previously associated with the specified key, ornullif no values were associated previously. -
putAll
Description copied from interface:MultiMapCopies the mappings from the specified map to this map, after removing all old values associated with the key. Note thatputAll(mm)wheremmis aMultiMapwill NOT add all of the mappings inmm; it will only add all of the Keys inmm, mapping each Key to one of the Values it mapped to inmm. To add all of the mappings from anotherMultiMap, useMultiMap.addAll(MultiMap). -
remove
Description copied from interface:MultiMapRemoves mappings from key to all associated values from this map. This is consistent with theMapdefinition ofremove.- Specified by:
removein interfaceMap<K,V> - Specified by:
removein interfaceMultiMap<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
Description copied from interface:MultiMapRemoves a mapping from key to value from this map if present. (MultiMapspecific operation). 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. -
removeAll
Description copied from interface:MultiMapRemoves from the current mappings: associations forkeyto any value invalues. (MultiMapspecific operation). -
retainAll
Description copied from interface:MultiMapRemoves from the current mappings: associations forkeyto any value not invalues. (MultiMapspecific operation). -
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). -
toString
-
values
-