Map from a given key to a set of values
//package org.streets.commons.collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
* Map from a given key to a set of values
*
* @author dzb
*/
public class MapSet<K, V> extends HashMap<K, Set<V>> {
private static final long serialVersionUID = 3462998132471897564L;
public void add(K key, V value) {
Set<V> values = get(key);
if (values == null) {
values = new HashSet<V>();
put(key, values);
}
values.add(value);
}
public void remove(K key, V value) {
Set<V> values = get(key);
if (values != null) {
values.remove(value);
}
}
}
Related examples in the same category