
org.snpeff.collections.MultivalueHashMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SnpEff Show documentation
Show all versions of SnpEff Show documentation
Variant annotation and effect prediction package.
The newest version!
package org.snpeff.collections;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
/**
* A Hash that can hold multiple values for each key
*
* @author pcingola
*/
public class MultivalueHashMap extends HashMap> {
private static final long serialVersionUID = -8860279543165990227L;
public MultivalueHashMap() {
super();
}
/**
* Add multiple values
*/
public void add(K key, Collection values) {
getOrCreate(key).addAll(values); // Add all to the list
}
/**
* Add a single value
*/
public void add(K key, V value) {
getOrCreate(key).add(value); // Add to the list
}
/**
* Get a list of values (or create it if not available)
*/
public List getOrCreate(K key) {
// Get list
LinkedList list = get(key);
if (list == null) { // No list? Create one
list = new LinkedList();
put(key, list);
}
return list;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy