public interface Scanner<T> extends Closeable
| Modifier and Type | Method and Description |
|---|---|
boolean |
advance()
Try to update current to the next item, if there is one.
|
default Scanner<T> |
advanceUntil(Predicate<? super T> predicate)
Stop the scanner when the predicate matches, excluding the item that caused it to stop.
|
default Scanner<T> |
advanceWhile(Predicate<? super T> predicate)
Stop the scanner when the predicated fails to match, excluding the item that caused it to stop.
|
default boolean |
allMatch(Predicate<? super T> predicate)
Apply the Predicate to every item in the Scanner, returning whether they all match.
|
default boolean |
anyMatch(Predicate<? super T> predicate)
Apply the predicate to each item in the Scanner until one matches, returning true, otherwise return false if the
Scanner is consumed with no matches.
|
default Scanner<T> |
append(Iterable<T> iterable)
Concats the provided Iterable items after the current Scanner.
|
default Scanner<T> |
append(Scanner<T> scanner)
Concats the provided Scanner after the current Scanner.
|
default Scanner<T> |
append(T... items)
Concats the provided array items after the current Scanner.
|
default <R> R |
apply(Function<Scanner<T>,R> function)
Beta: Apply the provided Function which returns another Scanner.
|
default Scanner<List<T>> |
batch(int batchSize) |
default void |
close()
Override to cleanup any resources.
|
default <R> Scanner<R> |
collate(Function<? super T,Scanner<R>> mapper)
Similar to the merge phase of a merge sort, assuming the input Scanners are sorted.
|
default <R> Scanner<R> |
collate(Function<? super T,Scanner<R>> mapper,
Comparator<? super R> comparator)
Similar to the merge phase of a merge sort, assuming the input Scanners are sorted.
|
default <R,A> R |
collect(Collector<? super T,A,R> collector) |
default <C extends Collection<T>> |
collect(Supplier<C> collectionSupplier) |
default <R> Scanner<R> |
concat(Function<? super T,Scanner<R>> mapToScanner)
Combine the items from multiple Scanners into a single Scanner.
|
static <T> Scanner<T> |
concat(Iterable<T>... iterables)
Combine the items from multiple Iterables into a single Scanner.
|
static <T> Scanner<T> |
concat(Scanner<T>... scanners)
Combine the items from multiple Scanners into a single Scanner.
|
default <R> Scanner<R> |
concatIter(Function<? super T,Iterable<R>> mapToIterable)
Combine the items from multiple Iterables into a single Scanner.
|
default long |
count()
Advance through every item in the Scanner, returning the count of items seen.
|
T |
current() |
default Scanner<T> |
deduplicateConsecutive()
Skips consecutive duplicates.
|
default Scanner<T> |
deduplicateConsecutiveBy(Function<T,?> mapper)
Skips items where the mapper outputs the same value as the previous item.
|
default Scanner<T> |
distinct() |
default Scanner<T> |
distinctBy(Function<T,?> mapper) |
default Scanner<T> |
each(Consumer<? super T> consumer)
Calls Consumer::accept on each item.
|
static <T> Scanner<T> |
empty() |
default Scanner<T> |
exclude(Predicate<? super T> predicate)
Skips items where the Predicate returns true.
|
default Optional<T> |
findFirst()
Return the first item encountered in the Scanner, wrapped in an Optional, otherwise Optional.empty() if no items
were found.
|
default Optional<T> |
findLast()
Advance through every item in the Scanner, returning the last item wrapped in an Optional, otherwise
Optional.empty() if the Scanner had no items.
|
default Optional<T> |
findMax(Comparator<? super T> comparator)
Advance through all items, retaining the maximum as computed by the Comparator and returning it.
|
default Optional<T> |
findMin(Comparator<? super T> comparator)
Advance through all items, retaining the minimum as computed by the Comparator and returning it.
|
default Scanner<T> |
flush(Consumer<List<T>> consumer) |
default void |
forEach(Consumer<? super T> action)
Perform an operation on each item.
|
static <T> Scanner<T> |
generate(Supplier<T> supplier) |
default <K> Map<K,List<T>> |
groupBy(Function<T,K> keyFunction) |
default <K,V> Map<K,List<V>> |
groupBy(Function<T,K> keyFunction,
Function<T,V> valueFunction) |
default <K,V,M extends Map<K,List<V>>> |
groupBy(Function<T,K> keyFunction,
Function<T,V> valueFunction,
Supplier<M> mapSupplier) |
default <K,V,C extends Collection<V>,M extends Map<K,C>> |
groupBy(Function<T,K> keyFunction,
Function<T,V> valueFunction,
Supplier<M> mapSupplier,
Supplier<C> collectionSupplier) |
default boolean |
hasAny()
Test whether the first advance() returns true.
|
default Scanner<T> |
include(Predicate<? super T> predicate)
Skips items where the Predicate returns false.
|
default boolean |
isEmpty()
Test whether the first advance() returns false.
|
default Iterable<T> |
iterable() |
static <T> Scanner<T> |
iterate(T seed,
UnaryOperator<T> unaryOperator)
Generate a sequence where each item is calculated off the one before it.
|
default Iterator<T> |
iterator() |
default Scanner<T> |
limit(long limit)
Ends the Scanner when the limit has been reached.
|
default <R> Scanner<R> |
link(Function<Scanner<T>,BaseLinkedScanner<T,R>> scannerBuilder)
A caller can extend BaseLinkedScanner, which has exception handling logic, and fluently include it in the
Scanner pipeline.
|
default List<T> |
list() |
default <R> R |
listTo(Function<List<T>,R> mapper) |
default <R> Scanner<R> |
map(Function<? super T,? extends R> mapper)
For each input item, outputs the result of Function::apply.
|
default Scanner<T> |
maxN(Comparator<? super T> comparator,
int num)
Retains the max N items as defined by the comparator and returns a Scanner of them in descending order.
|
default Scanner<T> |
minN(Comparator<? super T> comparator,
int num)
Retains the min N items as defined by the comparator and returns a Scanner of them in ascending order.
|
default boolean |
noneMatch(Predicate<? super T> predicate)
Return false as soon as the Predicate passes, otherwise true if all items fail the Predicate.
|
static <T> Scanner<T> |
of(Iterable<T> iterable)
Create a Scanner of items in the Iterable.
|
static <T> Scanner<T> |
of(Iterator<T> iterator)
Create a Scanner of items in the Iterator.
|
static <T> Scanner<T> |
of(Stream<T> stream)
Create a Scanner of items in the Stream.
|
static <T> Scanner<T> |
of(T... array)
Create a Scanner of items in the array.
|
static <T> Scanner<T> |
of(T object)
Convert an Object into a Scanner.
|
static <T> Scanner<T> |
ofNullable(T object)
Convert an Object into a Scanner if non-null.
|
default ParallelScanner<T> |
parallel(ParallelScannerContext context) |
default Scanner<T> |
prefetch(ExecutorService exec,
int batchSize) |
default Optional<T> |
reduce(BinaryOperator<T> reducer) |
default T |
reduce(T seed,
BinaryOperator<T> reducer) |
default Scanner<RetainingGroup<T>> |
retain(int retaining)
For retaining a window of N previous items.
|
default Scanner<T> |
reverse()
Collect all items into an List and return a Scanner that iterates through them backwards.
|
default Scanner<T> |
sample(long sampleSize,
boolean includeLast)
Return every Nth item.
|
default Scanner<T> |
shuffle() |
default Scanner<T> |
skip(long numToSkip)
Skip the leading items from the Scanner.
|
default Scanner<T> |
sort() |
default Scanner<T> |
sort(Comparator<? super T> comparator) |
default Scanner<Scanner<T>> |
splitBy(Function<T,?> mapper)
Applies the Function to each item in the Scanner, returning a new Scanner each time the mapped value changes.
|
default Stream<T> |
stream() |
default DoubleStream |
streamDoubles(ToDoubleFunction<? super T> mapper) |
default IntStream |
streamInts(ToIntFunction<? super T> mapper) |
default LongStream |
streamLongs(ToLongFunction<? super T> mapper) |
default List<T> |
take(int numToTake)
Consume up to N items without closing, only closing the scanner if the last item was consumed.
|
default void |
then(Consumer<Scanner<T>> consumer)
Beta: Pass the current Scanner to a method that will Consume this Scanner and return nothing.
|
default Object[] |
toArray() |
default Map<T,T> |
toMap() |
default <K> Map<K,T> |
toMap(Function<T,K> keyFunction) |
default <K,V> Map<K,V> |
toMap(Function<T,K> keyFunction,
Function<T,V> valueFunction) |
default <K,V> Map<K,V> |
toMap(Function<T,K> keyFunction,
Function<T,V> valueFunction,
BinaryOperator<V> mergeFunction) |
default <K,V> Map<K,V> |
toMap(Function<T,K> keyFunction,
Function<T,V> valueFunction,
ScannerToMap.Replace replacePolicy) |
default <K,V,M extends Map<K,V>> |
toMapSupplied(Function<T,K> keyFunction,
Function<T,V> valueFunction,
BinaryOperator<V> mergeFunction,
Supplier<M> mapSupplier) |
default <K,V,M extends Map<K,V>> |
toMapSupplied(Function<T,K> keyFunction,
Function<T,V> valueFunction,
ScannerToMap.Replace replacePolicy,
Supplier<M> mapSupplier) |
default <K,V,M extends Map<K,V>> |
toMapSupplied(Function<T,K> keyFunction,
Function<T,V> valueFunction,
Supplier<M> mapSupplier) |
default <K,M extends Map<K,T>> |
toMapSupplied(Function<T,K> keyFunction,
Supplier<M> mapSupplier) |
boolean advance()
T current()
default void close()
close in interface AutoCloseableclose in interface Closeabledefault void forEach(Consumer<? super T> action)
action - Consumer::accept is performed on each itemdefault List<T> take(int numToTake)
numToTake - Maximum returned itemsstatic <T> Scanner<T> empty()
static <T> Scanner<T> generate(Supplier<T> supplier)
supplier - Supplier that generates items indefinitelystatic <T> Scanner<T> iterate(T seed, UnaryOperator<T> unaryOperator)
seed - The first itemunaryOperator - A function applied to the current item to generate the next itemstatic <T> Scanner<T> ofNullable(T object)
object - A nullable Objectstatic <T> Scanner<T> of(T object)
object - A non-null Object@SafeVarargs static <T> Scanner<T> of(T... array)
array - An array or var-argsstatic <T> Scanner<T> of(Iterator<T> iterator)
iterator - An Iteratorstatic <T> Scanner<T> of(Iterable<T> iterable)
iterable - An Iterable, which includes any Collectionstatic <T> Scanner<T> of(Stream<T> stream)
stream - A Streamdefault <R> Scanner<R> concatIter(Function<? super T,Iterable<R>> mapToIterable)
mapToIterable - Converts the input items into the Iterables to be combineddefault <R> Scanner<R> concat(Function<? super T,Scanner<R>> mapToScanner)
mapToScanner - Converts the input items into the Scanners to be combined@SafeVarargs static <T> Scanner<T> concat(Scanner<T>... scanners)
scanners - Input Scanners to be combined@SafeVarargs static <T> Scanner<T> concat(Iterable<T>... iterables)
iterables - Input Iterables to be combined, where Iterable includes any Collectiondefault Scanner<T> append(Scanner<T> scanner)
default Scanner<T> append(T... items)
default Scanner<T> append(Iterable<T> iterable)
default <R> Scanner<R> collate(Function<? super T,Scanner<R>> mapper)
default <R> Scanner<R> collate(Function<? super T,Scanner<R>> mapper, Comparator<? super R> comparator)
default <R> Scanner<R> link(Function<Scanner<T>,BaseLinkedScanner<T,R>> scannerBuilder)
scannerBuilder - Function to build the BaseLinkedScannerdefault <R> R apply(Function<Scanner<T>,R> function)
function - A method reference that accepts this Scannerdefault void then(Consumer<Scanner<T>> consumer)
consumer - A method reference that accepts this Scannerdefault ParallelScanner<T> parallel(ParallelScannerContext context)
default Scanner<T> prefetch(ExecutorService exec, int batchSize)
default Scanner<T> advanceUntil(Predicate<? super T> predicate)
default Scanner<T> advanceWhile(Predicate<? super T> predicate)
default Scanner<T> deduplicateConsecutive()
default Scanner<T> deduplicateConsecutiveBy(Function<T,?> mapper)
default Scanner<T> exclude(Predicate<? super T> predicate)
default Scanner<T> include(Predicate<? super T> predicate)
default <R> Scanner<R> map(Function<? super T,? extends R> mapper)
default Scanner<RetainingGroup<T>> retain(int retaining)
retaining - The number of extra items to retain, in addition to the Scanner's default of zero.default Scanner<T> sample(long sampleSize, boolean includeLast)
sampleSize - A Scanner with 8 items and sample size 8 will return either 2 or 3 results.includeLast - Whether to include the last item in case of a partial sample.default Scanner<T> skip(long numToSkip)
numToSkip - Skips up to this many items, or fewer if the Scanner had fewer items.default Scanner<Scanner<T>> splitBy(Function<T,?> mapper)
default boolean allMatch(Predicate<? super T> predicate)
default boolean anyMatch(Predicate<? super T> predicate)
default long count()
default Optional<T> findFirst()
default Optional<T> findLast()
default Optional<T> findMax(Comparator<? super T> comparator)
default Optional<T> findMin(Comparator<? super T> comparator)
default boolean hasAny()
default boolean isEmpty()
default boolean noneMatch(Predicate<? super T> predicate)
default Optional<T> reduce(BinaryOperator<T> reducer)
default T reduce(T seed, BinaryOperator<T> reducer)
default <C extends Collection<T>> C collect(Supplier<C> collectionSupplier)
default Scanner<T> maxN(Comparator<? super T> comparator, int num)
default Scanner<T> minN(Comparator<? super T> comparator, int num)
default Scanner<T> reverse()
default Scanner<T> sort(Comparator<? super T> comparator)
default Object[] toArray()
default <K,V> Map<K,V> toMap(Function<T,K> keyFunction, Function<T,V> valueFunction, ScannerToMap.Replace replacePolicy)
default <K,V> Map<K,V> toMap(Function<T,K> keyFunction, Function<T,V> valueFunction, BinaryOperator<V> mergeFunction)
default <K,M extends Map<K,T>> M toMapSupplied(Function<T,K> keyFunction, Supplier<M> mapSupplier)
default <K,V,M extends Map<K,V>> M toMapSupplied(Function<T,K> keyFunction, Function<T,V> valueFunction, Supplier<M> mapSupplier)
default <K,V,M extends Map<K,V>> M toMapSupplied(Function<T,K> keyFunction, Function<T,V> valueFunction, ScannerToMap.Replace replacePolicy, Supplier<M> mapSupplier)
default <K,V,M extends Map<K,V>> M toMapSupplied(Function<T,K> keyFunction, Function<T,V> valueFunction, BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier)
default <K,V> Map<K,List<V>> groupBy(Function<T,K> keyFunction, Function<T,V> valueFunction)
default <K,V,M extends Map<K,List<V>>> M groupBy(Function<T,K> keyFunction, Function<T,V> valueFunction, Supplier<M> mapSupplier)
default <K,V,C extends Collection<V>,M extends Map<K,C>> M groupBy(Function<T,K> keyFunction, Function<T,V> valueFunction, Supplier<M> mapSupplier, Supplier<C> collectionSupplier)
default IntStream streamInts(ToIntFunction<? super T> mapper)
default LongStream streamLongs(ToLongFunction<? super T> mapper)
default DoubleStream streamDoubles(ToDoubleFunction<? super T> mapper)
Copyright © 2009–2022. All rights reserved.