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 * http://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 */ 017package org.apache.commons.collections4; 018 019import java.util.Set; 020 021/** 022 * Defines a map that holds a set of values against each key. 023 * <p> 024 * A {@code SetValuedMap} is a Map with slightly different semantics: 025 * <ul> 026 * <li>Putting a value into the map will add the value to a {@link Set} at that key.</li> 027 * <li>Getting a value will return a {@link Set}, holding all the values put to that key.</li> 028 * </ul> 029 * 030 * @param <K> the type of the keys in this map 031 * @param <V> the type of the values in this map 032 * @since 4.1 033 */ 034public interface SetValuedMap<K, V> extends MultiValuedMap<K, V> { 035 036 /** 037 * Gets the set of values associated with the specified key. 038 * <p> 039 * Implementations typically return an empty {@code Set} if no values 040 * have been mapped to the key. 041 * <p> 042 * 043 * @param key the key to retrieve 044 * @return the {@code Set} of values, implementations should return an 045 * empty {@code Set} for no mapping 046 * @throws NullPointerException if the key is null and null keys are invalid 047 */ 048 @Override 049 Set<V> get(K key); 050 051 /** 052 * Removes all values associated with the specified key. 053 * <p> 054 * The returned set <i>may</i> be modifiable, but updates will not be 055 * propagated to this set-valued map. In case no mapping was stored for the 056 * specified key, an empty, unmodifiable set will be returned. 057 * 058 * @param key the key to remove values from 059 * @return the {@code Set} of values removed, implementations should 060 * return null for no mapping found, but may return an empty collection 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 Set<V> remove(Object key); 066}