Package net.cscott.jutil
Class AbstractMultiMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
net.cscott.jutil.AbstractMultiMap<K,V>
- Direct Known Subclasses:
GenericMultiMap
This class provides a skeletal implementation of the
MultiMap
interface, to minimize the effort requires to implement this interface.- Since:
- 1.3
- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
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.booleanAdd all mappings in the given multimap to this multimap.abstract voidclear()abstract booleanReturns true ifahas a mapping tobinthis.booleancontainsKey(Object key) booleancontainsValue(Object value) abstract MultiMapSet<K, V> entrySet()booleanReturns some arbitrary value from the collection of values to which this map maps the specified key.abstract Collection<V> Returns the collection of Values associated withkey.inthashCode()booleanisEmpty()Associates the specified value with the specified key in this map.voidCopies the mappings from the specified map to this map.abstract VRemoves mappings from key to all associated values from this map.abstract 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()Methods inherited from class java.util.AbstractMap
clone, keySet, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, keySet, merge, putIfAbsent, replace, valuesMethods inherited from interface net.cscott.jutil.MultiMap
replace, replaceAll
-
Constructor Details
-
AbstractMultiMap
public AbstractMultiMap()
-
-
Method Details
-
toString
- Overrides:
toStringin classAbstractMap<K,V>
-
hashCode
public int hashCode() -
add
-
addAll
Adds to the current mappings: associations forkeyto each value invalues. (MultiMapspecific operation). -
addAll
Add all mappings in the given multimap to this multimap. -
retainAll
Removes from the current mappings: associations forkeyto any value not invalues. (MultiMapspecific operation). -
removeAll
Removes from the current mappings: associations forkeyto any value invalues. (MultiMapspecific operation). -
equals
-
putAll
Copies the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map. 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, useaddAll(MultiMap). -
put
Associates the specified value with the specified key in this map. If the map previously contained any mappings for this key, all of the old values are replaced. Returns some value that was previous associated with the specified key, ornullif no values were associated previously. -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V>
-
isEmpty
public boolean isEmpty() -
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). -
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). -
contains
Description copied from interface: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> - Overrides:
removein classAbstractMap<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. -
clear
public abstract void clear() -
entrySet
Description copied from interface:MultiMap
-