Class Scanner<T>
- java.lang.Object
-
- dev.aherscu.qa.testing.extra.supermachine.Scanner<T>
-
- Type Parameters:
T
- the type of elements composing the data structure.
- Direct Known Subclasses:
BeanScanner
,StreamScanner
public abstract class Scanner<T> extends Object
Abstraction wrapping a data structure that can be walked through to produce streams.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract <X> Scanner<X>
create(Stream<X> source)
Constructs a scanner out of a source stream.<X> Scanner<X>
extract(Function<T,X> extractor)
Apply a function to every items of this scanner and returns a scanner emitting the non-null results.Scanner<T>
filter(Predicate<T> predicate)
Filters out items according to predicate.<X> Scanner<X>
find(Class<X> clazz)
Scans the elements of the source and returns a scanner emitting relevant items of the given type.Stream<T>
stream()
Extracts the items of this scanner as a stream.<X> Scanner<X>
then(Function<Scanner<T>,Scanner<X>>... fns)
Transforms this scanner into one or more derived scanners and merges their emitted items.<X> Scanner<X>
walk(Class<X> clazz)
Scans the elements of the source and returns a scanner emitting all resulting items of the given type.
-
-
-
Method Detail
-
extract
public <X> Scanner<X> extract(Function<T,X> extractor)
Apply a function to every items of this scanner and returns a scanner emitting the non-null results.- Type Parameters:
X
- the returned type.- Parameters:
extractor
- the function applied to each item, can return null.- Returns:
- a scanner emitting non-null results of the function applied to items.
-
filter
public Scanner<T> filter(Predicate<T> predicate)
Filters out items according to predicate.- Parameters:
predicate
- the condition to emit the items.- Returns:
- a scanner emitting the items matching the predicate.
-
find
public <X> Scanner<X> find(Class<X> clazz)
Scans the elements of the source and returns a scanner emitting relevant items of the given type. This method can return fewer items according to subclass logic. Subclasses implement the actual scanning algorithm.- Type Parameters:
X
- type of the selector and resulting items.- Parameters:
clazz
- the type selector.- Returns:
- a scanner emitting the selected items.
-
stream
public Stream<T> stream()
Extracts the items of this scanner as a stream.- Returns:
- a stream of items.
-
then
@SafeVarargs public final <X> Scanner<X> then(Function<Scanner<T>,Scanner<X>>... fns)
Transforms this scanner into one or more derived scanners and merges their emitted items.- Type Parameters:
X
- the common type of items resulting of the scanners to merge.- Parameters:
fns
- the functions that will be applied to this scanner and produce the scanners to merge.- Returns:
- a scanner merging the result of the composed scanners.
-
walk
public <X> Scanner<X> walk(Class<X> clazz)
Scans the elements of the source and returns a scanner emitting all resulting items of the given type. Subclasses implement the actual scanning algorithm.- Type Parameters:
X
- type of the selector and resulting items.- Parameters:
clazz
- the type selector.- Returns:
- a scanner emitting the selected items.
-
create
protected abstract <X> Scanner<X> create(Stream<X> source)
Constructs a scanner out of a source stream.- Type Parameters:
X
- the type of elements in the source stream.- Parameters:
source
- the wrapped stream, will contain only one element when it is a root.- Returns:
- a scanner based on the given source.
-
-