
org.snpeff.collections.AutoHashMap 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.HashMap;
/**
* A Hash that creates new elements if they don't exists
* @author pcingola
*
* @param
* @param
*/
public class AutoHashMap extends HashMap {
private static final long serialVersionUID = 255818677257868365L;
V instance;
public AutoHashMap(V instance) {
super();
this.instance = instance;
}
@SuppressWarnings("unchecked")
public V getOrCreate(K key) {
V v = get(key);
if (v == null) {
try {
v = (V) instance.getClass().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
put(key, v);
}
return v;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy