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