Source Code : Map from a given key to a set of values

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

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

   
    
    
    
    
    
  

Thank with us