Class AbstractMapBasedMultimap.WrappedCollection
- All Implemented Interfaces:
Iterable<V>,Collection<V>
- Direct Known Subclasses:
AbstractMapBasedMultimap.WrappedList,AbstractMapBasedMultimap.WrappedSet,AbstractMapBasedMultimap.WrappedSortedSet
- Enclosing class:
AbstractMapBasedMultimap<K,V>
Full collections, identified by a null ancestor field, contain all multimap values for a
given key. Its delegate is a value in AbstractMapBasedMultimap.map whenever the
delegate is non-empty. The refreshIfEmpty, removeIfEmpty, and addToMap
methods ensure that the WrappedCollection and map remain consistent.
A subcollection, such as a sublist, contains some of the values for a given key. Its
ancestor field points to the full wrapped collection with all values for the key. The
subcollection refreshIfEmpty, removeIfEmpty, and addToMap methods call
the corresponding methods of the full wrapped collection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classCollection iterator forWrappedCollection. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AbstractMapBasedMultimap<K,V>.WrappedCollection (package private) final Collection<V> (package private) Collection<V> (package private) final K -
Constructor Summary
ConstructorsConstructorDescriptionWrappedCollection(K key, Collection<V> delegate, AbstractMapBasedMultimap<K, V>.WrappedCollection ancestor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends V> collection) (package private) voidaddToMap()Add the delegate to the map.voidclear()booleanbooleancontainsAll(Collection<?> c) boolean(package private) AbstractMapBasedMultimap<K,V>.WrappedCollection (package private) Collection<V> (package private) KgetKey()inthashCode()iterator()(package private) voidIf the delegate collection is empty, but the multimap has values for the key, replace the delegate with the new collection for the key.booleanbooleanremoveAll(Collection<?> c) (package private) voidIf collection is empty, remove it fromAbstractMapBasedMultimap.this.map.booleanretainAll(Collection<?> c) intsize()toString()Methods inherited from class java.util.AbstractCollection
isEmpty, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
key
-
delegate
Collection<V> delegate -
ancestor
-
ancestorDelegate
-
-
Constructor Details
-
WrappedCollection
WrappedCollection(K key, Collection<V> delegate, @CheckForNull AbstractMapBasedMultimap<K, V>.WrappedCollection ancestor)
-
-
Method Details
-
refreshIfEmpty
void refreshIfEmpty()If the delegate collection is empty, but the multimap has values for the key, replace the delegate with the new collection for the key.For a subcollection, refresh its ancestor and validate that the ancestor delegate hasn't changed.
-
removeIfEmpty
void removeIfEmpty()If collection is empty, remove it fromAbstractMapBasedMultimap.this.map. For subcollections, check whether the ancestor collection is empty. -
getKey
K getKey() -
addToMap
void addToMap()Add the delegate to the map. OtherWrappedCollectionmethods should call this method after adding elements to a previously empty collection.Subcollection add the ancestor's delegate instead.
-
size
public int size()- Specified by:
sizein interfaceCollection<V>- Specified by:
sizein classAbstractCollection<V>
-
equals
- Specified by:
equalsin interfaceCollection<V>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<V>- Overrides:
hashCodein classObject
-
toString
- Overrides:
toStringin classAbstractCollection<V>
-
getDelegate
Collection<V> getDelegate() -
iterator
- Specified by:
iteratorin interfaceCollection<V>- Specified by:
iteratorin interfaceIterable<V>- Specified by:
iteratorin classAbstractCollection<V>
-
spliterator
-
add
- Specified by:
addin interfaceCollection<V>- Overrides:
addin classAbstractCollection<V>
-
getAncestor
-
addAll
- Specified by:
addAllin interfaceCollection<V>- Overrides:
addAllin classAbstractCollection<V>
-
contains
- Specified by:
containsin interfaceCollection<V>- Overrides:
containsin classAbstractCollection<V>
-
containsAll
- Specified by:
containsAllin interfaceCollection<V>- Overrides:
containsAllin classAbstractCollection<V>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<V>- Overrides:
clearin classAbstractCollection<V>
-
remove
- Specified by:
removein interfaceCollection<V>- Overrides:
removein classAbstractCollection<V>
-
removeAll
- Specified by:
removeAllin interfaceCollection<V>- Overrides:
removeAllin classAbstractCollection<V>
-
retainAll
- Specified by:
retainAllin interfaceCollection<V>- Overrides:
retainAllin classAbstractCollection<V>
-