Modifier and Type | Method and Description |
---|---|
static <E> boolean |
allMatch(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns whether or not all elements of an iterator match a specific predicate.
|
static <E> boolean |
anyMatch(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns whether or not at least one element of an iterator matches a specific predicate.
|
static <E> Iterator<E> |
chainIterables(Iterable<? extends E>... iterables)
Returns an iterator that contains the elements of several other iterables.
|
static <E> Iterator<E> |
chainIterables(Iterable<? extends Iterable<? extends E>> iterables)
Returns an iterator that contains the elements of several other iterables.
|
static <E> Iterator<E> |
chainIterators(Iterable<? extends Iterator<? extends E>> iterators)
Returns an iterator that contains the elements of several other iterators.
|
static <E> Iterator<E> |
chainIterators(Iterator<? extends E>... iterators)
Returns an iterator that contains the elements of several other iterators.
|
static <E,R,A> R |
collect(Iterator<E> iterator,
Collector<? super E,A,R> collector)
Performs a reduction on the elements of an iterator.
|
static <E,R> R |
collect(Iterator<E> iterator,
Supplier<R> supplier,
BiConsumer<R,? super E> accumulator)
Performs a reduction on the elements of an iterator.
|
static long |
count(Iterator<?> iterator)
Returns the number of elements of an iterator.
|
static <E> Iterator<E> |
distinct(Iterator<E> iterator)
Returns an iterator that returns the distinct elements of another iterator (according to
Object.equals(Object) ). |
static <E> Iterator<E> |
dropWhile(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns an iterator that discards elements of another iterator until an element does not match a specific predicate.
|
static <E> Iterator<E> |
filter(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns an iterator that filters out elements of another iterator.
|
static <E> Optional<E> |
findFirst(Iterator<E> iterator)
Returns the first element of an iterator.
|
static <E,R> Iterator<R> |
flatMap(Iterator<E> iterator,
Function<? super E,? extends Iterator<? extends R>> mapper)
Returns an iterator that replaces the elements of another iterator with the elements of a mapped iterator produced by applying a function to
each element.
|
static <E> Iterator<E> |
iterate(E seed,
Predicate<? super E> hasNext,
UnaryOperator<E> next)
Returns an iterator for which the elements are produced by iterative application of a function.
|
static <E> Iterator<E> |
limit(Iterator<E> iterator,
long maxSize)
Returns an iterator that truncates another iterator.
|
static <E,R> Iterator<R> |
map(Iterator<E> iterator,
Function<? super E,? extends R> mapper)
Returns an iterator that applies a function to the elements of another iterator.
|
static <E> Optional<E> |
max(Iterator<E> iterator,
Comparator<? super E> comparator)
Returns the maximum element of an iterator according to a specific comparator.
|
static <E> Optional<E> |
min(Iterator<E> iterator,
Comparator<? super E> comparator)
Returns the minimum element of an iterator according to a specific comparator.
|
static <E> boolean |
noneMatch(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns whether or not no element of an iterator matches a specific predicate.
|
static <E> Iterator<E> |
peek(Iterator<E> iterator,
Consumer<? super E> action)
Returns an iterator that performs an additional action for each element of another iterator.
|
static <E> Optional<E> |
reduce(Iterator<E> iterator,
BinaryOperator<E> accumulator)
Performs a reduction on the elements of an iterator.
|
static <E> E |
reduce(Iterator<E> iterator,
E identity,
BinaryOperator<E> accumulator)
Performs a reduction on the elements of an iterator.
|
static <E,U> U |
reduce(Iterator<E> iterator,
U identity,
BiFunction<U,? super E,U> accumulator)
Performs a reduction on the elements of an iterator.
|
static <E> Iterator<E> |
singletonIterator(E element)
Returns an iterator that returns a single element.
|
static <E> Iterator<E> |
skip(Iterator<E> iterator,
long n)
Returns an iterator that discards a number of elements at the start of another iterator.
|
static <E> Iterator<E> |
takeWhile(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns an iterator that discards elements of another iterator once an element matches a specific predicate.
|
static <E> Stream<E> |
toStream(Iterator<E> iterator)
Returns a stream based on an iterator.
|
static <E> Stream<E> |
toStream(Iterator<E> iterator,
int characteristics)
Returns a stream based on an iterator.
|
static <E> Stream<E> |
toStream(Iterator<E> iterator,
long size)
Returns a stream based on an iterator.
|
static <E> Stream<E> |
toStream(Iterator<E> iterator,
long size,
int characteristics)
Returns a stream based on an iterator.
|
static <E> Iterator<E> |
unmodifiableIterator(Iterator<E> iterator)
Returns an unmodifiable view of an iterator.
|
public static <E> Iterator<E> singletonIterator(E element)
Collections.singleton(Object)
.Iterator.remove()
operation.E
- The element type.element
- The element to return.public static <E> Iterator<E> unmodifiableIterator(Iterator<E> iterator)
Iterator.remove()
will result in an UnsupportedOperationException
.E
- The element type.iterator
- The iterator to return an unmodifiable view of.NullPointerException
- If the given iterator is null
.public static <E> Iterator<E> filter(Iterator<E> iterator, Predicate<? super E> predicate)
Iterator.remove()
operation if the given iterator does.E
- The element type.iterator
- The iterator for which to filter out elements.predicate
- A predicate that determines whether or not elements should be included.NullPointerException
- If the given iterator or predicate is null
.Stream.filter(Predicate)
public static <E,R> Iterator<R> map(Iterator<E> iterator, Function<? super E,? extends R> mapper)
Iterator.remove()
operation if the given iterator does.E
- The element type of the input iterator.R
- The element type of the resulting iterator.iterator
- The iterator with the elements to apply the function to.mapper
- The function to apply.NullPointerException
- If the given iterator or function is null
.Stream.map(Function)
public static <E,R> Iterator<R> flatMap(Iterator<E> iterator, Function<? super E,? extends Iterator<? extends R>> mapper)
Iterator.remove()
operation.E
- The element type of the input iterator.R
- The element type of the resulting iterator.iterator
- The iterator with the elements to apply the function to.mapper
- The function to apply.NullPointerException
- If the given iterator or function is null
.Stream.flatMap(Function)
public static <E> Iterator<E> distinct(Iterator<E> iterator)
Object.equals(Object)
).Iterator.remove()
operation if the given iterator does.
If elements occur more than once in the original iterator, only the first occurrence will be returned by the returned iterator,
and therefore only the first occurrence can be removed.E
- The element type.iterator
- The element to return distinct elements of.NullPointerException
- If the given iterator is null
.Stream.distinct()
public static <E> Iterator<E> peek(Iterator<E> iterator, Consumer<? super E> action)
Iterator.remove()
operation if the given iterator does.E
- The element type.iterator
- The iterator with the element to perform an action for.action
- The action to perform.NullPointerException
- If the given iterator or action is null
.Stream.peek(Consumer)
public static <E> Iterator<E> limit(Iterator<E> iterator, long maxSize)
Iterator.remove()
operation if the given iterator does.
Discarded elements will not be returned by the returned iterator, and therefore cannot be removed.E
- The element type.iterator
- The iterator to truncate.maxSize
- The maximum number of elements in the returned iterator.NullPointerException
- If the given iterator is null
.IllegalArgumentException
- If the given maximum number of elements is negative.Stream.limit(long)
public static <E> Iterator<E> skip(Iterator<E> iterator, long n)
Iterator.remove()
operation if the given iterator does.
Discarded elements will not be returned by the returned iterator, and therefore cannot be removed.E
- The element type.iterator
- The iterator for which to discard the first elements.n
- The number of elements to discard.n
elements of the given iterator.NullPointerException
- If the given iterator is null
.IllegalArgumentException
- If the given number of elements is negative.Stream.skip(long)
public static <E> Iterator<E> takeWhile(Iterator<E> iterator, Predicate<? super E> predicate)
Iterator.remove()
operation if the given iterator does.
Discarded elements will not be returned by the returned iterator, and therefore cannot be removed.E
- The element type.iterator
- The iterator for which to discard elements.predicate
- The predicate that determines when elements are discarded.NullPointerException
- If the given iterator or predicate is null
.public static <E> Iterator<E> dropWhile(Iterator<E> iterator, Predicate<? super E> predicate)
Iterator.remove()
operation if the given iterator does.
Discarded elements will not be returned by the returned iterator, and therefore cannot be removed.E
- The element type.iterator
- The iterator for which to discard elements.predicate
- The predicate that determines until when elements are discarded.NullPointerException
- If the given iterator or predicate is null
.public static <E> E reduce(Iterator<E> iterator, E identity, BinaryOperator<E> accumulator)
E
- The element type.iterator
- The iterator with the elements to perform a reduction on.identity
- The identity value for the accumulating function.accumulator
- A function for combining two values.NullPointerException
- If the given iterator or accumulator function is null
.Stream.reduce(Object, BinaryOperator)
public static <E> Optional<E> reduce(Iterator<E> iterator, BinaryOperator<E> accumulator)
E
- The element type.iterator
- The iterator with the elements to perform a reduction on.accumulator
- A function for combining two values.Optional
describing the result of the reduction, or Optional.empty()
if the given iterator has no elements.NullPointerException
- If the given iterator or accumulator function or the result of the reduction is null
.Stream.reduce(BinaryOperator)
public static <E,U> U reduce(Iterator<E> iterator, U identity, BiFunction<U,? super E,U> accumulator)
E
- The element type of the input iterator.U
- The element type of the resulting iterator.iterator
- The iterator with the elements to perform a reduction on.identity
- The identity value for the accumulating function.accumulator
- A function for combining two values.NullPointerException
- If the given iterator or accumulator function is null
.Stream.reduce(Object, BiFunction, BinaryOperator)
public static <E,R> R collect(Iterator<E> iterator, Supplier<R> supplier, BiConsumer<R,? super E> accumulator)
E
- The element type of the input iterator.R
- The element type of the resulting iterator.iterator
- The iterator with the elements to perform a reduction on.supplier
- A supplier for mutable result containers.accumulator
- A function that folds elements into a result container.NullPointerException
- If the given iterator, supplier or accumulator function is null
.Stream.collect(Supplier, BiConsumer, BiConsumer)
public static <E,R,A> R collect(Iterator<E> iterator, Collector<? super E,A,R> collector)
E
- The element type of the input iterator.R
- The element type of the resulting iterator.A
- The intermediate accumulation type of the collector.iterator
- The iterator with the elements to perform a reduction on.collector
- The collector to use for the reduction.NullPointerException
- If the given iterator or collector is null
.Stream.collect(Collector)
public static <E> Optional<E> min(Iterator<E> iterator, Comparator<? super E> comparator)
E
- The element type.iterator
- The iterator to return the minimum element of.comparator
- The comparator to use for comparing elements.Optional
describing the minimum element, or Optional.empty()
if the given iterator has no elements.NullPointerException
- If the given iterator or comparator is null
.Stream.min(Comparator)
public static <E> Optional<E> max(Iterator<E> iterator, Comparator<? super E> comparator)
E
- The element type.iterator
- The iterator to return the maximum element of.comparator
- The comparator to use for comparing elements.Optional
describing the maximum element, or Optional.empty()
if the given iterator has no elements.NullPointerException
- If the given iterator or comparator is null
.Stream.max(Comparator)
public static long count(Iterator<?> iterator)
iterator
- The iterator to return the number of elements of.NullPointerException
- If the given iterator is null
.Stream.count()
public static <E> boolean anyMatch(Iterator<E> iterator, Predicate<? super E> predicate)
E
- The element type.iterator
- The iterator with the elements to match.predicate
- The predicate to apply to elements of the given iterator.true
if at least one element of the given iterator matches the given predicate, or false
otherwise.NullPointerException
- If the given iterator or predicate is null
.Stream.anyMatch(Predicate)
public static <E> boolean allMatch(Iterator<E> iterator, Predicate<? super E> predicate)
E
- The element type.iterator
- The iterator with the elements to match.predicate
- The predicate to apply to elements of the given iterator.true
if all elements of the given iterator match the given predicate, or false
otherwise.NullPointerException
- If the given iterator or predicate is null
.Stream.allMatch(Predicate)
public static <E> boolean noneMatch(Iterator<E> iterator, Predicate<? super E> predicate)
E
- The element type.iterator
- The iterator with the elements to match.predicate
- The predicate to apply to elements of the given iterator.true
if no element of the given iterator matches the given predicate, or false
otherwise.NullPointerException
- If the given iterator or predicate is null
.Stream.noneMatch(Predicate)
public static <E> Optional<E> findFirst(Iterator<E> iterator)
E
- The element type.iterator
- The iterator to return the first element of.Optional
describing the first element, or Optional.empty()
if the given iterator has no elements.NullPointerException
- If the given iterator is null
.Stream.findFirst()
public static <E> Stream<E> toStream(Iterator<E> iterator)
E
- The element type.iterator
- The iterator to return a stream for.NullPointerException
- If the given iterator is null
.Spliterators.spliteratorUnknownSize(Iterator, int)
,
StreamSupport.stream(Spliterator, boolean)
public static <E> Stream<E> toStream(Iterator<E> iterator, int characteristics)
E
- The element type.iterator
- The iterator to return a stream for.characteristics
- Characteristics of the iterator's elements.NullPointerException
- If the given iterator is null
.Spliterators.spliteratorUnknownSize(Iterator, int)
,
StreamSupport.stream(Spliterator, boolean)
public static <E> Stream<E> toStream(Iterator<E> iterator, long size)
E
- The element type.iterator
- The iterator to return a stream for.size
- The number of elements in the iterator.NullPointerException
- If the given iterator is null
.Spliterators.spliterator(Iterator, long, int)
,
StreamSupport.stream(Spliterator, boolean)
public static <E> Stream<E> toStream(Iterator<E> iterator, long size, int characteristics)
E
- The element type.iterator
- The iterator to return a stream for.size
- The number of elements in the iterator.characteristics
- Characteristics of the iterator's elements.NullPointerException
- If the given iterator is null
.Spliterators.spliterator(Iterator, long, int)
,
StreamSupport.stream(Spliterator, boolean)
@SafeVarargs public static <E> Iterator<E> chainIterators(Iterator<? extends E>... iterators)
E
- The element type.iterators
- The iterators with the elements for the returned iterator.NullPointerException
- If any of the given iterators is null
.public static <E> Iterator<E> chainIterators(Iterable<? extends Iterator<? extends E>> iterators)
E
- The element type.iterators
- The iterators with the elements for the returned iterator.NullPointerException
- If any of the given iterators is null
.@SafeVarargs public static <E> Iterator<E> chainIterables(Iterable<? extends E>... iterables)
E
- The element type.iterables
- The iterables with the elements for the returned iterator.NullPointerException
- If any of the given iterables is null
.public static <E> Iterator<E> chainIterables(Iterable<? extends Iterable<? extends E>> iterables)
E
- The element type.iterables
- The iterables with the elements for the returned iterator.NullPointerException
- If any of the given iterables is null
.public static <E> Iterator<E> iterate(E seed, Predicate<? super E> hasNext, UnaryOperator<E> next)
E
- The element type.seed
- The initial element.hasNext
- A predicate that determines when iteration ends.next
- A function that determines the next element based on the previous one.Copyright © 2022. All rights reserved.