public class IntStreamEx extends Object implements IntStream
IntStream implementation with additional functionality| Modifier and Type | Class and Description |
|---|---|
static interface |
IntStreamEx.IntEmitter
A helper interface to build a new stream by emitting elements and
creating new emitters in a chain.
|
IntStream.Builder| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(IntPredicate predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(IntPredicate predicate)
Returns whether any elements of this stream match the provided
predicate.
|
IntStreamEx |
append(int... values)
Returns a new
IntStreamEx which is a concatenation of this stream
and the stream containing supplied values
This is a quasi-intermediate
operation. |
IntStreamEx |
append(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements
of this stream followed by all the elements of the other stream.
|
InputStream |
asByteInputStream()
Returns an
InputStream lazily populated from the current
IntStreamEx. |
DoubleStreamEx |
asDoubleStream()
Returns a
DoubleStream consisting of the elements of this stream,
converted to double. |
LongStreamEx |
asLongStream()
Returns a
LongStream consisting of the elements of this stream,
converted to long. |
IntStreamEx |
atLeast(int value)
Returns a stream consisting of the elements of this stream that greater
than or equal to the specified value.
|
IntStreamEx |
atMost(int value)
Returns a stream consisting of the elements of this stream that less than
or equal to the specified value.
|
OptionalDouble |
average()
Returns an
OptionalDouble describing the arithmetic mean of elements of
this stream, or an empty optional if this stream is empty. |
StreamEx<Integer> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to an Integer. |
<U> U |
chain(Function<? super IntStreamEx,U> mapper)
Applies the supplied function to this stream and returns the result of
the function.
|
String |
charsToString()
Returns a
String consisting of chars from this stream. |
void |
close()
Closes this stream, causing all close handlers for this stream pipeline
to be called.
|
String |
codePointsToString()
Returns a
String consisting of code points from this stream. |
<A,R> R |
collect(IntCollector<A,R> collector)
Performs a mutable reduction operation on the elements of this stream
using an
IntCollector which encapsulates the supplier,
accumulator and merger functions making easier to reuse collection
strategies. |
<R> R |
collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BiConsumer<R,R> combiner)
Performs a mutable
reduction operation on the elements of this stream.
|
static IntStreamEx |
constant(int value,
long length)
Returns a sequential unordered
IntStreamEx of given length which
elements are equal to supplied value. |
long |
count()
Returns the count of elements in this stream.
|
IntStreamEx |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
IntStreamEx |
dropWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream starting
from the first element which does not match the given predicate.
|
DoubleStreamEx |
elements(double[] array)
Returns a
DoubleStreamEx consisting of the elements of given
array corresponding to the indices which appear in this stream. |
IntStreamEx |
elements(int[] array)
Returns an
IntStreamEx consisting of the elements of given array
corresponding to the indices which appear in this stream. |
<U> StreamEx<U> |
elements(List<U> list)
|
LongStreamEx |
elements(long[] array)
Returns a
LongStreamEx consisting of the elements of given array
corresponding to the indices which appear in this stream. |
<U> StreamEx<U> |
elements(U[] array)
Returns an object-valued
StreamEx consisting of the elements of
given array corresponding to the indices which appear in this stream. |
static IntStreamEx |
empty()
Returns an empty sequential
IntStreamEx. |
IntStreamEx |
filter(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
OptionalInt |
findAny()
Returns an
OptionalInt describing some element of the stream, or
an empty OptionalInt if the stream is empty. |
OptionalInt |
findAny(IntPredicate predicate)
Returns an
OptionalInt describing some element of the stream,
which matches given predicate, or an empty OptionalInt if there's
no matching element. |
OptionalInt |
findFirst()
Returns an
OptionalInt describing the first element of this
stream, or an empty OptionalInt if the stream is empty. |
OptionalInt |
findFirst(IntPredicate predicate)
Returns an
OptionalInt describing the first element of this
stream, which matches given predicate, or an empty OptionalInt if
there's no matching element. |
IntStreamEx |
flatMap(IntFunction<? extends IntStream> mapper)
Returns a stream consisting of the results of replacing each element of
this stream with the contents of a mapped stream produced by applying
the provided mapping function to each element.
|
DoubleStreamEx |
flatMapToDouble(IntFunction<? extends DoubleStream> mapper)
Returns a
DoubleStreamEx consisting of the results of replacing
each element of this stream with the contents of a mapped stream produced
by applying the provided mapping function to each element. |
LongStreamEx |
flatMapToLong(IntFunction<? extends LongStream> mapper)
Returns a
LongStreamEx consisting of the results of replacing
each element of this stream with the contents of a mapped stream produced
by applying the provided mapping function to each element. |
<R> StreamEx<R> |
flatMapToObj(IntFunction<? extends Stream<R>> mapper)
Returns a
StreamEx consisting of the results of replacing each
element of this stream with the contents of a mapped stream produced by
applying the provided mapping function to each element. |
OptionalInt |
foldLeft(IntBinaryOperator accumulator)
Folds the elements of this stream using the provided accumulation
function, going left to right.
|
int |
foldLeft(int seed,
IntBinaryOperator accumulator)
Folds the elements of this stream using the provided seed object and
accumulation function, going left to right.
|
void |
forEach(IntConsumer action)
Performs an action for each element of this stream.
|
void |
forEachOrdered(IntConsumer action)
Performs an action for each element of this stream, guaranteeing that
each element is processed in encounter order for streams that have a
defined encounter order.
|
static IntStreamEx |
generate(IntSupplier s)
Returns an infinite sequential unordered stream where each element is
generated by the provided
IntSupplier. |
IntStreamEx |
greater(int value)
Returns a stream consisting of the elements of this stream that strictly
greater than the specified value.
|
boolean |
has(int value)
Returns true if this stream contains the specified value.
|
OptionalLong |
indexOf(int value)
Returns an
OptionalLong describing the zero-based index of the
first element of this stream, which equals to the given value, or an
empty OptionalLong if there's no matching element. |
OptionalLong |
indexOf(IntPredicate predicate)
Returns an
OptionalLong describing the zero-based index of the
first element of this stream, which matches given predicate, or an empty
OptionalLong if there's no matching element. |
static IntStreamEx |
ints()
Returns a sequential ordered
IntStreamEx from 0 (inclusive) to
Integer.MAX_VALUE (exclusive) by an incremental step of 1
. |
boolean |
isParallel()
Returns whether this stream, if a terminal operation were to be executed,
would execute in parallel.
|
static IntStreamEx |
iterate(int seed,
IntPredicate predicate,
IntUnaryOperator f)
Returns a sequential ordered
IntStreamEx produced by iterative
application of a function to an initial element, conditioned on
satisfying the supplied predicate. |
static IntStreamEx |
iterate(int seed,
IntUnaryOperator f)
Returns an infinite sequential ordered
IntStreamEx produced by
iterative application of a function f to an initial element
seed, producing a stream consisting of seed,
f(seed), f(f(seed)), etc. |
PrimitiveIterator.OfInt |
iterator()
Returns an iterator for the elements of this stream.
|
String |
joining(CharSequence delimiter)
Returns a
String which is the concatenation of the results of
calling String.valueOf(int) on each element of this stream,
separated by the specified delimiter, in encounter order. |
String |
joining(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns a
String which is the concatenation of the results of
calling String.valueOf(int) on each element of this stream,
separated by the specified delimiter, with the specified prefix and
suffix in encounter order. |
IntStreamEx |
less(int value)
Returns a stream consisting of the elements of this stream that strictly
less than the specified value.
|
IntStreamEx |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
IntStreamEx |
map(IntUnaryOperator mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
IntStreamEx |
mapFirst(IntUnaryOperator mapper)
Returns a stream where the first element is the replaced with the result
of applying the given function while the other elements are left intact.
|
IntStreamEx |
mapLast(IntUnaryOperator mapper)
Returns a stream where the last element is the replaced with the result
of applying the given function while the other elements are left intact.
|
DoubleStreamEx |
mapToDouble(IntToDoubleFunction mapper)
Returns a
DoubleStream consisting of the results of applying the
given function to the elements of this stream. |
<K,V> EntryStream<K,V> |
mapToEntry(IntFunction<? extends K> keyMapper,
IntFunction<? extends V> valueMapper)
Returns an
EntryStream consisting of the Map.Entry objects
which keys and values are results of applying the given functions to the
elements of this stream. |
LongStreamEx |
mapToLong(IntToLongFunction mapper)
Returns a
LongStream consisting of the results of applying the
given function to the elements of this stream. |
<U> StreamEx<U> |
mapToObj(IntFunction<? extends U> mapper)
Returns an object-valued
Stream consisting of the results of
applying the given function to the elements of this stream. |
OptionalInt |
max()
Returns an
OptionalInt describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalInt |
max(Comparator<Integer> comparator)
Returns the maximum element of this stream according to the provided
Comparator. |
<V extends Comparable<? super V>> |
maxBy(IntFunction<V> keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalInt |
maxByDouble(IntToDoubleFunction keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalInt |
maxByInt(IntUnaryOperator keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalInt |
maxByLong(IntToLongFunction keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalInt |
min()
Returns an
OptionalInt describing the minimum element of this
stream, or an empty optional if this stream is empty. |
OptionalInt |
min(Comparator<Integer> comparator)
Returns the minimum element of this stream according to the provided
Comparator. |
<V extends Comparable<? super V>> |
minBy(IntFunction<V> keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalInt |
minByDouble(IntToDoubleFunction keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalInt |
minByInt(IntUnaryOperator keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalInt |
minByLong(IntToLongFunction keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
boolean |
noneMatch(IntPredicate predicate)
Returns whether no elements of this stream match the provided predicate.
|
static IntStreamEx |
of(BitSet bitSet)
Returns an
IntStreamEx of indices for which the specified
BitSet contains a bit in the set state. |
static IntStreamEx |
of(byte... elements)
Returns a sequential ordered
IntStreamEx whose elements are the
specified values casted to int. |
static IntStreamEx |
of(byte[] array,
int startInclusive,
int endExclusive)
Returns a sequential
IntStreamEx with the specified range of the
specified array as its source. |
static IntStreamEx |
of(char... elements)
Returns a sequential ordered
IntStreamEx whose elements are the
specified values casted to int. |
static IntStreamEx |
of(char[] array,
int startInclusive,
int endExclusive)
Returns a sequential
IntStreamEx with the specified range of the
specified array as its source. |
static IntStreamEx |
of(Collection<Integer> collection)
Returns a sequential ordered
IntStreamEx whose elements are the
unboxed elements of supplied collection. |
static IntStreamEx |
of(InputStream is)
Returns a sequential ordered
IntStreamEx backed by the content of
given InputStream. |
static IntStreamEx |
of(int... elements)
Returns a sequential ordered
IntStreamEx whose elements are the
specified values. |
static IntStreamEx |
of(int element)
Returns a sequential
IntStreamEx containing a single element. |
static IntStreamEx |
of(int[] array,
int startInclusive,
int endExclusive)
Returns a sequential
IntStreamEx with the specified range of the
specified array as its source. |
static IntStreamEx |
of(IntBuffer buf)
Returns a sequential ordered
IntStreamEx whose elements are the
values in the supplied IntBuffer. |
static IntStreamEx |
of(Integer[] array)
Returns a sequential ordered
IntStreamEx whose elements are the
unboxed elements of supplied array. |
static IntStreamEx |
of(IntStream stream)
Returns an
IntStreamEx object which wraps given IntStream
. |
static IntStreamEx |
of(OptionalInt optional)
Returns a sequential
IntStreamEx containing an
OptionalInt value, if present, otherwise returns an empty
IntStreamEx. |
static IntStreamEx |
of(PrimitiveIterator.OfInt iterator)
Returns a sequential, ordered
IntStreamEx created from given
PrimitiveIterator.OfInt. |
static IntStreamEx |
of(Random random)
Returns an effectively unlimited stream of pseudorandom
int
values produced by given Random object. |
static IntStreamEx |
of(Random random,
int randomNumberOrigin,
int randomNumberBound)
Returns an effectively unlimited stream of pseudorandom
int
values, each conforming to the given origin (inclusive) and bound
(exclusive). |
static IntStreamEx |
of(Random random,
long streamSize)
Returns a stream producing the given
streamSize number of
pseudorandom int values. |
static IntStreamEx |
of(Random random,
long streamSize,
int randomNumberOrigin,
int randomNumberBound)
Returns a stream producing the given
streamSize number of
pseudorandom int values, each conforming to the given origin
(inclusive) and bound (exclusive). |
static IntStreamEx |
of(short... elements)
Returns a sequential ordered
IntStreamEx whose elements are the
specified values casted to int. |
static IntStreamEx |
of(short[] array,
int startInclusive,
int endExclusive)
Returns a sequential
IntStreamEx with the specified range of the
specified array as its source. |
static IntStreamEx |
of(Spliterator.OfInt spliterator)
Returns a sequential
IntStreamEx created from given
Spliterator.OfInt. |
static IntStreamEx |
ofChars(CharSequence seq)
|
static IntStreamEx |
ofCodePoints(CharSequence seq)
Returns an
IntStreamEx of code point values from the supplied
CharSequence. |
static IntStreamEx |
ofIndices(double[] array)
Returns a sequential ordered
IntStreamEx containing all the
indices of supplied array. |
static IntStreamEx |
ofIndices(double[] array,
DoublePredicate predicate)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied array elements which match given predicate. |
static IntStreamEx |
ofIndices(int[] array)
Returns a sequential ordered
IntStreamEx containing all the
indices of supplied array. |
static IntStreamEx |
ofIndices(int[] array,
IntPredicate predicate)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied array elements which match given predicate. |
static <T> IntStreamEx |
ofIndices(List<T> list)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied list. |
static <T> IntStreamEx |
ofIndices(List<T> list,
Predicate<T> predicate)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied list elements which match given predicate. |
static IntStreamEx |
ofIndices(long[] array)
Returns a sequential ordered
IntStreamEx containing all the
indices of supplied array. |
static IntStreamEx |
ofIndices(long[] array,
LongPredicate predicate)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied array elements which match given predicate. |
static <T> IntStreamEx |
ofIndices(T[] array)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied array. |
static <T> IntStreamEx |
ofIndices(T[] array,
Predicate<T> predicate)
Returns a sequential ordered
IntStreamEx containing all the
indices of the supplied array elements which match given predicate. |
IntStreamEx |
onClose(Runnable closeHandler)
Returns an equivalent stream with an additional close handler.
|
IntStreamEx |
pairMap(IntBinaryOperator mapper)
Returns a stream consisting of the results of applying the given function
to the every adjacent pair of elements of this stream.
|
IntStreamEx |
parallel()
Returns an equivalent stream that is parallel.
|
IntStreamEx |
parallel(ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the supplied
ForkJoinPool. |
IntStreamEx |
peek(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on each element as elements are consumed
from the resulting stream.
|
IntStreamEx |
peekFirst(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on the first stream element when it's
consumed from the resulting stream.
|
IntStreamEx |
peekLast(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on the last stream element when it's
consumed from the resulting stream.
|
IntStreamEx |
prefix(IntBinaryOperator op)
Returns a stream containing cumulative results of applying the
accumulation function going left to right.
|
IntStreamEx |
prepend(int... values)
Returns a new
IntStreamEx which is a concatenation of the stream
containing supplied values and this stream
This is a quasi-intermediate
operation. |
IntStreamEx |
prepend(IntStream other)
Creates a lazily concatenated stream whose elements are all the elements
of the other stream followed by all the elements of this stream.
|
static IntStreamEx |
produce(Predicate<IntConsumer> producer)
Return an ordered stream produced by consecutive calls of the supplied
producer until it returns false.
|
static IntStreamEx |
range(int endExclusive)
Returns a sequential ordered
IntStreamEx from 0 (inclusive) to
endExclusive (exclusive) by an incremental step of 1. |
static IntStreamEx |
range(int startInclusive,
int endExclusive)
Returns a sequential ordered
IntStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
an incremental step of 1. |
static IntStreamEx |
range(int startInclusive,
int endExclusive,
int step)
Returns a sequential ordered
IntStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
the specified incremental step. |
static IntStreamEx |
rangeClosed(int startInclusive,
int endInclusive)
Returns a sequential ordered
IntStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
an incremental step of 1. |
static IntStreamEx |
rangeClosed(int startInclusive,
int endInclusive,
int step)
Returns a sequential ordered
IntStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
the specified incremental step. |
OptionalInt |
reduce(IntBinaryOperator op)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
OptionalInt describing the reduced value,
if any. |
int |
reduce(int identity,
IntBinaryOperator op)
Performs a reduction on the
elements of this stream, using the provided identity value and an
associative
accumulation function, and returns the reduced value.
|
IntStreamEx |
remove(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that don't
match the given predicate.
|
IntStreamEx |
reverseSorted()
Returns a stream consisting of the elements of this stream in reverse
sorted order.
|
int[] |
scanLeft(IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the
accumulation function going left to right.
|
int[] |
scanLeft(int seed,
IntBinaryOperator accumulator)
Produces an array containing cumulative results of applying the
accumulation function going left to right using given seed value.
|
IntStreamEx |
sequential()
Returns an equivalent stream that is sequential.
|
IntStreamEx |
skip(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
IntStreamEx |
skipOrdered(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
IntStreamEx |
sorted()
Returns a stream consisting of the elements of this stream in sorted
order.
|
IntStreamEx |
sorted(Comparator<Integer> comparator)
Returns a stream consisting of the elements of this stream sorted
according to the given comparator.
|
<V extends Comparable<? super V>> |
sortedBy(IntFunction<V> keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the natural order of the keys extracted by provided
function.
|
IntStreamEx |
sortedByDouble(IntToDoubleFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the double values extracted by provided function.
|
IntStreamEx |
sortedByInt(IntUnaryOperator keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the int values extracted by provided function.
|
IntStreamEx |
sortedByLong(IntToLongFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the long values extracted by provided function.
|
SPLTR |
spliterator()
Returns a spliterator for the elements of this stream.
|
int |
sum()
Returns the sum of elements in this stream.
|
IntSummaryStatistics |
summaryStatistics()
Returns an
IntSummaryStatistics describing various
summary data about the elements of this stream. |
IntStreamEx |
takeWhile(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the
first element which does not match the given predicate is found.
|
IntStreamEx |
takeWhileInclusive(IntPredicate predicate)
Returns a stream consisting of all elements from this stream until the
first element which does not match the given predicate is found
(including the first mismatching element).
|
int[] |
toArray()
Returns an array containing the elements of this stream.
|
BitSet |
toBitSet()
Returns a
BitSet containing the elements of this stream. |
byte[] |
toByteArray()
Returns a
byte[] array containing the elements of this stream
which are converted to bytes using (byte) cast operation. |
char[] |
toCharArray()
Returns a
char[] array containing the elements of this stream
which are converted to chars using (char) cast operation. |
short[] |
toShortArray()
Returns a
short[] array containing the elements of this stream
which are converted to shorts using (short) cast operation. |
IntStreamEx |
unordered()
Returns an equivalent stream that is
unordered.
|
IntStreamEx |
without(int... values)
Returns a stream consisting of the elements of this stream that don't
equal to any of the supplied values.
|
IntStreamEx |
without(int value)
Returns a stream consisting of the elements of this stream that don't
equal to the given value.
|
static IntStreamEx |
zip(int[] first,
int[] second,
IntBinaryOperator mapper)
Returns a sequential
IntStreamEx containing the results of
applying the given function to the corresponding pairs of values in given
two arrays. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, concat, spliteratorclose, isParallelpublic IntStreamEx unordered()
java.util.stream.BaseStreamThis is an intermediate operation.
unordered in interface BaseStream<Integer,IntStream>public IntStreamEx onClose(Runnable closeHandler)
java.util.stream.BaseStreamBaseStream.close() method
is called on the stream, and are executed in the order they were
added. All close handlers are run, even if earlier close handlers throw
exceptions. If any close handler throws an exception, the first
exception thrown will be relayed to the caller of close(), with
any remaining exceptions added to that exception as suppressed exceptions
(unless one of the remaining exceptions is the same exception as the
first exception, since an exception cannot suppress itself.) May
return itself.
This is an intermediate operation.
onClose in interface BaseStream<Integer,IntStream>closeHandler - A task to execute when the stream is closedpublic IntStreamEx filter(IntPredicate predicate)
java.util.stream.IntStreamThis is an intermediate operation.
filter in interface IntStreampredicate - a non-interfering,
stateless
predicate to apply to each element to determine if it
should be includedpublic IntStreamEx remove(IntPredicate predicate)
This is an intermediate operation.
predicate - a non-interfering, stateless predicate to apply to each
element to determine if it should be excludedpublic boolean has(int value)
This is a short-circuiting terminal operation.
value - the value too look for in the streamIntStream.anyMatch(IntPredicate)public IntStreamEx without(int value)
This is an intermediate operation.
value - the value to remove from the stream.without(int...),
remove(IntPredicate)public IntStreamEx without(int... values)
This is an intermediate operation. May return itself if no values were supplied.
Current implementation scans the supplied values linearly for every stream element.
If the values array is changed between calling this method and
finishing the stream traversal, then the result of the stream traversal
is undefined: changes may or may not be taken into account.
values - the values to remove from the stream.without(int),
remove(IntPredicate)public IntStreamEx greater(int value)
This is an intermediate operation.
value - a value to compare topublic IntStreamEx atLeast(int value)
This is an intermediate operation.
value - a value to compare topublic IntStreamEx less(int value)
This is an intermediate operation.
value - a value to compare topublic IntStreamEx atMost(int value)
This is an intermediate operation.
value - a value to compare topublic IntStreamEx map(IntUnaryOperator mapper)
java.util.stream.IntStreamThis is an intermediate operation.
map in interface IntStreammapper - a non-interfering,
stateless
function to apply to each elementpublic <U> StreamEx<U> mapToObj(IntFunction<? extends U> mapper)
java.util.stream.IntStreamStream consisting of the results of
applying the given function to the elements of this stream.
This is an intermediate operation.
mapToObj in interface IntStreamU - the element type of the new streammapper - a non-interfering,
stateless
function to apply to each elementpublic LongStreamEx mapToLong(IntToLongFunction mapper)
java.util.stream.IntStreamLongStream consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToLong in interface IntStreammapper - a non-interfering,
stateless
function to apply to each elementpublic DoubleStreamEx mapToDouble(IntToDoubleFunction mapper)
java.util.stream.IntStreamDoubleStream consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToDouble in interface IntStreammapper - a non-interfering,
stateless
function to apply to each elementpublic <K,V> EntryStream<K,V> mapToEntry(IntFunction<? extends K> keyMapper, IntFunction<? extends V> valueMapper)
EntryStream consisting of the Map.Entry objects
which keys and values are results of applying the given functions to the
elements of this stream.
This is an intermediate operation.
K - The Entry key typeV - The Entry value typekeyMapper - a non-interfering, stateless function to apply to each
elementvalueMapper - a non-interfering, stateless function to apply to each
elementpublic IntStreamEx flatMap(IntFunction<? extends IntStream> mapper)
java.util.stream.IntStreamclosed after its contents
have been placed into this stream. (If a mapped stream is null
an empty stream is used, instead.)
This is an intermediate operation.
flatMap in interface IntStreammapper - a non-interfering,
stateless
function to apply to each element which produces an
IntStream of new valuesStream.flatMap(Function)public LongStreamEx flatMapToLong(IntFunction<? extends LongStream> mapper)
LongStreamEx consisting of the results of replacing
each element of this stream with the contents of a mapped stream produced
by applying the provided mapping function to each element. Each mapped
stream is closed after its contents have been placed into this stream.
(If a mapped stream is null an empty stream is used, instead.)
This is an intermediate operation.
mapper - a non-interfering, stateless function to apply to each
element which produces a LongStream of new valuespublic DoubleStreamEx flatMapToDouble(IntFunction<? extends DoubleStream> mapper)
DoubleStreamEx consisting of the results of replacing
each element of this stream with the contents of a mapped stream produced
by applying the provided mapping function to each element. Each mapped
stream is closed after its contents have been placed into this stream.
(If a mapped stream is null an empty stream is used, instead.)
This is an intermediate operation.
mapper - a non-interfering, stateless function to apply to each
element which produces a DoubleStream of new valuespublic <R> StreamEx<R> flatMapToObj(IntFunction<? extends Stream<R>> mapper)
StreamEx consisting of the results of replacing each
element of this stream with the contents of a mapped stream produced by
applying the provided mapping function to each element. Each mapped
stream is closed after its contents have been placed into this stream.
(If a mapped stream is null an empty stream is used, instead.)
This is an intermediate operation.
R - The element type of the new streammapper - a non-interfering, stateless function to apply to each
element which produces a Stream of new valuespublic IntStreamEx distinct()
java.util.stream.IntStreamThis is a stateful intermediate operation.
public IntStreamEx sorted()
java.util.stream.IntStreamThis is a stateful intermediate operation.
public IntStreamEx sorted(Comparator<Integer> comparator)
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
comparator - a
non-interfering
, stateless
Comparator to be used to compare stream elementspublic IntStreamEx reverseSorted()
This is a stateful intermediate operation.
public <V extends Comparable<? super V>> IntStreamEx sortedBy(IntFunction<V> keyExtractor)
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
V - the type of the Comparable sort keykeyExtractor - a
non-interfering
, stateless
function to be used to extract sorting keyspublic IntStreamEx sortedByInt(IntUnaryOperator keyExtractor)
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
keyExtractor - a
non-interfering
, stateless
function to be used to extract sorting keyspublic IntStreamEx sortedByLong(IntToLongFunction keyExtractor)
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
keyExtractor - a
non-interfering
, stateless
function to be used to extract sorting keyspublic IntStreamEx sortedByDouble(IntToDoubleFunction keyExtractor)
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
keyExtractor - a
non-interfering
, stateless
function to be used to extract sorting keyspublic IntStreamEx peek(IntConsumer action)
java.util.stream.IntStreamThis is an intermediate operation.
For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
peek in interface IntStreamaction - a
non-interfering action to perform on the elements as
they are consumed from the streampublic IntStreamEx peekFirst(IntConsumer action)
This is an intermediate operation.
The action is called at most once. For parallel stream pipelines, it's not guaranteed in which thread it will be executed, so if it modifies shared state, it is responsible for providing the required synchronization.
Note that the action might not be called at all if the first element is not consumed from the input (for example, if there's short-circuiting operation downstream which stopped the stream before the first element).
This method exists mainly to support debugging.
action - a
non-interfering
action to perform on the first stream element as it is
consumed from the streampublic IntStreamEx peekLast(IntConsumer action)
This is an intermediate operation.
The action is called at most once. For parallel stream pipelines, it's not guaranteed in which thread it will be executed, so if it modifies shared state, it is responsible for providing the required synchronization.
Note that the action might not be called at all if the last element is not consumed from the input (for example, if there's short-circuiting operation downstream).
This method exists mainly to support debugging.
action - a
non-interfering
action to perform on the first stream element as it is
consumed from the streampublic IntStreamEx limit(long maxSize)
java.util.stream.IntStreammaxSize in length.
public IntStreamEx skip(long n)
java.util.stream.IntStreamn elements of the stream.
If this stream contains fewer than n elements then an
empty stream will be returned.
This is a stateful intermediate operation.
public IntStreamEx skipOrdered(long n)
n elements of the stream. If this
stream contains fewer than n elements then an empty stream will
be returned.
This is a stateful quasi-intermediate operation. Unlike
skip(long) it skips the first elements even if the stream is
unordered. The main purpose of this method is to workaround the problem
of skipping the first elements from non-sized source with further
parallel processing and unordered terminal operation (such as
forEach(IntConsumer)). This problem was fixed in OracleJDK 8u60.
Also it behaves much better with infinite streams processed in parallel.
For example,
IntStreamEx.iterate(0, i->i+1).skip(1).limit(100).parallel().toArray()
will likely to fail with OutOfMemoryError, but will work nicely
if skip is replaced with skipOrdered.
For sequential streams this method behaves exactly like
skip(long).
n - the number of leading elements to skipIllegalArgumentException - if n is negativeskip(long)public void forEach(IntConsumer action)
java.util.stream.IntStreamThis is a terminal operation.
For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.
forEach in interface IntStreamaction - a
non-interfering action to perform on the elementspublic void forEachOrdered(IntConsumer action)
java.util.stream.IntStreamThis is a terminal operation.
forEachOrdered in interface IntStreamaction - a
non-interfering action to perform on the elementsIntStream.forEach(IntConsumer)public int[] toArray()
java.util.stream.IntStreamThis is a terminal operation.
public byte[] toByteArray()
byte[] array containing the elements of this stream
which are converted to bytes using (byte) cast operation.
This is a terminal operation.
public char[] toCharArray()
char[] array containing the elements of this stream
which are converted to chars using (char) cast operation.
This is a terminal operation.
public short[] toShortArray()
short[] array containing the elements of this stream
which are converted to shorts using (short) cast operation.
This is a terminal operation.
public BitSet toBitSet()
BitSet containing the elements of this stream.
This is a terminal operation.
BitSet which set bits correspond to the elements of
this stream.public InputStream asByteInputStream()
InputStream lazily populated from the current
IntStreamEx.
Note that only the least-significant byte of every number encountered in
this stream is preserved in the resulting InputStream, other
bytes are silently lost. Thus it's a caller responsibility to check
whether this may cause problems.
This is a terminal operation.
When the resulting InputStream is closed, this
IntStreamEx is closed as well.
InputStream.of(InputStream)public int reduce(int identity,
IntBinaryOperator op)
java.util.stream.IntStream
int result = identity;
for (int element : this stream)
result = accumulator.applyAsInt(result, element)
return result;
but is not constrained to execute sequentially.
The identity value must be an identity for the accumulator
function. This means that for all x,
accumulator.apply(identity, x) is equal to x.
The accumulator function must be an
associative function.
This is a terminal operation.
reduce in interface IntStreamidentity - the identity value for the accumulating functionop - an associative,
non-interfering,
stateless
function for combining two valuesIntStream.sum(),
IntStream.min(),
IntStream.max(),
IntStream.average()public OptionalInt reduce(IntBinaryOperator op)
java.util.stream.IntStreamOptionalInt describing the reduced value,
if any. This is equivalent to:
boolean foundAny = false;
int result = null;
for (int element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.applyAsInt(result, element);
}
return foundAny ? OptionalInt.of(result) : OptionalInt.empty();
but is not constrained to execute sequentially.
The accumulator function must be an
associative function.
This is a terminal operation.
reduce in interface IntStreamop - an associative,
non-interfering,
stateless
function for combining two valuesIntStream.reduce(int, IntBinaryOperator)public OptionalInt foldLeft(IntBinaryOperator accumulator)
boolean foundAny = false;
int result = 0;
for (int element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.apply(result, element);
}
return foundAny ? OptionalInt.of(result) : OptionalInt.empty();
This is a terminal operation.
This method cannot take all the advantages of parallel streams as it must
process elements strictly left to right. If your accumulator function is
associative, consider using reduce(IntBinaryOperator) method.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
accumulator - a
non-interfering
, stateless
function for incorporating an additional element into a resultfoldLeft(int, IntBinaryOperator),
reduce(IntBinaryOperator)public int foldLeft(int seed,
IntBinaryOperator accumulator)
int result = seed;
for (int element : this stream)
result = accumulator.apply(result, element)
return result;
This is a terminal operation.
This method cannot take all the advantages of parallel streams as it must
process elements strictly left to right. If your accumulator function is
associative, consider using reduce(int, IntBinaryOperator)
method.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
seed - the starting valueaccumulator - a
non-interfering
, stateless
function for incorporating an additional element into a resultreduce(int, IntBinaryOperator),
foldLeft(IntBinaryOperator)public int[] scanLeft(IntBinaryOperator accumulator)
This is a terminal operation.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right.
accumulator - a
non-interfering
, stateless
function for incorporating an additional element into a resultfoldLeft(IntBinaryOperator)public int[] scanLeft(int seed,
IntBinaryOperator accumulator)
This is a terminal operation.
For parallel stream it's not guaranteed that accumulator will always be executed in the same thread.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right.
seed - the starting valueaccumulator - a
non-interfering
, stateless
function for incorporating an additional element into a resultfoldLeft(int, IntBinaryOperator)public <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)
ArrayList, and elements are incorporated by updating
the state of the result rather than by replacing the result. This
produces a result equivalent to:
R result = supplier.get();
for (int element : this stream)
accumulator.accept(result, element);
return result;
Like IntStream.reduce(int, IntBinaryOperator), collect operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
collect in interface IntStreamR - type of the resultsupplier - a function that creates a new result container. For a
parallel execution, this function may be called
multiple times and must return a fresh value each time.accumulator - an associative,
non-interfering,
stateless
function for incorporating an additional element into a resultcombiner - an associative,
non-interfering,
stateless
function for combining two values, which must be
compatible with the accumulator functioncollect(IntCollector)public <A,R> R collect(IntCollector<A,R> collector)
IntCollector which encapsulates the supplier,
accumulator and merger functions making easier to reuse collection
strategies.
Like reduce(int, IntBinaryOperator), collect operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
A - the intermediate accumulation type of the IntCollectorR - type of the resultcollector - the IntCollector describing the reductioncollect(Supplier, ObjIntConsumer, BiConsumer)public int sum()
java.util.stream.IntStream
return reduce(0, Integer::sum);
This is a terminal operation.
public OptionalInt min()
java.util.stream.IntStreamOptionalInt describing the minimum element of this
stream, or an empty optional if this stream is empty. This is a special
case of a reduction
and is equivalent to:
return reduce(Integer::min);
This is a terminal operation.
public OptionalInt min(Comparator<Integer> comparator)
Comparator.
This is a terminal operation.
comparator - a non-interfering, stateless Comparator to
compare elements of this streamOptionalInt describing the minimum element of this
stream, or an empty OptionalInt if the stream is emptypublic <V extends Comparable<? super V>> OptionalInt minBy(IntFunction<V> keyExtractor)
This is a terminal operation.
V - the type of the Comparable sort keykeyExtractor - a non-interfering, stateless functionOptionalInt describing some element of this stream for
which the lowest value was returned by key extractor, or an empty
OptionalInt if the stream is emptypublic OptionalInt minByInt(IntUnaryOperator keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing the first element of this
stream for which the lowest value was returned by key extractor,
or an empty OptionalInt if the stream is emptypublic OptionalInt minByLong(IntToLongFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing some element of this stream for
which the lowest value was returned by key extractor, or an empty
OptionalInt if the stream is emptypublic OptionalInt minByDouble(IntToDoubleFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing some element of this stream for
which the lowest value was returned by key extractor, or an empty
OptionalInt if the stream is emptypublic OptionalInt max()
java.util.stream.IntStreamOptionalInt describing the maximum element of this
stream, or an empty optional if this stream is empty. This is a special
case of a reduction
and is equivalent to:
return reduce(Integer::max);
This is a terminal operation.
public OptionalInt max(Comparator<Integer> comparator)
Comparator.
This is a terminal operation.
comparator - a non-interfering, stateless Comparator to
compare elements of this streamOptionalInt describing the maximum element of this
stream, or an empty OptionalInt if the stream is emptypublic <V extends Comparable<? super V>> OptionalInt maxBy(IntFunction<V> keyExtractor)
This is a terminal operation.
V - the type of the Comparable sort keykeyExtractor - a non-interfering, stateless functionOptionalInt describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalInt if the stream is emptypublic OptionalInt maxByInt(IntUnaryOperator keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalInt if the stream is emptypublic OptionalInt maxByLong(IntToLongFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalInt if the stream is emptypublic OptionalInt maxByDouble(IntToDoubleFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalInt describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalInt if the stream is emptypublic long count()
java.util.stream.IntStream
return mapToLong(e -> 1L).sum();
This is a terminal operation.
public OptionalDouble average()
java.util.stream.IntStreamOptionalDouble describing the arithmetic mean of elements of
this stream, or an empty optional if this stream is empty. This is a
special case of a
reduction.
This is a terminal operation.
public IntSummaryStatistics summaryStatistics()
java.util.stream.IntStreamIntSummaryStatistics describing various
summary data about the elements of this stream. This is a special
case of a reduction.
This is a terminal operation.
summaryStatistics in interface IntStreamIntSummaryStatistics describing various summary data
about the elements of this streampublic boolean anyMatch(IntPredicate predicate)
java.util.stream.IntStreamfalse is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
anyMatch in interface IntStreampredicate - a non-interfering,
stateless
predicate to apply to elements of this streamtrue if any elements of the stream match the provided
predicate, otherwise falsepublic boolean allMatch(IntPredicate predicate)
java.util.stream.IntStreamtrue is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
allMatch in interface IntStreampredicate - a non-interfering,
stateless
predicate to apply to elements of this streamtrue if either all elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic boolean noneMatch(IntPredicate predicate)
java.util.stream.IntStreamtrue is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
noneMatch in interface IntStreampredicate - a non-interfering,
stateless
predicate to apply to elements of this streamtrue if either no elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic OptionalInt findFirst()
java.util.stream.IntStreamOptionalInt describing the first element of this
stream, or an empty OptionalInt if the stream is empty. If the
stream has no encounter order, then any element may be returned.
This is a short-circuiting terminal operation.
public OptionalInt findFirst(IntPredicate predicate)
OptionalInt describing the first element of this
stream, which matches given predicate, or an empty OptionalInt if
there's no matching element.
This is a short-circuiting terminal operation.
predicate - a
non-interfering
, stateless
predicate which returned value should matchOptionalInt describing the first matching element of
this stream, or an empty OptionalInt if there's no
matching elementfindFirst()public OptionalInt findAny()
java.util.stream.IntStreamOptionalInt describing some element of the stream, or
an empty OptionalInt if the stream is empty.
This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is
free to select any element in the stream. This is to allow for maximal
performance in parallel operations; the cost is that multiple invocations
on the same source may not return the same result. (If a stable result
is desired, use IntStream.findFirst() instead.)
findAny in interface IntStreamOptionalInt describing some element of this stream, or
an empty OptionalInt if the stream is emptyIntStream.findFirst()public OptionalInt findAny(IntPredicate predicate)
OptionalInt describing some element of the stream,
which matches given predicate, or an empty OptionalInt if there's
no matching element.
This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is free
to select any element in the stream. This is to allow for maximal
performance in parallel operations; the cost is that multiple invocations
on the same source may not return the same result. (If a stable result is
desired, use findFirst(IntPredicate) instead.)
predicate - a
non-interfering
, stateless
predicate which returned value should matchOptionalInt describing some matching element of this
stream, or an empty OptionalInt if there's no matching
elementfindAny(),
findFirst(IntPredicate)public OptionalLong indexOf(int value)
OptionalLong describing the zero-based index of the
first element of this stream, which equals to the given value, or an
empty OptionalLong if there's no matching element.
This is a short-circuiting terminal operation.
value - a value to look forOptionalLong describing the index of the first
matching element of this stream, or an empty OptionalLong
if there's no matching element.indexOf(IntPredicate)public OptionalLong indexOf(IntPredicate predicate)
OptionalLong describing the zero-based index of the
first element of this stream, which matches given predicate, or an empty
OptionalLong if there's no matching element.
This is a short-circuiting terminal operation.
predicate - a
non-interfering
, stateless
predicate which returned value should matchOptionalLong describing the index of the first
matching element of this stream, or an empty OptionalLong
if there's no matching element.findFirst(IntPredicate)public LongStreamEx asLongStream()
java.util.stream.IntStreamLongStream consisting of the elements of this stream,
converted to long.
This is an intermediate operation.
asLongStream in interface IntStreamLongStream consisting of the elements of this stream,
converted to longpublic DoubleStreamEx asDoubleStream()
java.util.stream.IntStreamDoubleStream consisting of the elements of this stream,
converted to double.
This is an intermediate operation.
asDoubleStream in interface IntStreamDoubleStream consisting of the elements of this stream,
converted to doublepublic StreamEx<Integer> boxed()
java.util.stream.IntStreamStream consisting of the elements of this stream,
each boxed to an Integer.
This is an intermediate operation.
public IntStreamEx sequential()
java.util.stream.BaseStreamThis is an intermediate operation.
sequential in interface BaseStream<Integer,IntStream>sequential in interface IntStreampublic IntStreamEx parallel()
This is an intermediate operation.
If this stream was created using parallel(ForkJoinPool), the new
stream forgets about supplied custom ForkJoinPool and its
terminal operation will be executed in common pool.
public IntStreamEx parallel(ForkJoinPool fjp)
ForkJoinPool.
This is an intermediate operation.
The terminal operation of this stream or any derived stream (except the
streams created via parallel() or sequential() methods)
will be executed inside the supplied ForkJoinPool. If current
thread does not belong to that pool, it will wait till calculation
finishes.
fjp - a ForkJoinPool to submit the stream operation to.ForkJoinPoolpublic PrimitiveIterator.OfInt iterator()
java.util.stream.BaseStreamThis is a terminal operation.
public IntStreamEx append(int... values)
IntStreamEx which is a concatenation of this stream
and the stream containing supplied values
This is a quasi-intermediate operation.
values - the values to append to the streampublic IntStreamEx append(IntStream other)
other - the other streamIntStream.concat(IntStream, IntStream)public IntStreamEx prepend(int... values)
IntStreamEx which is a concatenation of the stream
containing supplied values and this stream
This is a quasi-intermediate operation.
values - the values to prepend to the streampublic IntStreamEx prepend(IntStream other)
other - the other streamIntStream.concat(IntStream, IntStream)public <U> StreamEx<U> elements(U[] array)
StreamEx consisting of the elements of
given array corresponding to the indices which appear in this stream.
This is an intermediate operation.
U - the element type of the new streamarray - the array to take the elements frompublic <U> StreamEx<U> elements(List<U> list)
StreamEx consisting of the elements of
given List corresponding to the indices which appear in this
stream.
The list elements are accessed using List.get(int), so the list
should provide fast random access. The list is assumed to be unmodifiable
during the stream operations.
This is an intermediate operation.
U - the element type of the new streamlist - the list to take the elements frompublic IntStreamEx elements(int[] array)
IntStreamEx consisting of the elements of given array
corresponding to the indices which appear in this stream.
This is an intermediate operation.
array - the array to take the elements frompublic LongStreamEx elements(long[] array)
LongStreamEx consisting of the elements of given array
corresponding to the indices which appear in this stream.
This is an intermediate operation.
array - the array to take the elements frompublic DoubleStreamEx elements(double[] array)
DoubleStreamEx consisting of the elements of given
array corresponding to the indices which appear in this stream.
This is an intermediate operation.
array - the array to take the elements frompublic String charsToString()
String consisting of chars from this stream.
This is a terminal operation.
During string creation stream elements are converted to chars using
(char) cast operation.
Stringpublic String codePointsToString()
String consisting of code points from this stream.
This is a terminal operation.
Stringpublic IntStreamEx pairMap(IntBinaryOperator mapper)
This is a quasi-intermediate operation.
The output stream will contain one element less than this stream. If this stream contains zero or one element the output stream will be empty.
mapper - a non-interfering, stateless function to apply to each
adjacent pair of this stream elements.public String joining(CharSequence delimiter)
String which is the concatenation of the results of
calling String.valueOf(int) on each element of this stream,
separated by the specified delimiter, in encounter order.
This is a terminal operation.
delimiter - the delimiter to be used between each elementpublic String joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
String which is the concatenation of the results of
calling String.valueOf(int) on each element of this stream,
separated by the specified delimiter, with the specified prefix and
suffix in encounter order.
This is a terminal operation.
delimiter - the delimiter to be used between each elementprefix - the sequence of characters to be used at the beginning of
the joined resultsuffix - the sequence of characters to be used at the end of the
joined resultprefix + suffix is returned.public IntStreamEx takeWhile(IntPredicate predicate)
This is a short-circuiting stateful operation. It can be either intermediate or quasi-intermediate. When using with JDK 1.9 or higher it calls the corresponding JDK 1.9 implementation. When using with JDK 1.8 it uses own implementation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
predicate - a non-interfering, stateless predicate to apply to
elements.takeWhileInclusive(IntPredicate),
dropWhile(IntPredicate)public IntStreamEx takeWhileInclusive(IntPredicate predicate)
This is a quasi-intermediate operation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
predicate - a non-interfering, stateless predicate to apply to
elements.takeWhile(IntPredicate)public IntStreamEx dropWhile(IntPredicate predicate)
This is a stateful operation. It can be either intermediate or quasi-intermediate. When using with JDK 1.9 or higher it calls the corresponding JDK 1.9 implementation. When using with JDK 1.8 it uses own implementation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
predicate - a non-interfering, stateless predicate to apply to
elements.public IntStreamEx mapFirst(IntUnaryOperator mapper)
This is a quasi-intermediate operation.
mapper - a
non-interfering
, stateless
function to apply to the first elementpublic IntStreamEx mapLast(IntUnaryOperator mapper)
This is a quasi-intermediate operation.
The mapper function is called at most once. It could be not called at all if the stream is empty or there is short-circuiting operation downstream.
mapper - a
non-interfering
, stateless
function to apply to the last elementpublic IntStreamEx prefix(IntBinaryOperator op)
This is a stateful quasi-intermediate operation.
This operation resembles scanLeft(IntBinaryOperator), but unlike
scanLeft this operation is intermediate and accumulation function
must be associative.
This method cannot take all the advantages of parallel streams as it must
process elements strictly left to right. Using an unordered source or
removing the ordering constraint with unordered() may improve
the parallel processing speed.
op - an associative
, non-interfering
, stateless
function for computing the next element based on the previous onescanLeft(IntBinaryOperator)public <U> U chain(Function<? super IntStreamEx,U> mapper)
This method can be used to add more functionality in the fluent style.
For example, consider user-defined static method
batches(stream, n) which breaks the stream into batches of given
length. Normally you would write
batches(StreamEx.of(input).map(...), 10).filter(...). Using the
chain() method you can write in more fluent manner:
StreamEx.of(input).map(...).chain(s -> batches(s, 10)).filter(...).
You could even go further and define a method which returns a function
like <T> UnaryOperator<StreamEx<T>> batches(int n) and use it
like this:
StreamEx.of(input).map(...).chain(batches(10)).filter(...).
U - the type of the function result.mapper - function to invoke.public static IntStreamEx empty()
IntStreamEx.public static IntStreamEx of(int element)
IntStreamEx containing a single element.public static IntStreamEx of(int... elements)
IntStreamEx whose elements are the
specified values.public static IntStreamEx of(int[] array, int startInclusive, int endExclusive)
IntStreamEx with the specified range of the
specified array as its source.array - the array, assumed to be unmodified during usestartInclusive - the first index to cover, inclusiveendExclusive - index immediately past the last index to coverIntStreamEx for the array rangeArrayIndexOutOfBoundsException - if startInclusive is
negative, endExclusive is less than
startInclusive, or endExclusive is greater than
the array sizeArrays.stream(int[], int, int)public static IntStreamEx of(byte... elements)
IntStreamEx whose elements are the
specified values casted to int.elements - the elements of the new streampublic static IntStreamEx of(byte[] array, int startInclusive, int endExclusive)
IntStreamEx with the specified range of the
specified array as its source. Array values will be casted to int.array - the array, assumed to be unmodified during usestartInclusive - the first index to cover, inclusiveendExclusive - index immediately past the last index to coverIntStreamEx for the array rangeArrayIndexOutOfBoundsException - if startInclusive is
negative, endExclusive is less than
startInclusive, or endExclusive is greater than
the array sizepublic static IntStreamEx of(char... elements)
IntStreamEx whose elements are the
specified values casted to int.elements - the elements of the new streampublic static IntStreamEx of(char[] array, int startInclusive, int endExclusive)
IntStreamEx with the specified range of the
specified array as its source. Array values will be casted to int.array - the array, assumed to be unmodified during usestartInclusive - the first index to cover, inclusiveendExclusive - index immediately past the last index to coverIntStreamEx for the array rangeArrayIndexOutOfBoundsException - if startInclusive is
negative, endExclusive is less than
startInclusive, or endExclusive is greater than
the array sizepublic static IntStreamEx of(short... elements)
IntStreamEx whose elements are the
specified values casted to int.elements - the elements of the new streampublic static IntStreamEx of(short[] array, int startInclusive, int endExclusive)
IntStreamEx with the specified range of the
specified array as its source. Array values will be casted to int.array - the array, assumed to be unmodified during usestartInclusive - the first index to cover, inclusiveendExclusive - index immediately past the last index to coverIntStreamEx for the array rangeArrayIndexOutOfBoundsException - if startInclusive is
negative, endExclusive is less than
startInclusive, or endExclusive is greater than
the array sizepublic static IntStreamEx of(InputStream is)
IntStreamEx backed by the content of
given InputStream.
The resulting stream contains int values between 0 and 255 (0xFF)
inclusive, as they are returned by the InputStream.read() method.
If you want to get byte values (e.g. -1 instead of 255),
simply cast the stream elements like .map(b -> (byte)b).
The terminal -1 value is excluded from the resulting stream.
If the underlying InputStream throws an IOException
during the stream traversal, it will be rethrown as
UncheckedIOException.
When the returned IntStreamEx is closed the original
InputStream is closed as well. If InputStream.close()
method throws an IOException, it will be rethrown as
UncheckedIOException.
is - an InputStream to create an IntStreamEx on.asByteInputStream()public static IntStreamEx of(Integer[] array)
IntStreamEx whose elements are the
unboxed elements of supplied array.array - the array to create the stream from.Arrays.stream(Object[])public static IntStreamEx of(IntBuffer buf)
IntStreamEx whose elements are the
values in the supplied IntBuffer.
The resulting stream covers only a portion of IntBuffer content
which starts with position (inclusive) and
ends with limit (exclusive). Changes in
position and limit after the stream creation don't affect the stream.
The resulting stream does not change the internal IntBuffer
state.
buf - the IntBuffer to create a stream frompublic static <T> IntStreamEx ofIndices(List<T> list)
IntStreamEx containing all the
indices of the supplied list.T - list element typelist - list to get the stream of its indicesIntStreamEx for the range of int
elements starting from 0 to (not inclusive) list.size()public static <T> IntStreamEx ofIndices(List<T> list, Predicate<T> predicate)
IntStreamEx containing all the
indices of the supplied list elements which match given predicate.
The list elements are accessed using List.get(int), so the list
should provide fast random access. The list is assumed to be unmodifiable
during the stream operations.
T - list element typelist - list to get the stream of its indicespredicate - a predicate to test list elementsIntStreamEx of the matched list indicespublic static <T> IntStreamEx ofIndices(T[] array)
IntStreamEx containing all the
indices of the supplied array.T - array element typearray - array to get the stream of its indicesIntStreamEx for the range of int
elements starting from 0 to (not inclusive) array.lengthpublic static <T> IntStreamEx ofIndices(T[] array, Predicate<T> predicate)
IntStreamEx containing all the
indices of the supplied array elements which match given predicate.T - array element typearray - array to get the stream of its indicespredicate - a predicate to test array elementsIntStreamEx of the matched array indicespublic static IntStreamEx ofIndices(int[] array)
IntStreamEx containing all the
indices of supplied array.array - array to get the stream of its indicesIntStreamEx for the range of int
elements starting from 0 to (not inclusive) array.lengthpublic static IntStreamEx ofIndices(int[] array, IntPredicate predicate)
IntStreamEx containing all the
indices of the supplied array elements which match given predicate.array - array to get the stream of its indicespredicate - a predicate to test array elementsIntStreamEx of the matched array indicespublic static IntStreamEx ofIndices(long[] array)
IntStreamEx containing all the
indices of supplied array.array - array to get the stream of its indicesIntStreamEx for the range of int
elements starting from 0 to (not inclusive) array.lengthpublic static IntStreamEx ofIndices(long[] array, LongPredicate predicate)
IntStreamEx containing all the
indices of the supplied array elements which match given predicate.array - array to get the stream of its indicespredicate - a predicate to test array elementsIntStreamEx of the matched array indicespublic static IntStreamEx ofIndices(double[] array)
IntStreamEx containing all the
indices of supplied array.array - array to get the stream of its indicesIntStreamEx for the range of int
elements starting from 0 to (not inclusive) array.lengthpublic static IntStreamEx ofIndices(double[] array, DoublePredicate predicate)
IntStreamEx containing all the
indices of the supplied array elements which match given predicate.array - array to get the stream of its indicespredicate - a predicate to test array elementsIntStreamEx of the matched array indicespublic static IntStreamEx of(IntStream stream)
IntStreamEx object which wraps given IntStream
.
The supplied stream must not be consumed or closed when this method is called. No operation must be performed on the supplied stream after it's wrapped.
stream - original streampublic static IntStreamEx of(Spliterator.OfInt spliterator)
IntStreamEx created from given
Spliterator.OfInt.spliterator - a spliterator to create the stream from.public static IntStreamEx of(PrimitiveIterator.OfInt iterator)
IntStreamEx created from given
PrimitiveIterator.OfInt.
This method is roughly equivalent to
IntStreamEx.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))
, but may show better performance for parallel processing.
Use this method only if you cannot provide better Stream source.
iterator - an iterator to create the stream from.public static IntStreamEx of(OptionalInt optional)
IntStreamEx containing an
OptionalInt value, if present, otherwise returns an empty
IntStreamEx.optional - the optional to create a stream ofOptionalInt value if present, otherwise
an empty streampublic static IntStreamEx of(BitSet bitSet)
IntStreamEx of indices for which the specified
BitSet contains a bit in the set state. The indices are returned
in order, from lowest to highest. The size of the stream is the number of
bits in the set state, equal to the value returned by the
BitSet.cardinality() method.
The bit set must remain constant during the execution of the terminal stream operation. Otherwise, the result of the terminal stream operation is undefined.
bitSet - a BitSet to produce the stream fromBitSet.stream()public static IntStreamEx of(Collection<Integer> collection)
IntStreamEx whose elements are the
unboxed elements of supplied collection.collection - the collection to create the stream from.Collection.stream()public static IntStreamEx of(Random random)
int
values produced by given Random object.
A pseudorandom int value is generated as if it's the result of
calling the method Random.nextInt().
random - a Random object to produce the stream fromint valuesRandom.ints()public static IntStreamEx of(Random random, long streamSize)
streamSize number of
pseudorandom int values.
A pseudorandom int value is generated as if it's the result of
calling the method Random.nextInt().
random - a Random object to produce the stream fromstreamSize - the number of values to generateint valuesRandom.ints(long)public static IntStreamEx of(Random random, int randomNumberOrigin, int randomNumberBound)
int
values, each conforming to the given origin (inclusive) and bound
(exclusive).random - a Random object to produce the stream fromrandomNumberOrigin - the origin (inclusive) of each random valuerandomNumberBound - the bound (exclusive) of each random valueint valuesRandom.ints(long, int, int)public static IntStreamEx of(Random random, long streamSize, int randomNumberOrigin, int randomNumberBound)
streamSize number of
pseudorandom int values, each conforming to the given origin
(inclusive) and bound (exclusive).random - a Random object to produce the stream fromstreamSize - the number of values to generaterandomNumberOrigin - the origin (inclusive) of each random valuerandomNumberBound - the bound (exclusive) of each random valueint valuesRandom.ints(long, int, int)public static IntStreamEx ofChars(CharSequence seq)
IntStreamEx of int zero-extending the
char values from the supplied CharSequence. Any char
which maps to a surrogate code point is passed through uninterpreted.
If the sequence is mutated while the stream is being read, the result is undefined.
seq - sequence to read characters fromCharSequence.chars()public static IntStreamEx ofCodePoints(CharSequence seq)
IntStreamEx of code point values from the supplied
CharSequence. Any surrogate pairs encountered in the sequence are
combined as if by Character.toCodePoint and the result is passed to the stream. Any other
code units, including ordinary BMP characters, unpaired surrogates, and
undefined code units, are zero-extended to int values which are
then passed to the stream.
If the sequence is mutated while the stream is being read, the result is undefined.
seq - sequence to read code points fromCharSequence.codePoints()public static IntStreamEx iterate(int seed, IntUnaryOperator f)
IntStreamEx produced by
iterative application of a function f to an initial element
seed, producing a stream consisting of seed,
f(seed), f(f(seed)), etc.
The first element (position 0) in the IntStreamEx will be
the provided seed. For n > 0, the element at position
n, will be the result of applying the function f to the
element at position n - 1.
iterate in interface IntStreamseed - the initial elementf - a function to be applied to to the previous element to produce a
new elementIntStreamiterate(int, IntPredicate, IntUnaryOperator)public static IntStreamEx iterate(int seed, IntPredicate predicate, IntUnaryOperator f)
IntStreamEx produced by iterative
application of a function to an initial element, conditioned on
satisfying the supplied predicate. The stream terminates as soon as the
predicate function returns false.
IntStreamEx.iterate should produce the same sequence of elements
as produced by the corresponding for-loop:
for (int index=seed; predicate.test(index); index = f.apply(index)) {
...
}
The resulting sequence may be empty if the predicate does not hold on the seed value. Otherwise the first element will be the supplied seed value, the next element (if present) will be the result of applying the function f to the seed value, and so on iteratively until the predicate indicates that the stream should terminate.
seed - the initial elementpredicate - a predicate to apply to elements to determine when the
stream must terminate.f - a function to be applied to the previous element to produce a
new elementIntStreamExiterate(int, IntUnaryOperator)public static IntStreamEx generate(IntSupplier s)
IntSupplier. This is suitable for
generating constant streams, streams of random elements, etc.generate in interface IntStreams - the IntSupplier for generated elementsIntStreamExIntStream.generate(IntSupplier)public static IntStreamEx produce(Predicate<IntConsumer> producer)
The producer function may call the passed consumer any number of times and return true if the producer should be called again or false otherwise. It's guaranteed that the producer will not be called anymore, once it returns false.
This method is particularly useful when producer changes the mutable object which should be left in known state after the full stream consumption. Note however that if a short-circuiting operation is used, then the final state of the mutable object cannot be guaranteed.
producer - a predicate which calls the passed consumer to emit
stream element(s) and returns true if it producer should be
applied again.public static IntStreamEx ints()
IntStreamEx from 0 (inclusive) to
Integer.MAX_VALUE (exclusive) by an incremental step of 1
.IntStreamEx for the range of int
elementsrange(int, int)public static IntStreamEx range(int endExclusive)
IntStreamEx from 0 (inclusive) to
endExclusive (exclusive) by an incremental step of 1.endExclusive - the exclusive upper boundIntStreamEx for the range of int
elementsrange(int, int)public static IntStreamEx range(int startInclusive, int endExclusive)
IntStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
an incremental step of 1.range in interface IntStreamstartInclusive - the (inclusive) initial valueendExclusive - the exclusive upper boundIntStreamEx for the range of int
elementsIntStream.range(int, int)public static IntStreamEx range(int startInclusive, int endExclusive, int step)
IntStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
the specified incremental step. The negative step values are also
supported. In this case the startInclusive should be greater than
endExclusive.startInclusive - the (inclusive) initial valueendExclusive - the exclusive upper boundstep - the non-zero value which designates the difference between
the consecutive values of the resulting stream.IntStreamEx for the range of int
elementsIllegalArgumentException - if step is zerorange(int, int)public static IntStreamEx rangeClosed(int startInclusive, int endInclusive)
IntStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
an incremental step of 1.rangeClosed in interface IntStreamstartInclusive - the (inclusive) initial valueendInclusive - the inclusive upper boundIntStreamEx for the range of int
elementsIntStream.rangeClosed(int, int)public static IntStreamEx rangeClosed(int startInclusive, int endInclusive, int step)
IntStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
the specified incremental step. The negative step values are also
supported. In this case the startInclusive should be greater than
endInclusive.
Note that depending on the step value the endInclusive bound may
still not be reached. For example
IntStreamEx.rangeClosed(0, 5, 2) will yield the stream of three
numbers: 0, 2 and 4.
startInclusive - the (inclusive) initial valueendInclusive - the inclusive upper boundstep - the non-zero value which designates the difference between
the consecutive values of the resulting stream.IntStreamEx for the range of int
elementsIllegalArgumentException - if step is zerorangeClosed(int, int)public static IntStreamEx constant(int value, long length)
IntStreamEx of given length which
elements are equal to supplied value.value - the constant valuelength - the length of the streamIntStreamExpublic static IntStreamEx zip(int[] first, int[] second, IntBinaryOperator mapper)
IntStreamEx containing the results of
applying the given function to the corresponding pairs of values in given
two arrays.first - the first arraysecond - the second arraymapper - a non-interfering, stateless function to apply to each pair
of the corresponding array elements.IntStreamExIllegalArgumentException - if length of the arrays differs.public SPLTR spliterator()
java.util.stream.BaseStreamThis is a terminal operation.
spliterator in interface BaseStream<T,S extends BaseStream<T,S>>public boolean isParallel()
java.util.stream.BaseStreamisParallel in interface BaseStream<T,S extends BaseStream<T,S>>true if this stream would execute in parallel if executedpublic void close()
java.util.stream.BaseStreamclose in interface AutoCloseableclose in interface BaseStream<T,S extends BaseStream<T,S>>AutoCloseable.close()Copyright © 2017. All rights reserved.