Class MapConstraints.ConstrainedMultimap<K,V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMultimap<K,V>
-
- com.google.common.collect.MapConstraints.ConstrainedMultimap<K,V>
-
- All Implemented Interfaces:
Multimap<K,V>,java.io.Serializable
- Direct Known Subclasses:
MapConstraints.ConstrainedListMultimap
- Enclosing class:
- MapConstraints
private static class MapConstraints.ConstrainedMultimap<K,V> extends ForwardingMultimap<K,V> implements java.io.Serializable
- See Also:
MapConstraints#constrainedMultimap
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<K,java.util.Collection<V>>asMap(package private) MapConstraint<? super K,? super V>constraint(package private) Multimap<K,V>delegate(package private) java.util.Collection<java.util.Map.Entry<K,V>>entries
-
Constructor Summary
Constructors Constructor Description ConstrainedMultimap(Multimap<K,V> delegate, MapConstraint<? super K,? super V> constraint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<K,java.util.Collection<V>>asMap()Returns a view of this multimap as aMapfrom each distinct key to the nonempty collection of that key's associated values.protected Multimap<K,V>delegate()Returns the backing delegate instance that methods are forwarded to.java.util.Collection<java.util.Map.Entry<K,V>>entries()Returns a view collection of all key-value pairs contained in this multimap, asMap.Entryinstances.java.util.Collection<V>get(K key)Returns a view collection of the values associated withkeyin this multimap, if any.booleanput(K key, V value)Stores a key-value pair in this multimap.booleanputAll(Multimap<? extends K,? extends V> multimap)Stores all key-value pairs ofmultimapin this multimap, in the order returned bymultimap.entries().booleanputAll(K key, java.lang.Iterable<? extends V> values)Stores a key-value pair in this multimap for each ofvalues, all using the same key,key.java.util.Collection<V>replaceValues(K key, java.lang.Iterable<? extends V> values)Stores a collection of values with the same key, replacing any existing values for that key.-
Methods inherited from class com.google.common.collect.ForwardingMultimap
clear, containsEntry, containsKey, containsValue, equals, hashCode, isEmpty, keys, keySet, remove, removeAll, size, values
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Method Detail
-
delegate
protected Multimap<K,V> delegate()
Description copied from class:ForwardingObjectReturns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingMultimap<K,V>
-
asMap
public java.util.Map<K,java.util.Collection<V>> asMap()
Description copied from interface:MultimapReturns a view of this multimap as aMapfrom each distinct key to the nonempty collection of that key's associated values. Note thatthis.asMap().get(k)is equivalent tothis.get(k)only whenkis a key contained in the multimap; otherwise it returnsnullas opposed to an empty collection.Changes to the returned map or the collections that serve as its values will update the underlying multimap, and vice versa. The map does not support
putorputAll, nor do its entries supportsetValue.
-
entries
public java.util.Collection<java.util.Map.Entry<K,V>> entries()
Description copied from interface:MultimapReturns a view collection of all key-value pairs contained in this multimap, asMap.Entryinstances.Changes to the returned collection or the entries it contains will update the underlying multimap, and vice versa. However, adding to the returned collection is not possible.
-
get
public java.util.Collection<V> get(K key)
Description copied from interface:MultimapReturns a view collection of the values associated withkeyin this multimap, if any. Note that whencontainsKey(key)is false, this returns an empty collection, notnull.Changes to the returned collection will update the underlying multimap, and vice versa.
-
put
public boolean put(K key, V value)
Description copied from interface:MultimapStores a key-value pair in this multimap.Some multimap implementations allow duplicate key-value pairs, in which case
putalways adds a new key-value pair and increases the multimap size by 1. Other implementations prohibit duplicates, and storing a key-value pair that's already in the multimap has no effect.
-
putAll
public boolean putAll(K key, java.lang.Iterable<? extends V> values)
Description copied from interface:MultimapStores a key-value pair in this multimap for each ofvalues, all using the same key,key. Equivalent to (but expected to be more efficient than):for (V value : values) { put(key, value); }In particular, this is a no-op if
valuesis empty.
-
putAll
public boolean putAll(Multimap<? extends K,? extends V> multimap)
Description copied from interface:MultimapStores all key-value pairs ofmultimapin this multimap, in the order returned bymultimap.entries().
-
replaceValues
public java.util.Collection<V> replaceValues(K key, java.lang.Iterable<? extends V> values)
Description copied from interface:MultimapStores a collection of values with the same key, replacing any existing values for that key.If
valuesis empty, this is equivalent toremoveAll(key).- Specified by:
replaceValuesin interfaceMultimap<K,V>- Overrides:
replaceValuesin classForwardingMultimap<K,V>- Returns:
- the collection of replaced values, or an empty collection if no values were previously associated with the key. The collection may be modifiable, but updating it will have no effect on the multimap.
-
-