Class AbstractMutableMultimap<K,V,C extends MutableCollection<V>>
- java.lang.Object
-
- org.eclipse.collections.impl.multimap.AbstractMultimap<K,V,C>
-
- org.eclipse.collections.impl.multimap.AbstractMutableMultimap<K,V,C>
-
- All Implemented Interfaces:
Multimap<K,V>
,MutableMultimap<K,V>
- Direct Known Subclasses:
AbstractMutableBagMultimap
,AbstractMutableListMultimap
,AbstractMutableSetMultimap
,AbstractSynchronizedPutMultimap
,TreeBagMultimap
,TreeBagMultimap
,TreeBagMultimap
,TreeSortedSetMultimap
public abstract class AbstractMutableMultimap<K,V,C extends MutableCollection<V>> extends AbstractMultimap<K,V,C> implements MutableMultimap<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected MutableMap<K,C>
map
protected int
totalSize
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMutableMultimap()
protected
AbstractMutableMultimap(int size)
protected
AbstractMutableMultimap(java.lang.Iterable<Pair<K,V>> inputIterable)
Constructs aMultimap
containingIterable
.protected
AbstractMutableMultimap(MutableMap<K,C> newMap)
protected
AbstractMutableMultimap(Pair<K,V>... pairs)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addToTotalSize(int value)
This method is provided to allow for subclasses to provide the behavior.void
clear()
protected void
clearTotalSize()
This method is provided to allow for subclasses to provide the behavior.protected abstract MutableMap<K,C>
createMap()
protected abstract MutableMap<K,C>
createMapWithKeyCount(int keyCount)
protected void
decrementTotalSize()
This method is provided to allow for subclasses to provide the behavior.C
get(K key)
Returns a view of all values associated with the given key.C
getIfAbsentPutAll(K key, java.lang.Iterable<? extends V> values)
Puts values into multimap if there are no values already associated with key.private C
getIfAbsentPutCollection(K key)
protected MutableMap<K,C>
getMap()
protected void
incrementTotalSize()
This method is provided to allow for subclasses to provide the behavior.boolean
isEmpty()
Returnstrue
if there are no entries.SetIterable<K>
keySet()
Returns an unmodifiableSetIterable
of keys with O(1) complexity.boolean
put(K key, V value)
boolean
putAll(K key, java.lang.Iterable<? extends V> values)
<KK extends K,VV extends V>
booleanputAll(Multimap<KK,VV> multimap)
private <KK extends K,VV extends V>
booleanputAllAbstractMutableMultimap(AbstractMutableMultimap<KK,VV,MutableCollection<VV>> other)
private boolean
putAllNotEmpty(K key, java.lang.Iterable<? extends V> values)
private <KK extends K,VV extends V>
booleanputAllReadOnlyMultimap(Multimap<KK,VV> multimap)
void
readExternal(java.io.ObjectInput in)
(package private) void
readValuesFrom(java.io.ObjectInput in)
boolean
remove(java.lang.Object key, java.lang.Object value)
C
removeAll(java.lang.Object key)
C
replaceValues(K key, java.lang.Iterable<? extends V> values)
int
size()
Use the size method directly instead of totalSize internally so subclasses can override if necessary.int
sizeDistinct()
Returns the number of distinct keys.protected void
subtractFromTotalSize(int value)
This method is provided to allow for subclasses to provide the behavior.MutableMap<K,RichIterable<V>>
toMap()
Returns a newMutableMap
of keys from this Multimap to the mapped values as aRichIterable
.<R extends java.util.Collection<V>>
MutableMap<K,R>toMap(Function0<R> collectionFactory)
Returns a newMutableMap
of keys from this Multimap to the mapped values as aRichIterable
.void
writeExternal(java.io.ObjectOutput out)
-
Methods inherited from class org.eclipse.collections.impl.multimap.AbstractMultimap
collectKeyMultiValues, collectKeysValues, collectValues, containsKey, containsKeyAndValue, containsValue, createCollection, createCollectionBlock, equals, forEachKey, forEachKeyMultiValues, forEachKeyValue, forEachValue, hashCode, keyBag, keyMultiValuePairsView, keysView, keyValuePairsView, multiValuesView, notEmpty, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, toString, valuesView
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.multimap.Multimap
collectKeyMultiValues, collectKeysValues, collectValues, containsKey, containsKeyAndValue, containsValue, equals, forEachKey, forEachKeyMultiValues, forEachKeyValue, forEachValue, hashCode, keyBag, keyMultiValuePairsView, keysView, keyValuePairsView, multiValuesView, notEmpty, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, toImmutable, toMutable, valuesView
-
Methods inherited from interface org.eclipse.collections.api.multimap.MutableMultimap
add, asSynchronized, collectKeyMultiValues, collectKeysValues, collectValues, flip, newEmpty, putAllPairs, putAllPairs, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, withKeyMultiValues, withKeyValue
-
-
-
-
Field Detail
-
map
protected MutableMap<K,C extends MutableCollection<V>> map
-
totalSize
protected int totalSize
-
-
Constructor Detail
-
AbstractMutableMultimap
protected AbstractMutableMultimap()
-
AbstractMutableMultimap
protected AbstractMutableMultimap(MutableMap<K,C> newMap)
-
AbstractMutableMultimap
protected AbstractMutableMultimap(int size)
-
AbstractMutableMultimap
protected AbstractMutableMultimap(Pair<K,V>... pairs)
- Parameters:
pairs
- the mappings to initialize the multimap.
-
-
Method Detail
-
createMap
protected abstract MutableMap<K,C> createMap()
-
createMapWithKeyCount
protected abstract MutableMap<K,C> createMapWithKeyCount(int keyCount)
-
getMap
protected MutableMap<K,C> getMap()
- Specified by:
getMap
in classAbstractMultimap<K,V,C extends MutableCollection<V>>
-
size
public int size()
Use the size method directly instead of totalSize internally so subclasses can override if necessary.
-
incrementTotalSize
protected void incrementTotalSize()
This method is provided to allow for subclasses to provide the behavior. It should add 1 to the value that is returned by calling size().
-
decrementTotalSize
protected void decrementTotalSize()
This method is provided to allow for subclasses to provide the behavior. It should remove 1 from the value that is returned by calling size().
-
addToTotalSize
protected void addToTotalSize(int value)
This method is provided to allow for subclasses to provide the behavior. It should add the specified amount to the value that is returned by calling size().
-
subtractFromTotalSize
protected void subtractFromTotalSize(int value)
This method is provided to allow for subclasses to provide the behavior. It should subtract the specified amount from the value that is returned by calling size().
-
clearTotalSize
protected void clearTotalSize()
This method is provided to allow for subclasses to provide the behavior. It should set the value returned by size() to 0.
-
sizeDistinct
public int sizeDistinct()
Description copied from interface:Multimap
Returns the number of distinct keys.- Specified by:
sizeDistinct
in interfaceMultimap<K,V>
-
isEmpty
public boolean isEmpty()
Description copied from interface:Multimap
Returnstrue
if there are no entries.
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
- Specified by:
remove
in interfaceMutableMultimap<K,V>
-
putAll
public boolean putAll(K key, java.lang.Iterable<? extends V> values)
- Specified by:
putAll
in interfaceMutableMultimap<K,V>
-
putAll
public <KK extends K,VV extends V> boolean putAll(Multimap<KK,VV> multimap)
- Specified by:
putAll
in interfaceMutableMultimap<K,V>
-
putAllReadOnlyMultimap
private <KK extends K,VV extends V> boolean putAllReadOnlyMultimap(Multimap<KK,VV> multimap)
-
putAllAbstractMutableMultimap
private <KK extends K,VV extends V> boolean putAllAbstractMutableMultimap(AbstractMutableMultimap<KK,VV,MutableCollection<VV>> other)
-
replaceValues
public C replaceValues(K key, java.lang.Iterable<? extends V> values)
- Specified by:
replaceValues
in interfaceMutableMultimap<K,V>
-
removeAll
public C removeAll(java.lang.Object key)
- Specified by:
removeAll
in interfaceMutableMultimap<K,V>
-
clear
public void clear()
- Specified by:
clear
in interfaceMutableMultimap<K,V>
-
keySet
public SetIterable<K> keySet()
Description copied from interface:Multimap
Returns an unmodifiableSetIterable
of keys with O(1) complexity.
-
get
public C get(K key)
Description copied from interface:Multimap
Returns a view of all values associated with the given key.If the given key does not exist, an empty
RichIterable
is returned.
-
getIfAbsentPutAll
public C getIfAbsentPutAll(K key, java.lang.Iterable<? extends V> values)
Description copied from interface:MutableMultimap
Puts values into multimap if there are no values already associated with key. Then returns a view of the values associated with key, like the result ofMultimap.get(Object)
- Specified by:
getIfAbsentPutAll
in interfaceMutableMultimap<K,V>
-
toMap
public MutableMap<K,RichIterable<V>> toMap()
Description copied from interface:Multimap
Returns a newMutableMap
of keys from this Multimap to the mapped values as aRichIterable
.
-
toMap
public <R extends java.util.Collection<V>> MutableMap<K,R> toMap(Function0<R> collectionFactory)
Description copied from interface:Multimap
Returns a newMutableMap
of keys from this Multimap to the mapped values as aRichIterable
.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
readValuesFrom
void readValuesFrom(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
-