Class MapConstraints.ConstrainedMultimap<K,​V>

    • 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  
    • 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 a Map from 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, as Map.Entry instances.
      java.util.Collection<V> get​(K key)
      Returns a view collection of the values associated with key in this multimap, if any.
      boolean put​(K key, V value)
      Stores a key-value pair in this multimap.
      boolean putAll​(Multimap<? extends K,​? extends V> multimap)
      Stores all key-value pairs of multimap in this multimap, in the order returned by multimap.entries().
      boolean putAll​(K key, java.lang.Iterable<? extends V> values)
      Stores a key-value pair in this multimap for each of values, 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 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • entries

        transient java.util.Collection<java.util.Map.Entry<K,​V>> entries
      • asMap

        transient java.util.Map<K,​java.util.Collection<V>> asMap
    • Constructor Detail

      • ConstrainedMultimap

        public ConstrainedMultimap​(Multimap<K,​V> delegate,
                                   MapConstraint<? super K,​? super V> constraint)
    • Method Detail

      • delegate

        protected Multimap<K,​V> delegate()
        Description copied from class: ForwardingObject
        Returns 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 as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingMultimap<K,​V>
      • asMap

        public java.util.Map<K,​java.util.Collection<V>> asMap()
        Description copied from interface: Multimap
        Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values. Note that this.asMap().get(k) is equivalent to this.get(k) only when k is a key contained in the multimap; otherwise it returns null as 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 put or putAll, nor do its entries support setValue.

        Specified by:
        asMap in interface Multimap<K,​V>
        Overrides:
        asMap in class ForwardingMultimap<K,​V>
      • entries

        public java.util.Collection<java.util.Map.Entry<K,​V>> entries()
        Description copied from interface: Multimap
        Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

        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.

        Specified by:
        entries in interface Multimap<K,​V>
        Overrides:
        entries in class ForwardingMultimap<K,​V>
      • get

        public java.util.Collection<V> get​(K key)
        Description copied from interface: Multimap
        Returns a view collection of the values associated with key in this multimap, if any. Note that when containsKey(key) is false, this returns an empty collection, not null.

        Changes to the returned collection will update the underlying multimap, and vice versa.

        Specified by:
        get in interface Multimap<K,​V>
        Overrides:
        get in class ForwardingMultimap<K,​V>
      • put

        public boolean put​(K key,
                           V value)
        Description copied from interface: Multimap
        Stores a key-value pair in this multimap.

        Some multimap implementations allow duplicate key-value pairs, in which case put always 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.

        Specified by:
        put in interface Multimap<K,​V>
        Overrides:
        put in class ForwardingMultimap<K,​V>
        Returns:
        true if the method increased the size of the multimap, or false if the multimap already contained the key-value pair and doesn't allow duplicates
      • putAll

        public boolean putAll​(K key,
                              java.lang.Iterable<? extends V> values)
        Description copied from interface: Multimap
        Stores a key-value pair in this multimap for each of values, 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 values is empty.

        Specified by:
        putAll in interface Multimap<K,​V>
        Overrides:
        putAll in class ForwardingMultimap<K,​V>
        Returns:
        true if the multimap changed
      • putAll

        public boolean putAll​(Multimap<? extends K,​? extends V> multimap)
        Description copied from interface: Multimap
        Stores all key-value pairs of multimap in this multimap, in the order returned by multimap.entries().
        Specified by:
        putAll in interface Multimap<K,​V>
        Overrides:
        putAll in class ForwardingMultimap<K,​V>
        Returns:
        true if the multimap changed
      • replaceValues

        public java.util.Collection<V> replaceValues​(K key,
                                                     java.lang.Iterable<? extends V> values)
        Description copied from interface: Multimap
        Stores a collection of values with the same key, replacing any existing values for that key.

        If values is empty, this is equivalent to removeAll(key).

        Specified by:
        replaceValues in interface Multimap<K,​V>
        Overrides:
        replaceValues in class ForwardingMultimap<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.