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.List;
21
22 /**
23 * Defines a map that holds a list of values against each key.
24 * <p>
25 * A {@code ListValuedMap} 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 List} at that key.</li>
29 * <li>Getting a value will return a {@link List}, 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 ListValuedMap<K, V> extends MultiValuedMap<K, V> {
37
38 /**
39 * Gets the list of values associated with the specified key.
40 * <p>
41 * This method will return an <strong>empty</strong> list if {@link #containsKey(Object)} returns {@code false}. Changes to the returned list will update
42 * the underlying {@code ListValuedMap} and vice-versa.
43 * </p>
44 *
45 * @param key The key to retrieve.
46 * @return The {@code List} of values, implementations should return an empty {@code List} for no mapping.
47 * @throws NullPointerException if the key is null and null keys are invalid.
48 */
49 @Override
50 List<V> get(K key);
51
52 /**
53 * Removes all values associated with the specified key.
54 * <p>
55 * The returned list <em>may</em> be modifiable, but updates will not be propagated to this list-valued map. In case no mapping was stored for the specified
56 * key, an empty, unmodifiable list will be returned.
57 * </p>
58 *
59 * @param key The key to remove values from.
60 * @return The {@code List} of values removed, implementations typically return an empty, unmodifiable {@code List} for no mapping found.
61 * @throws UnsupportedOperationException if the map is unmodifiable.
62 * @throws NullPointerException if the key is null and null keys are invalid.
63 */
64 @Override
65 List<V> remove(Object key);
66 }