001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * https://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.collections4; 019 020import java.util.List; 021 022/** 023 * Defines a map that holds a list of values against each key. 024 * <p> 025 * A {@code ListValuedMap} is a Map with slightly different semantics: 026 * </p> 027 * <ul> 028 * <li>Putting a value into the map will add the value to a {@link List} at that key.</li> 029 * <li>Getting a value will return a {@link List}, holding all the values put to that key.</li> 030 * </ul> 031 * 032 * @param <K> The type of the keys in this map 033 * @param <V> The type of the values in this map 034 * @since 4.1 035 */ 036public interface ListValuedMap<K, V> extends MultiValuedMap<K, V> { 037 038 /** 039 * Gets the list of values associated with the specified key. 040 * <p> 041 * This method will return an <strong>empty</strong> list if {@link #containsKey(Object)} returns {@code false}. Changes to the returned list will update 042 * the underlying {@code ListValuedMap} and vice-versa. 043 * </p> 044 * 045 * @param key The key to retrieve. 046 * @return The {@code List} of values, implementations should return an empty {@code List} for no mapping. 047 * @throws NullPointerException if the key is null and null keys are invalid. 048 */ 049 @Override 050 List<V> get(K key); 051 052 /** 053 * Removes all values associated with the specified key. 054 * <p> 055 * 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 056 * key, an empty, unmodifiable list will be returned. 057 * </p> 058 * 059 * @param key The key to remove values from. 060 * @return The {@code List} of values removed, implementations typically return an empty, unmodifiable {@code List} for no mapping found. 061 * @throws UnsupportedOperationException if the map is unmodifiable. 062 * @throws NullPointerException if the key is null and null keys are invalid. 063 */ 064 @Override 065 List<V> remove(Object key); 066}