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.Map;
023    import java.util.Set;
024    
025    import javax.annotation.Nullable;
026    
027    /**
028     * A {@code Multimap} that cannot hold duplicate key-value pairs. Adding a
029     * key-value pair that's already in the multimap has no effect.
030     *
031     * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods
032     * each return a {@link Set} of values, while {@link #entries} returns a {@code
033     * Set} of map entries. Though the method signature doesn't say so explicitly,
034     * the map returned by {@link #asMap} has {@code Set} values.
035     * 
036     * <p>See the Guava User Guide article on <a href=
037     * "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Multimap">
038     * {@code Multimap}</a>.
039     *
040     * @author Jared Levy
041     * @since 2.0 (imported from Google Collections Library)
042     */
043    @GwtCompatible
044    public interface SetMultimap<K, V> extends Multimap<K, V> {
045      /**
046       * {@inheritDoc}
047       *
048       * <p>Because a {@code SetMultimap} has unique values for a given key, this
049       * method returns a {@link Set}, instead of the {@link java.util.Collection}
050       * specified in the {@link Multimap} interface.
051       */
052      @Override
053      Set<V> get(@Nullable K key);
054    
055      /**
056       * {@inheritDoc}
057       *
058       * <p>Because a {@code SetMultimap} has unique values for a given key, this
059       * method returns a {@link Set}, instead of the {@link java.util.Collection}
060       * specified in the {@link Multimap} interface.
061       */
062      @Override
063      Set<V> removeAll(@Nullable Object key);
064    
065      /**
066       * {@inheritDoc}
067       *
068       * <p>Because a {@code SetMultimap} has unique values for a given key, this
069       * method returns a {@link Set}, instead of the {@link java.util.Collection}
070       * specified in the {@link Multimap} interface.
071       *
072       * <p>Any duplicates in {@code values} will be stored in the multimap once.
073       */
074      @Override
075      Set<V> replaceValues(K key, Iterable<? extends V> values);
076    
077      /**
078       * {@inheritDoc}
079       *
080       * <p>Because a {@code SetMultimap} has unique values for a given key, this
081       * method returns a {@link Set}, instead of the {@link java.util.Collection}
082       * specified in the {@link Multimap} interface.
083       */
084      @Override
085      Set<Map.Entry<K, V>> entries();
086    
087      /**
088       * {@inheritDoc}
089       *
090       * <p>Though the method signature doesn't say so explicitly, the returned map
091       * has {@link Set} values.
092       */
093      @Override
094      Map<K, Collection<V>> asMap();
095    
096      /**
097       * Compares the specified object to this multimap for equality.
098       *
099       * <p>Two {@code SetMultimap} instances are equal if, for each key, they
100       * contain the same values. Equality does not depend on the ordering of keys
101       * or values.
102       *
103       * <p>An empty {@code SetMultimap} is equal to any other empty {@code
104       * Multimap}, including an empty {@code ListMultimap}.
105       */
106      @Override
107      boolean equals(@Nullable Object obj);
108    }