MapSet.java Source code

Java tutorial

Introduction

Here is the source code for MapSet.java

Source

//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);
        }
    }
}