1/*
2 * Copyright (C) 2007 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect;
18
19import com.google.common.annotations.GwtCompatible;
20
21import java.util.Collection;
22import java.util.Map;
23import java.util.Set;
24
25import javax.annotation.Nullable;
26
27/**
28 * A {@code Multimap} that cannot hold duplicate key-value pairs. Adding a
29 * key-value pair that's already in the multimap has no effect.
30 *
31 * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods
32 * each return a {@link Set} of values, while {@link #entries} returns a {@code
33 * Set} of map entries. Though the method signature doesn't say so explicitly,
34 * the map returned by {@link #asMap} has {@code Set} values.
35 *
36 * @author Jared Levy
37 * @since 2.0 (imported from Google Collections Library)
38 */
39@GwtCompatible
40public interface SetMultimap<K, V> extends Multimap<K, V> {
41  /**
42   * {@inheritDoc}
43   *
44   * <p>Because a {@code SetMultimap} has unique values for a given key, this
45   * method returns a {@link Set}, instead of the {@link java.util.Collection}
46   * specified in the {@link Multimap} interface.
47   */
48  @Override
49  Set<V> get(@Nullable K key);
50
51  /**
52   * {@inheritDoc}
53   *
54   * <p>Because a {@code SetMultimap} has unique values for a given key, this
55   * method returns a {@link Set}, instead of the {@link java.util.Collection}
56   * specified in the {@link Multimap} interface.
57   */
58  @Override
59  Set<V> removeAll(@Nullable Object key);
60
61  /**
62   * {@inheritDoc}
63   *
64   * <p>Because a {@code SetMultimap} has unique values for a given key, this
65   * method returns a {@link Set}, instead of the {@link java.util.Collection}
66   * specified in the {@link Multimap} interface.
67   *
68   * <p>Any duplicates in {@code values} will be stored in the multimap once.
69   */
70  @Override
71  Set<V> replaceValues(K key, Iterable<? extends V> values);
72
73  /**
74   * {@inheritDoc}
75   *
76   * <p>Because a {@code SetMultimap} has unique values for a given key, this
77   * method returns a {@link Set}, instead of the {@link java.util.Collection}
78   * specified in the {@link Multimap} interface.
79   */
80  @Override
81  Set<Map.Entry<K, V>> entries();
82
83  /**
84   * {@inheritDoc}
85   *
86   * <p>Though the method signature doesn't say so explicitly, the returned map
87   * has {@link Set} values.
88   */
89  @Override
90  Map<K, Collection<V>> asMap();
91
92  /**
93   * Compares the specified object to this multimap for equality.
94   *
95   * <p>Two {@code SetMultimap} instances are equal if, for each key, they
96   * contain the same values. Equality does not depend on the ordering of keys
97   * or values.
98   *
99   * <p>An empty {@code SetMultimap} is equal to any other empty {@code
100   * Multimap}, including an empty {@code ListMultimap}.
101   */
102  @Override
103  boolean equals(@Nullable Object obj);
104}
105