com.hfg.bio.seq.pattern.SeqPatternMatcher 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.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;
}
}