View Javadoc
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    *      http://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  package org.apache.commons.collections4;
18  
19  import java.util.Set;
20  
21  /**
22   * Defines a map that holds a set of values against each key.
23   * <p>
24   * A {@code SetValuedMap} is a Map with slightly different semantics:
25   * </p>
26   * <ul>
27   *   <li>Putting a value into the map will add the value to a {@link Set} at that key.</li>
28   *   <li>Getting a value will return a {@link Set}, holding all the values put to that key.</li>
29   * </ul>
30   *
31   * @param <K> the type of the keys in this map
32   * @param <V> the type of the values in this map
33   * @since 4.1
34   */
35  public interface SetValuedMap<K, V> extends MultiValuedMap<K, V> {
36  
37      /**
38       * Gets the set of values associated with the specified key.
39       * <p>
40       * Implementations typically return an empty {@code Set} if no values
41       * 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
46       *   empty {@code Set} for no mapping
47       * @throws NullPointerException if the key is null and null keys are invalid
48       */
49      @Override
50      Set<V> get(K key);
51  
52      /**
53       * Removes all values associated with the specified key.
54       * <p>
55       * The returned set <i>may</i> be modifiable, but updates will not be
56       * propagated to this set-valued map. In case no mapping was stored for the
57       * specified key, an empty, unmodifiable set will be returned.
58       *
59       * @param key  the key to remove values from
60       * @return the {@code Set} of values removed, implementations should
61       *   return null for no mapping found, but may return an empty collection
62       * @throws UnsupportedOperationException if the map is unmodifiable
63       * @throws NullPointerException if the key is null and null keys are invalid
64       */
65      @Override
66      Set<V> remove(Object key);
67  }