001    /*
002     * Copyright (C) 2007 The Guava Authors
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package com.google.common.collect;
018    
019    import com.google.common.annotations.GwtCompatible;
020    
021    import java.util.Collection;
022    import java.util.Comparator;
023    import java.util.Map;
024    import java.util.Set;
025    import java.util.SortedSet;
026    
027    import javax.annotation.Nullable;
028    
029    /**
030     * A {@code SetMultimap} whose set of values for a given key are kept sorted;
031     * that is, they comprise a {@link SortedSet}. It cannot hold duplicate
032     * key-value pairs; adding a key-value pair that's already in the multimap has
033     * no effect. This interface does not specify the ordering of the multimap's
034     * keys. See the {@link Multimap} documentation for information common to all
035     * multimaps.
036     *
037     * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods
038     * each return a {@link SortedSet} of values, while {@link Multimap#entries()}
039     * returns a {@link Set} of map entries. Though the method signature doesn't say
040     * so explicitly, the map returned by {@link #asMap} has {@code SortedSet}
041     * values.
042     * 
043     * <p>See the Guava User Guide article on <a href=
044     * "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Multimap">
045     * {@code Multimap}</a>.
046     *
047     * @author Jared Levy
048     * @since 2.0 (imported from Google Collections Library)
049     */
050    @GwtCompatible
051    public interface SortedSetMultimap<K, V> extends SetMultimap<K, V> {
052      // Following Javadoc copied from Multimap.
053    
054      /**
055       * Returns a collection view of all values associated with a key. If no
056       * mappings in the multimap have the provided key, an empty collection is
057       * returned.
058       *
059       * <p>Changes to the returned collection will update the underlying multimap,
060       * and vice versa.
061       *
062       * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given
063       * key, this method returns a {@link SortedSet}, instead of the
064       * {@link java.util.Collection} specified in the {@link Multimap} interface.
065       */
066      SortedSet<V> get(@Nullable K key);
067    
068      /**
069       * Removes all values associated with a given key.
070       *
071       * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given
072       * key, this method returns a {@link SortedSet}, instead of the
073       * {@link java.util.Collection} specified in the {@link Multimap} interface.
074       */
075      SortedSet<V> removeAll(@Nullable Object key);
076    
077      /**
078       * Stores a collection of values with the same key, replacing any existing
079       * values for that key.
080       *
081       * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given
082       * key, this method returns a {@link SortedSet}, instead of the
083       * {@link java.util.Collection} specified in the {@link Multimap} interface.
084       *
085       * <p>Any duplicates in {@code values} will be stored in the multimap once.
086       */
087      SortedSet<V> replaceValues(K key, Iterable<? extends V> values);
088    
089      /**
090       * Returns a map view that associates each key with the corresponding values
091       * in the multimap. Changes to the returned map, such as element removal, will
092       * update the underlying multimap. The map does not support {@code setValue()}
093       * on its entries, {@code put}, or {@code putAll}.
094       *
095       * <p>When passed a key that is present in the map, {@code
096       * asMap().get(Object)} has the same behavior as {@link #get}, returning a
097       * live collection. When passed a key that is not present, however, {@code
098       * asMap().get(Object)} returns {@code null} instead of an empty collection.
099       *
100       * <p>Though the method signature doesn't say so explicitly, the returned map
101       * has {@link SortedSet} values.
102       */
103      Map<K, Collection<V>> asMap();
104    
105      /**
106       * Returns the comparator that orders the multimap values, with {@code null}
107       * indicating that natural ordering is used.
108       */
109      Comparator<? super V> valueComparator();
110    }