Class AbstractSortedSetMultimap<K,​V>

    • Constructor Detail

      • AbstractSortedSetMultimap

        protected AbstractSortedSetMultimap​(java.util.Map<K,​java.util.Collection<V>> map)
        Creates a new multimap that uses the provided map.
        Parameters:
        map - place to store the mapping from each key to its corresponding values
    • Method Detail

      • createCollection

        abstract java.util.SortedSet<V> createCollection()
        Description copied from class: AbstractMapBasedMultimap
        Creates the collection of values for a single key.

        Collections with weak, soft, or phantom references are not supported. Each call to createCollection should create a new instance.

        The returned collection class determines whether duplicate key-value pairs are allowed.

        Specified by:
        createCollection in class AbstractSetMultimap<K,​V>
        Returns:
        an empty collection of values
      • wrapCollection

        java.util.Collection<V> wrapCollection​(K key,
                                               java.util.Collection<V> collection)
        Description copied from class: AbstractMapBasedMultimap
        Generates a decorated collection that remains consistent with the values in the multimap for the provided key. Changes to the multimap may alter the returned collection, and vice versa.
        Overrides:
        wrapCollection in class AbstractSetMultimap<K,​V>
      • get

        public java.util.SortedSet<V> get​(K key)
        Returns a collection view of all values associated with a key. If no mappings in the multimap have the provided key, an empty collection is returned.

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

        Because a SortedSetMultimap has unique sorted values for a given key, this method returns a SortedSet, instead of the Collection specified in the Multimap interface.

        Specified by:
        get in interface Multimap<K,​V>
        Specified by:
        get in interface SetMultimap<K,​V>
        Specified by:
        get in interface SortedSetMultimap<K,​V>
        Overrides:
        get in class AbstractSetMultimap<K,​V>
      • removeAll

        public java.util.SortedSet<V> removeAll​(@CheckForNull
                                                java.lang.Object key)
        Removes all values associated with a given key. The returned collection is immutable.

        Because a SortedSetMultimap has unique sorted values for a given key, this method returns a SortedSet, instead of the Collection specified in the Multimap interface.

        Specified by:
        removeAll in interface Multimap<K,​V>
        Specified by:
        removeAll in interface SetMultimap<K,​V>
        Specified by:
        removeAll in interface SortedSetMultimap<K,​V>
        Overrides:
        removeAll in class AbstractSetMultimap<K,​V>
        Returns:
        the values that were removed (possibly empty). The returned collection may be modifiable, but updating it will have no effect on the multimap.
      • replaceValues

        public java.util.SortedSet<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. The returned collection is immutable.

        Because a SortedSetMultimap has unique sorted values for a given key, this method returns a SortedSet, instead of the Collection specified in the Multimap interface.

        Any duplicates in values will be stored in the multimap once.

        Specified by:
        replaceValues in interface Multimap<K,​V>
        Specified by:
        replaceValues in interface SetMultimap<K,​V>
        Specified by:
        replaceValues in interface SortedSetMultimap<K,​V>
        Overrides:
        replaceValues in class AbstractSetMultimap<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.
      • asMap

        public java.util.Map<K,​java.util.Collection<V>> asMap()
        Returns a map view that associates each key with the corresponding values in the multimap. Changes to the returned map, such as element removal, will update the underlying multimap. The map does not support setValue on its entries, put, or putAll.

        When passed a key that is present in the map, asMap().get(Object) has the same behavior as get(K), returning a live collection. When passed a key that is not present, however, asMap().get(Object) returns null instead of an empty collection.

        Though the method signature doesn't say so explicitly, the returned map has SortedSet values.

        Specified by:
        asMap in interface Multimap<K,​V>
        Specified by:
        asMap in interface SetMultimap<K,​V>
        Specified by:
        asMap in interface SortedSetMultimap<K,​V>
        Overrides:
        asMap in class AbstractSetMultimap<K,​V>
      • values

        public java.util.Collection<V> values()
        Returns a view collection containing the value from each key-value pair contained in this multimap, without collapsing duplicates (so values().size() == size()).

        Changes to the returned collection will update the underlying multimap, and vice versa. However, adding to the returned collection is not possible.

        The iterator generated by the returned collection traverses the values for one key, followed by the values of a second key, and so on.

        Consequently, the values do not follow their natural ordering or the ordering of the value comparator.

        Specified by:
        values in interface Multimap<K,​V>
        Overrides:
        values in class AbstractMapBasedMultimap<K,​V>