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.Set; 021 022/** 023 * Defines a map that holds a set of values against each key. 024 * <p> 025 * A {@code SetValuedMap} 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 Set} at that key.</li> 029 * <li>Getting a value will return a {@link Set}, 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 SetValuedMap<K, V> extends MultiValuedMap<K, V> { 037 038 /** 039 * Gets the set of values associated with the specified key. 040 * <p> 041 * Implementations typically return an empty {@code Set} if no values have been mapped to the key. 042 * </p> 043 * 044 * @param key The key to retrieve. 045 * @return The {@code Set} of values, implementations should return an 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 <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 055 * key, an empty, unmodifiable set will be returned. 056 * </p> 057 * 058 * @param key The key to remove values from. 059 * @return The {@code Set} of values removed, implementations should return null for no mapping found, but may return an empty collection. 060 * @throws UnsupportedOperationException if the map is unmodifiable. 061 * @throws NullPointerException if the key is null and null keys are invalid. 062 */ 063 @Override 064 Set<V> remove(Object key); 065}