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

com.hfg.bio.seq.pattern.SeqPatternMatcher Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio.seq.pattern;

import java.util.ArrayList;
import java.util.List;

import com.hfg.bio.seq.BioSequence;
import com.hfg.bio.seq.SeqLocation;
import com.hfg.util.collection.CollectionUtil;

public interface SeqPatternMatcher
{
   public S getTarget();
   public SeqLocation getSeqLocation();

   //---------------------------------------------------------------------------
   public default T find()
   {
      return find(null);
   }

   public T find(SeqLocation inSeqLocation);

   //---------------------------------------------------------------------------
   public default T findLast()
   {
      return findLast(null);
   }

   public default T findLast(SeqLocation inSeqLocation)
   {
      List matches = findAll(inSeqLocation);
      return (CollectionUtil.hasValues(matches) ? matches.get(matches.size() - 1) : null);
   }

   //---------------------------------------------------------------------------
   public default List findAll()
   {
      return findAll(null);
   }

   //---------------------------------------------------------------------------
   public default List findAll(SeqLocation inSeqLocation)
   {
      List matches = null;

      SeqLocation seqLocation;
      if (inSeqLocation != null)
      {
         seqLocation = inSeqLocation.clone();
      }
      else if (getSeqLocation() != null)
      {
         seqLocation = getSeqLocation().clone();
      }
      else
      {
         seqLocation = new SeqLocation(1, getTarget().length());
      }

      T match;
      while ((match = find(seqLocation)) != null)
      {
         if (null == matches)
         {
            matches = new ArrayList<>();
         }

         matches.add(match);

         seqLocation.setStart(match.getSeqLocation().getStart() + 1);

         if (seqLocation.length() <= 0)
         {
            break;
         }
      }

      return matches;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy