E
- The element type.public final class StreamLikeIterator<E> extends Object implements Iterator<E>
Iterator.remove()
operation if the original iterator does, and no intermediate operation of
this class removes support for the operation.Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(Predicate<? super E> predicate)
Returns whether or not all elements of this iterator match a specific predicate.
|
boolean |
anyMatch(Predicate<? super E> predicate)
Returns whether or not at least one element of this iterator matches a specific predicate.
|
static <E> StreamLikeIterator<E> |
backedBy(Iterator<E> iterator)
Creates a new
StreamLikeIterator backed by another iterator. |
<R,A> R |
collect(Collector<? super E,A,R> collector)
Performs a reduction on the elements of this iterator.
|
<R> R |
collect(Supplier<R> supplier,
BiConsumer<R,? super E> accumulator)
Performs a reduction on the elements of this iterator.
|
long |
count()
Returns the number of elements of this iterator.
|
StreamLikeIterator<E> |
distinct()
Returns an iterator that returns the distinct elements of this iterator (according to
Object.equals(Object) ). |
StreamLikeIterator<E> |
dropWhile(Predicate<? super E> predicate)
Returns an iterator that discards elements of this iterator until an element does not match a specific predicate.
|
StreamLikeIterator<E> |
filter(Predicate<? super E> predicate)
Returns an iterator that filters out elements of this iterator.
|
Optional<E> |
findFirst()
Returns the first element of this iterator.
|
<R> StreamLikeIterator<R> |
flatMap(Function<? super E,? extends Iterator<? extends R>> mapper)
Returns an iterator that replaces the elements of this iterator with the elements of a mapped iterator produced by applying a function to each
element.
|
void |
forEachRemaining(Consumer<? super E> action) |
boolean |
hasNext() |
StreamLikeIterator<E> |
limit(long maxSize)
Returns an iterator that truncates this iterator.
|
<R> StreamLikeIterator<R> |
map(Function<? super E,? extends R> mapper)
Returns an iterator that applies a function to the elements of this iterator.
|
Optional<E> |
max(Comparator<? super E> comparator)
Returns the maximum element of this iterator according to a specific comparator.
|
Optional<E> |
min(Comparator<? super E> comparator)
Returns the minimum element of this iterator according to a specific comparator.
|
E |
next() |
boolean |
noneMatch(Predicate<? super E> predicate)
Returns whether or not no element of this iterator matches a specific predicate.
|
StreamLikeIterator<E> |
peek(Consumer<? super E> action)
Returns an iterator that performs an additional action for each element of this iterator.
|
Optional<E> |
reduce(BinaryOperator<E> accumulator)
Performs a reduction on the elements of this iterator.
|
E |
reduce(E identity,
BinaryOperator<E> accumulator)
Performs a reduction on the elements of this iterator.
|
<U> U |
reduce(U identity,
BiFunction<U,? super E,U> accumulator)
Performs a reduction on the elements of this iterator.
|
void |
remove() |
StreamLikeIterator<E> |
skip(long n)
Returns an iterator that discards a number of elements at the start of this iterator.
|
StreamLikeIterator<E> |
takeWhile(Predicate<? super E> predicate)
Returns an iterator that discards elements of this iterator once an element matches a specific predicate.
|
public void forEachRemaining(Consumer<? super E> action)
forEachRemaining
in interface Iterator<E>
public StreamLikeIterator<E> filter(Predicate<? super E> predicate)
predicate
- A predicate that determines whether or not elements should be included.NullPointerException
- If the given predicate is null
.Stream.filter(Predicate)
public <R> StreamLikeIterator<R> map(Function<? super E,? extends R> mapper)
R
- The element type of the resulting iterator.mapper
- The function to apply.NullPointerException
- If the given function is null
.Stream.map(Function)
public <R> StreamLikeIterator<R> flatMap(Function<? super E,? extends Iterator<? extends R>> mapper)
Iterator.remove()
operation.R
- The element type of the resulting iterator.mapper
- The function to apply.NullPointerException
- If the given function is null
.Stream.flatMap(Function)
public StreamLikeIterator<E> distinct()
Object.equals(Object)
).Stream.distinct()
public StreamLikeIterator<E> peek(Consumer<? super E> action)
action
- The action to perform.NullPointerException
- If the given action is null
.Stream.peek(Consumer)
public StreamLikeIterator<E> limit(long maxSize)
maxSize
- The maximum number of elements in the returned iterator.IllegalArgumentException
- If the given maximum number of elements is negative.Stream.limit(long)
public StreamLikeIterator<E> skip(long n)
n
- The number of elements to discard.n
elements of this iterator.IllegalArgumentException
- If the given number of elements is negative.Stream.skip(long)
public StreamLikeIterator<E> takeWhile(Predicate<? super E> predicate)
predicate
- The predicate that determines when elements are discarded.NullPointerException
- If the given predicate is null
.public StreamLikeIterator<E> dropWhile(Predicate<? super E> predicate)
predicate
- The predicate that determines until when elements are discarded.NullPointerException
- If the given predicate is null
.public E reduce(E identity, BinaryOperator<E> accumulator)
identity
- The identity value for the accumulating function.accumulator
- A function for combining two values.NullPointerException
- If the given accumulator function is null
.Stream.reduce(Object, BinaryOperator)
public Optional<E> reduce(BinaryOperator<E> accumulator)
accumulator
- A function for combining two values.Optional
describing the result of the reduction, or Optional.empty()
if this iterator has no elements.NullPointerException
- If the given accumulator function or the result of the reduction is null
.Stream.reduce(BinaryOperator)
public <U> U reduce(U identity, BiFunction<U,? super E,U> accumulator)
U
- The element type of the resulting iterator.identity
- The identity value for the accumulating function.accumulator
- A function for combining two values.NullPointerException
- If the given accumulator function is null
.Stream.reduce(Object, BiFunction, BinaryOperator)
public <R> R collect(Supplier<R> supplier, BiConsumer<R,? super E> accumulator)
R
- The element type of the resulting iterator.supplier
- A supplier for mutable result containers.accumulator
- A function that folds elements into a result container.NullPointerException
- If the given supplier or accumulator function is null
.Stream.collect(Supplier, BiConsumer, BiConsumer)
public <R,A> R collect(Collector<? super E,A,R> collector)
R
- The element type of the resulting iterator.A
- The intermediate accumulation type of the collector.collector
- The collector to use for the reduction.NullPointerException
- If the given collector is null
.Stream.collect(Collector)
public Optional<E> min(Comparator<? super E> comparator)
comparator
- The comparator to use for comparing elements.Optional
describing the minimum element, or Optional.empty()
if this iterator has no elements.NullPointerException
- If the given comparator is null
.Stream.min(Comparator)
public Optional<E> max(Comparator<? super E> comparator)
comparator
- The comparator to use for comparing elements.Optional
describing the maximum element, or Optional.empty()
if this iterator has no elements.NullPointerException
- If the given comparator is null
.Stream.max(Comparator)
public long count()
Stream.count()
public boolean anyMatch(Predicate<? super E> predicate)
predicate
- The predicate to apply to elements of this iterator.true
if at least one element of this iterator matches the given predicate, or false
otherwise.NullPointerException
- If the given predicate is null
.Stream.anyMatch(Predicate)
public boolean allMatch(Predicate<? super E> predicate)
predicate
- The predicate to apply to elements of this iterator.true
if all elements of this iterator match the given predicate, or false
otherwise.NullPointerException
- If the given predicate is null
.Stream.allMatch(Predicate)
public boolean noneMatch(Predicate<? super E> predicate)
predicate
- The predicate to apply to elements of this iterator.true
if no element of this iterator matches the given predicate, or false
otherwise.NullPointerException
- If the given predicate is null
.Stream.noneMatch(Predicate)
public Optional<E> findFirst()
Optional
describing the first element, or Optional.empty()
if this iterator has no elements.Stream.findFirst()
public static <E> StreamLikeIterator<E> backedBy(Iterator<E> iterator)
StreamLikeIterator
backed by another iterator.E
- The element type.iterator
- The backing iterator.StreamLikeIterator
Copyright © 2022. All rights reserved.