1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.collections4;
19
20 import java.util.Set;
21
22 /**
23 * Defines a map that holds a set of values against each key.
24 * <p>
25 * A {@code SetValuedMap} is a Map with slightly different semantics:
26 * </p>
27 * <ul>
28 * <li>Putting a value into the map will add the value to a {@link Set} at that key.</li>
29 * <li>Getting a value will return a {@link Set}, holding all the values put to that key.</li>
30 * </ul>
31 *
32 * @param <K> The type of the keys in this map.
33 * @param <V> The type of the values in this map.
34 * @since 4.1
35 */
36 public interface SetValuedMap<K, V> extends MultiValuedMap<K, V> {
37
38 /**
39 * Gets the set of values associated with the specified key.
40 * <p>
41 * Implementations typically return an empty {@code Set} if no values have been mapped to the key.
42 * </p>
43 *
44 * @param key The key to retrieve.
45 * @return The {@code Set} of values, implementations should return an empty {@code Set} for no mapping.
46 * @throws NullPointerException if the key is null and null keys are invalid.
47 */
48 @Override
49 Set<V> get(K key);
50
51 /**
52 * Removes all values associated with the specified key.
53 * <p>
54 * The returned set <em>may</em> be modifiable, but updates will not be propagated to this set-valued map. In case no mapping was stored for the specified
55 * key, an empty, unmodifiable set will be returned.
56 * </p>
57 *
58 * @param key The key to remove values from.
59 * @return The {@code Set} of values removed, implementations should return null for no mapping found, but may return an empty collection.
60 * @throws UnsupportedOperationException if the map is unmodifiable.
61 * @throws NullPointerException if the key is null and null keys are invalid.
62 */
63 @Override
64 Set<V> remove(Object key);
65 }