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) class
Collection 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 TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends V> collection) (package private) void
addToMap()
Add the delegate to the map.void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
(package private) AbstractMapBasedMultimap<K,
V>.WrappedCollection (package private) Collection
<V> (package private) K
getKey()
int
hashCode()
iterator()
(package private) void
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
boolean
removeAll
(Collection<?> c) (package private) void
If collection is empty, remove it fromAbstractMapBasedMultimap.this.map
.boolean
retainAll
(Collection<?> c) int
size()
toString()
Methods inherited from class java.util.AbstractCollection
isEmpty, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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. OtherWrappedCollection
methods 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:
size
in interfaceCollection<V>
- Specified by:
size
in classAbstractCollection<V>
-
equals
- Specified by:
equals
in interfaceCollection<V>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<V>
- Overrides:
hashCode
in classObject
-
toString
- Overrides:
toString
in classAbstractCollection<V>
-
getDelegate
Collection<V> getDelegate() -
iterator
- Specified by:
iterator
in interfaceCollection<V>
- Specified by:
iterator
in interfaceIterable<V>
- Specified by:
iterator
in classAbstractCollection<V>
-
spliterator
-
add
- Specified by:
add
in interfaceCollection<V>
- Overrides:
add
in classAbstractCollection<V>
-
getAncestor
-
addAll
- Specified by:
addAll
in interfaceCollection<V>
- Overrides:
addAll
in classAbstractCollection<V>
-
contains
- Specified by:
contains
in interfaceCollection<V>
- Overrides:
contains
in classAbstractCollection<V>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<V>
- Overrides:
containsAll
in classAbstractCollection<V>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<V>
- Overrides:
clear
in classAbstractCollection<V>
-
remove
- Specified by:
remove
in interfaceCollection<V>
- Overrides:
remove
in classAbstractCollection<V>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<V>
- Overrides:
removeAll
in classAbstractCollection<V>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<V>
- Overrides:
retainAll
in classAbstractCollection<V>
-