com.hfg.bio.seq.AminoAcidComposition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.bio.seq;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.hfg.bio.AminoAcid;
import com.hfg.exception.ProgrammingException;
public class AminoAcidComposition
{
private Map mMap = new HashMap<>(30);
//--------------------------------------------------------------------------
public void addAll(AminoAcidComposition inAAComposition)
{
for (Map.Entry entry : inAAComposition.mMap.entrySet())
{
increment(entry.getKey(), entry.getValue()[0]);
}
}
//--------------------------------------------------------------------------
public void increment(AminoAcid inAA)
{
increment(inAA, 1);
}
//--------------------------------------------------------------------------
public void increment(AminoAcid inAA, int inAmount)
{
int[] counter = mMap.computeIfAbsent(inAA, c -> new int[1]);
counter[0] += inAmount;
}
//--------------------------------------------------------------------------
public int get(AminoAcid inAA)
{
int[] counter = mMap.get(inAA);
return (null == counter ? 0 : counter[0]);
}
//--------------------------------------------------------------------------
public int size()
{
return mMap.size();
}
//--------------------------------------------------------------------------
public Set keySet()
{
return mMap.keySet();
}
//--------------------------------------------------------------------------
@Override
public AminoAcidComposition clone()
{
AminoAcidComposition cloneObj;
try
{
cloneObj = (AminoAcidComposition) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new ProgrammingException(e);
}
cloneObj.mMap = new HashMap<>(mMap);
return cloneObj;
}
}