class AbstractMapBasedMultimap.WrappedCollection
extends java.util.AbstractCollection<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.
Modifier and Type | Class and Description |
---|---|
(package private) class |
AbstractMapBasedMultimap.WrappedCollection.WrappedIterator
Collection iterator for
WrappedCollection . |
Modifier and Type | Field and Description |
---|---|
(package private) AbstractMapBasedMultimap.WrappedCollection |
ancestor |
(package private) java.util.Collection<V> |
ancestorDelegate |
(package private) java.util.Collection<V> |
delegate |
(package private) K |
key |
Constructor and Description |
---|
WrappedCollection(K key,
java.util.Collection<V> delegate,
AbstractMapBasedMultimap.WrappedCollection ancestor) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(V value) |
boolean |
addAll(java.util.Collection<? extends V> collection) |
(package private) void |
addToMap()
Add the delegate to the map.
|
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
equals(java.lang.Object object) |
(package private) AbstractMapBasedMultimap.WrappedCollection |
getAncestor() |
(package private) java.util.Collection<V> |
getDelegate() |
(package private) K |
getKey() |
int |
hashCode() |
java.util.Iterator<V> |
iterator() |
(package private) 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.
|
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
(package private) void |
removeIfEmpty()
If collection is empty, remove it from
AbstractMapBasedMultimap.this.map . |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
java.util.Spliterator<V> |
spliterator() |
java.lang.String |
toString() |
final K key
java.util.Collection<V> delegate
@CheckForNull final AbstractMapBasedMultimap.WrappedCollection ancestor
@CheckForNull final java.util.Collection<V> ancestorDelegate
WrappedCollection(K key, java.util.Collection<V> delegate, @CheckForNull AbstractMapBasedMultimap.WrappedCollection ancestor)
void refreshIfEmpty()
For a subcollection, refresh its ancestor and validate that the ancestor delegate hasn't changed.
void removeIfEmpty()
AbstractMapBasedMultimap.this.map
. For
subcollections, check whether the ancestor collection is empty.K getKey()
void addToMap()
WrappedCollection
methods should call this method
after adding elements to a previously empty collection.
Subcollection add the ancestor's delegate instead.
public int size()
public boolean equals(@CheckForNull java.lang.Object object)
equals
in interface java.util.Collection<V>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection<V>
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.util.AbstractCollection<V>
java.util.Collection<V> getDelegate()
public java.util.Iterator<V> iterator()
public java.util.Spliterator<V> spliterator()
public boolean add(V value)
@CheckForNull AbstractMapBasedMultimap.WrappedCollection getAncestor()
public boolean addAll(java.util.Collection<? extends V> collection)
public boolean contains(@CheckForNull java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public void clear()
public boolean remove(@CheckForNull java.lang.Object o)
public boolean removeAll(java.util.Collection<?> c)