Class AbstractMapBasedMultimap.WrappedCollection
- java.lang.Object
-
- java.util.AbstractCollection<V>
-
- com.google.common.collect.AbstractMapBasedMultimap.WrappedCollection
-
- All Implemented Interfaces:
java.lang.Iterable<V>,java.util.Collection<V>
- Direct Known Subclasses:
AbstractMapBasedMultimap.WrappedList,AbstractMapBasedMultimap.WrappedSet,AbstractMapBasedMultimap.WrappedSortedSet
- Enclosing class:
- AbstractMapBasedMultimap<K,V>
class AbstractMapBasedMultimap.WrappedCollection extends java.util.AbstractCollection<V>Collection decorator that stays in sync with the multimap values for a key. There are two kinds of wrapped collections: full and subcollections. Both have a delegate pointing to the underlying collection class.Full collections, identified by a null ancestor field, contain all multimap values for a given key. Its delegate is a value in
AbstractMapBasedMultimap.mapwhenever the delegate is non-empty. TherefreshIfEmpty,removeIfEmpty, andaddToMapmethods ensure that theWrappedCollectionand 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, andaddToMapmethods call the corresponding methods of the full wrapped collection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classAbstractMapBasedMultimap.WrappedCollection.WrappedIteratorCollection iterator forWrappedCollection.
-
Field Summary
Fields Modifier and Type Field Description (package private) AbstractMapBasedMultimap.WrappedCollectionancestor(package private) java.util.Collection<V>ancestorDelegate(package private) java.util.Collection<V>delegate(package private) Kkey
-
Constructor Summary
Constructors Constructor Description WrappedCollection(K key, java.util.Collection<V> delegate, AbstractMapBasedMultimap.WrappedCollection ancestor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(V value)booleanaddAll(java.util.Collection<? extends V> collection)(package private) voidaddToMap()Add the delegate to the map.voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object object)(package private) AbstractMapBasedMultimap.WrappedCollectiongetAncestor()(package private) java.util.Collection<V>getDelegate()(package private) KgetKey()inthashCode()java.util.Iterator<V>iterator()(package private) voidrefreshIfEmpty()If the delegate collection is empty, but the multimap has values for the key, replace the delegate with the new collection for the key.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)(package private) voidremoveIfEmpty()If collection is empty, remove it fromAbstractMapBasedMultimap.this.map.booleanretainAll(java.util.Collection<?> c)intsize()java.util.Spliterator<V>spliterator()java.lang.StringtoString()
-
-
-
Field Detail
-
key
final K key
-
delegate
java.util.Collection<V> delegate
-
ancestor
final AbstractMapBasedMultimap.WrappedCollection ancestor
-
ancestorDelegate
final java.util.Collection<V> ancestorDelegate
-
-
Constructor Detail
-
WrappedCollection
WrappedCollection(K key, java.util.Collection<V> delegate, AbstractMapBasedMultimap.WrappedCollection ancestor)
-
-
Method Detail
-
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()
-
equals
public boolean equals(java.lang.Object object)
- Specified by:
equalsin interfacejava.util.Collection<V>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<V>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<V>
-
getDelegate
java.util.Collection<V> getDelegate()
-
iterator
public java.util.Iterator<V> iterator()
-
spliterator
public java.util.Spliterator<V> spliterator()
-
add
public boolean add(V value)
-
getAncestor
AbstractMapBasedMultimap.WrappedCollection getAncestor()
-
addAll
public boolean addAll(java.util.Collection<? extends V> collection)
-
contains
public boolean contains(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
clear
public void clear()
-
remove
public boolean remove(java.lang.Object o)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
-