All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.bio.seq.AminoAcidComposition Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
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;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy