net.amygdalum.stringsearchalgorithms.search.AbstractStringFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stringsearchalgorithms Show documentation
Show all versions of stringsearchalgorithms Show documentation
Searching and Matching Strings with efficient algorithms:
- Knuth-Morris-Pratt
- Shift-And/Or
- Boyer-Moore-Horspool
- Sunday (QuickSearch)
- BNDM
- BOM
- Aho-Corasick
- Set-Horspool
- Wu-Manber
- Set-BOM
package net.amygdalum.stringsearchalgorithms.search;
import static net.amygdalum.stringsearchalgorithms.search.MatchOption.NON_OVERLAP;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractStringFinder implements StringFinder {
private boolean nonOverlap;
public AbstractStringFinder(StringFinderOption... options) {
nonOverlap = NON_OVERLAP.in(options);
}
public abstract StringMatch findNext();
public abstract void skipTo(long pos);
@Override
public List findAll() {
List matches = new ArrayList<>();
long last = -1;
while (true) {
StringMatch match = findNext();
if (match == null) {
return matches;
} else {
matches.add(match);
if (nonOverlap && match.end() > last) {
last = match.end();
skipTo(last);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy