T
- type of sequence elements, it is requiredpublic class FastSequenceSearch<T>
extends java.lang.Object
Currently only forward search is implemented, but basically both the search indexable
and the searched indexable can be reversed
before searching.
Although based on integers this may also be used for searches in byte or character sequences.
Constructor and Description |
---|
FastSequenceSearch(java.util.function.BiPredicate<? super T,? super T> equality,
T... searchTerm)
Constructor.
|
FastSequenceSearch(Indexable<T> searchTerm,
java.util.function.BiPredicate<? super T,? super T> equality)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
IntIndexable |
findAllMatches(Indexable<T> data,
boolean allowOverlaps)
Find all matches.
|
int |
findFirst(Indexable<T> data)
Find the first appearance of the search term in the given data.
|
int |
findNext(Indexable<T> data,
int pos)
Find the next appearance of the search term after the given position
in the given data.
|
int |
findNext(Indexable<T> data,
int pos,
int end)
Find the next appearance of the search term after the given start position
and before the given end position in the given data.
|
Indexable<T> |
getSearchTerm()
Get the search term.
|
static <TT> FastSequenceSearch<TT> |
usingDeepEquals(Indexable<TT> searchTerm)
Create a fast sequence search which uses
Objects.deepEquals() for equality. |
static <TT> FastSequenceSearch<TT> |
usingDeepEquals(TT... searchTerm)
Create a fast sequence search which uses
Objects.deepEquals() for equality. |
static <TT> FastSequenceSearch<TT> |
usingEquals(Indexable<TT> searchTerm)
Create a fast sequence search which uses
Objects.equals() for equality. |
static <TT> FastSequenceSearch<TT> |
usingEquals(TT... searchTerm)
Create a fast sequence search which uses
Objects.equals() for equality. |
static <TT> FastSequenceSearch<TT> |
usingIdentity(Indexable<TT> searchTerm)
Create a fast sequence search which uses identity (i.e.
|
static <TT> FastSequenceSearch<TT> |
usingSame(TT... searchTerm)
Create a fast sequence search which uses identity (i.e.
|
public FastSequenceSearch(@NotNull Indexable<T> searchTerm, @NotNull java.util.function.BiPredicate<? super T,? super T> equality)
searchTerm
- term to search forequality
- predicate which defines whether two elements are equal@NotNull public static <TT> FastSequenceSearch<TT> usingEquals(@NotNull Indexable<TT> searchTerm)
Objects.equals()
for equality.TT
- sequence element typesearchTerm
- search term@NotNull @SafeVarargs public static <TT> FastSequenceSearch<TT> usingEquals(@NotNull TT... searchTerm)
Objects.equals()
for equality.TT
- sequence element typesearchTerm
- search term@NotNull public static <TT> FastSequenceSearch<TT> usingDeepEquals(@NotNull Indexable<TT> searchTerm)
Objects.deepEquals()
for equality.TT
- sequence element typesearchTerm
- search term@NotNull @SafeVarargs public static <TT> FastSequenceSearch<TT> usingDeepEquals(@NotNull TT... searchTerm)
Objects.deepEquals()
for equality.TT
- sequence element typesearchTerm
- search term@NotNull public static <TT> FastSequenceSearch<TT> usingIdentity(@NotNull Indexable<TT> searchTerm)
o1 == o2
) for equality.TT
- sequence element typesearchTerm
- search term@NotNull @SafeVarargs public static <TT> FastSequenceSearch<TT> usingSame(@NotNull TT... searchTerm)
o1 == o2
) for equality.TT
- sequence element typesearchTerm
- search term@NotNull public Indexable<T> getSearchTerm()
public int findFirst(@NotNull Indexable<T> data)
data
- data to search through-1
if there was nothing foundpublic int findNext(@NotNull Indexable<T> data, int pos)
data
- data to search throughpos
- position to start the search-1
if there was nothing found between the position and the end of datapublic int findNext(@NotNull Indexable<T> data, int pos, int end)
data
- data to search throughpos
- position to start the searchend
- position to end the search, the whole search term has to fit before this position to be found-1
if there was nothing found between the position and the end of data@NotNull public IntIndexable findAllMatches(@NotNull Indexable<T> data, boolean allowOverlaps)
data
- data to searchallowOverlaps
- allow overlapping sequences in the matches?