public class LongStreamEx extends Object implements LongStream
LongStream implementation with additional functionality| Modifier and Type | Class and Description |
|---|---|
static interface |
LongStreamEx.LongEmitter
A helper interface to build a new stream by emitting elements and
creating new emitters in a chain.
|
LongStream.Builder| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(LongPredicate predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(LongPredicate predicate)
Returns whether any elements of this stream match the provided
predicate.
|
LongStreamEx |
append(long... values)
Returns a new
LongStreamEx which is a concatenation of this
stream and the stream containing supplied values
This is a quasi-intermediate
operation. |
LongStreamEx |
append(LongStream other)
Creates a lazily concatenated stream whose elements are all the elements
of this stream followed by all the elements of the other stream.
|
DoubleStreamEx |
asDoubleStream()
Returns a
DoubleStream consisting of the elements of this stream,
converted to double. |
LongStreamEx |
atLeast(long value)
Returns a stream consisting of the elements of this stream that greater
than or equal to the specified value.
|
LongStreamEx |
atMost(long 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<Long> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to a Long. |
<U> U |
chain(Function<? super LongStreamEx,U> mapper)
Applies the supplied function to this stream and returns the result of
the function.
|
void |
close()
Closes this stream, causing all close handlers for this stream pipeline
to be called.
|
<A,R> R |
collect(LongCollector<A,R> collector)
Performs a mutable reduction operation on the elements of this stream
using an
LongCollector which encapsulates the supplier,
accumulator and merger functions making easier to reuse collection
strategies. |
<R> R |
collect(Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R,R> combiner)
Performs a mutable
reduction operation on the elements of this stream.
|
static LongStreamEx |
constant(long value,
long length)
Returns a sequential unordered
LongStreamEx of given length which
elements are equal to supplied value. |
long |
count()
Returns the count of elements in this stream.
|
LongStreamEx |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
LongStreamEx |
dropWhile(LongPredicate predicate)
Returns a stream consisting of all elements from this stream starting
from the first element which does not match the given predicate.
|
static LongStreamEx |
empty()
Returns an empty sequential
LongStreamEx. |
LongStreamEx |
filter(LongPredicate predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
OptionalLong |
findAny()
Returns an
OptionalLong describing some element of the stream, or
an empty OptionalLong if the stream is empty. |
OptionalLong |
findAny(LongPredicate predicate)
Returns an
OptionalLong describing some element of the stream,
which matches given predicate, or an empty OptionalLong if
there's no matching element. |
OptionalLong |
findFirst()
Returns an
OptionalLong describing the first element of this
stream, or an empty OptionalLong if the stream is empty. |
OptionalLong |
findFirst(LongPredicate predicate)
Returns an
OptionalLong describing the first element of this
stream, which matches given predicate, or an empty OptionalLong
if there's no matching element. |
LongStreamEx |
flatMap(LongFunction<? extends LongStream> 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(LongFunction<? 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. |
IntStreamEx |
flatMapToInt(LongFunction<? extends IntStream> mapper)
Returns an
IntStreamEx 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(LongFunction<? 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. |
OptionalLong |
foldLeft(LongBinaryOperator accumulator)
Folds the elements of this stream using the provided accumulation
function, going left to right.
|
long |
foldLeft(long seed,
LongBinaryOperator accumulator)
Folds the elements of this stream using the provided seed object and
accumulation function, going left to right.
|
void |
forEach(LongConsumer action)
Performs an action for each element of this stream.
|
void |
forEachOrdered(LongConsumer 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 LongStreamEx |
generate(LongSupplier s)
Returns an infinite sequential unordered stream where each element is
generated by the provided
LongSupplier. |
LongStreamEx |
greater(long value)
Returns a stream consisting of the elements of this stream that strictly
greater than the specified value.
|
boolean |
has(long value)
Returns true if this stream contains the specified value
This is a short-circuiting terminal operation.
|
OptionalLong |
indexOf(long 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(LongPredicate 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. |
boolean |
isParallel()
Returns whether this stream, if a terminal operation were to be executed,
would execute in parallel.
|
static LongStreamEx |
iterate(long seed,
LongPredicate predicate,
LongUnaryOperator f)
Returns a sequential ordered
LongStreamEx produced by iterative
application of a function to an initial element, conditioned on
satisfying the supplied predicate. |
static LongStreamEx |
iterate(long seed,
LongUnaryOperator f)
Returns an infinite sequential ordered
LongStreamEx 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.OfLong |
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(long) 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(long) on each element of this stream,
separated by the specified delimiter, with the specified prefix and
suffix in encounter order. |
LongStreamEx |
less(long value)
Returns a stream consisting of the elements of this stream that strictly
less than the specified value.
|
LongStreamEx |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
static LongStreamEx |
longs()
Returns a sequential ordered
LongStreamEx from 0 (inclusive) to
Long.MAX_VALUE (exclusive) by an incremental step of 1. |
LongStreamEx |
map(LongUnaryOperator mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
LongStreamEx |
mapFirst(LongUnaryOperator 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.
|
LongStreamEx |
mapLast(LongUnaryOperator 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(LongToDoubleFunction 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(LongFunction<? extends K> keyMapper,
LongFunction<? 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. |
IntStreamEx |
mapToInt(LongToIntFunction mapper)
Returns an
IntStream consisting of the results of applying the
given function to the elements of this stream. |
<U> StreamEx<U> |
mapToObj(LongFunction<? extends U> mapper)
Returns an object-valued
Stream consisting of the results of
applying the given function to the elements of this stream. |
OptionalLong |
max()
Returns an
OptionalLong describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalLong |
max(Comparator<Long> comparator)
Returns the maximum element of this stream according to the provided
Comparator. |
<V extends Comparable<? super V>> |
maxBy(LongFunction<V> keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalLong |
maxByDouble(LongToDoubleFunction keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalLong |
maxByInt(LongToIntFunction keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalLong |
maxByLong(LongUnaryOperator keyExtractor)
Returns the maximum element of this stream according to the provided key
extractor function.
|
OptionalLong |
min()
Returns an
OptionalLong describing the minimum element of this
stream, or an empty optional if this stream is empty. |
OptionalLong |
min(Comparator<Long> comparator)
Returns the minimum element of this stream according to the provided
Comparator. |
<V extends Comparable<? super V>> |
minBy(LongFunction<V> keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalLong |
minByDouble(LongToDoubleFunction keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalLong |
minByInt(LongToIntFunction keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
OptionalLong |
minByLong(LongUnaryOperator keyExtractor)
Returns the minimum element of this stream according to the provided key
extractor function.
|
boolean |
noneMatch(LongPredicate predicate)
Returns whether no elements of this stream match the provided predicate.
|
static LongStreamEx |
of(Collection<Long> collection)
Returns a sequential ordered
LongStreamEx whose elements are the
unboxed elements of supplied collection. |
static LongStreamEx |
of(long... elements)
Returns a sequential ordered
LongStreamEx whose elements are the
specified values. |
static LongStreamEx |
of(long element)
Returns a sequential
LongStreamEx containing a single element. |
static LongStreamEx |
of(Long[] array)
Returns a sequential ordered
LongStreamEx whose elements are the
unboxed elements of supplied array. |
static LongStreamEx |
of(long[] array,
int startInclusive,
int endExclusive)
Returns a sequential
LongStreamEx with the specified range of the
specified array as its source. |
static LongStreamEx |
of(LongBuffer buf)
Returns a sequential ordered
LongStreamEx whose elements are the
values in the supplied LongBuffer. |
static LongStreamEx |
of(LongStream stream)
Returns a
LongStreamEx object which wraps given
LongStream. |
static LongStreamEx |
of(OptionalLong optional)
Returns a sequential
LongStreamEx containing an
OptionalLong value, if present, otherwise returns an empty
LongStreamEx. |
static LongStreamEx |
of(PrimitiveIterator.OfLong iterator)
Returns a sequential, ordered
LongStreamEx created from given
PrimitiveIterator.OfLong. |
static LongStreamEx |
of(Random random)
Returns an effectively unlimited stream of pseudorandom
long
values produced by given Random object. |
static LongStreamEx |
of(Random random,
long streamSize)
Returns a stream producing the given
streamSize number of
pseudorandom long values. |
static LongStreamEx |
of(Random random,
long randomNumberOrigin,
long randomNumberBound)
Returns an effectively unlimited stream of pseudorandom
long
values, each conforming to the given origin (inclusive) and bound
(exclusive). |
static LongStreamEx |
of(Random random,
long streamSize,
long randomNumberOrigin,
long randomNumberBound)
Returns a stream producing the given
streamSize number of
pseudorandom long values, each conforming to the given origin
(inclusive) and bound (exclusive). |
static LongStreamEx |
of(Spliterator.OfLong spliterator)
Returns a sequential
LongStreamEx created from given
Spliterator.OfLong. |
LongStreamEx |
onClose(Runnable closeHandler)
Returns an equivalent stream with an additional close handler.
|
LongStreamEx |
pairMap(LongBinaryOperator mapper)
Returns a stream consisting of the results of applying the given function
to the every adjacent pair of elements of this stream.
|
LongStreamEx |
parallel()
Returns an equivalent stream that is parallel.
|
LongStreamEx |
parallel(ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the supplied
ForkJoinPool. |
LongStreamEx |
peek(LongConsumer 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.
|
LongStreamEx |
peekFirst(LongConsumer 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.
|
LongStreamEx |
peekLast(LongConsumer 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.
|
LongStreamEx |
prefix(LongBinaryOperator op)
Returns a stream containing cumulative results of applying the
accumulation function going left to right.
|
LongStreamEx |
prepend(long... values)
Returns a new
LongStreamEx which is a concatenation of the stream
containing supplied values and this stream
This is a quasi-intermediate
operation. |
LongStreamEx |
prepend(LongStream 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 LongStreamEx |
produce(Predicate<LongConsumer> producer)
Return an ordered stream produced by consecutive calls of the supplied
producer until it returns false.
|
static LongStreamEx |
range(long endExclusive)
Returns a sequential ordered
LongStreamEx from 0 (inclusive) to
endExclusive (exclusive) by an incremental step of 1. |
static LongStreamEx |
range(long startInclusive,
long endExclusive)
Returns a sequential ordered
LongStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
an incremental step of 1. |
static LongStreamEx |
range(long startInclusive,
long endExclusive,
long step)
Returns a sequential ordered
LongStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
the specified incremental step. |
static LongStreamEx |
rangeClosed(long startInclusive,
long endInclusive)
Returns a sequential ordered
LongStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
an incremental step of 1. |
static LongStreamEx |
rangeClosed(long startInclusive,
long endInclusive,
long step)
Returns a sequential ordered
LongStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
the specified incremental step. |
OptionalLong |
reduce(LongBinaryOperator op)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
OptionalLong describing the reduced value,
if any. |
long |
reduce(long identity,
LongBinaryOperator 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.
|
LongStreamEx |
remove(LongPredicate predicate)
Returns a stream consisting of the elements of this stream that don't
match the given predicate.
|
LongStreamEx |
reverseSorted()
Returns a stream consisting of the elements of this stream in reverse
sorted order.
|
long[] |
scanLeft(LongBinaryOperator accumulator)
Produces an array containing cumulative results of applying the
accumulation function going left to right.
|
long[] |
scanLeft(long seed,
LongBinaryOperator accumulator)
Produces an array containing cumulative results of applying the
accumulation function going left to right using given seed value.
|
LongStreamEx |
sequential()
Returns an equivalent stream that is sequential.
|
LongStreamEx |
skip(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
LongStreamEx |
skipOrdered(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
LongStreamEx |
sorted()
Returns a stream consisting of the elements of this stream in sorted
order.
|
LongStreamEx |
sorted(Comparator<Long> comparator)
Returns a stream consisting of the elements of this stream sorted
according to the given comparator.
|
<V extends Comparable<? super V>> |
sortedBy(LongFunction<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.
|
LongStreamEx |
sortedByDouble(LongToDoubleFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the double values extracted by provided function.
|
LongStreamEx |
sortedByInt(LongToIntFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted
according to the int values extracted by provided function.
|
LongStreamEx |
sortedByLong(LongUnaryOperator 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.
|
long |
sum()
Returns the sum of elements in this stream.
|
LongSummaryStatistics |
summaryStatistics()
Returns a
LongSummaryStatistics describing various summary data
about the elements of this stream. |
LongStreamEx |
takeWhile(LongPredicate predicate)
Returns a stream consisting of all elements from this stream until the
first element which does not match the given predicate is found.
|
LongStreamEx |
takeWhileInclusive(LongPredicate 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).
|
long[] |
toArray()
Returns an array containing the elements of this stream.
|
LongStreamEx |
unordered()
Returns an equivalent stream that is
unordered.
|
LongStreamEx |
without(long... values)
Returns a stream consisting of the elements of this stream that don't
equal to any of the supplied values.
|
LongStreamEx |
without(long value)
Returns a stream consisting of the elements of this stream that don't
equal to the given value.
|
static LongStreamEx |
zip(long[] first,
long[] second,
LongBinaryOperator mapper)
Returns a sequential
LongStreamEx 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 LongStreamEx unordered()
java.util.stream.BaseStreamThis is an intermediate operation.
unordered in interface BaseStream<Long,LongStream>public LongStreamEx 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<Long,LongStream>closeHandler - A task to execute when the stream is closedpublic LongStreamEx filter(LongPredicate predicate)
java.util.stream.LongStreamThis is an intermediate operation.
filter in interface LongStreampredicate - a non-interfering,
stateless
predicate to apply to each element to determine if it
should be includedpublic LongStreamEx remove(LongPredicate 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(long value)
This is a short-circuiting terminal operation.
value - the value too look for in the streamLongStream.anyMatch(LongPredicate)public LongStreamEx without(long value)
This is an intermediate operation.
value - the value to remove from the stream.without(long...),
remove(LongPredicate)public LongStreamEx without(long... 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(long),
remove(LongPredicate)public LongStreamEx greater(long value)
This is an intermediate operation.
value - a value to compare topublic LongStreamEx atLeast(long value)
This is an intermediate operation.
value - a value to compare topublic LongStreamEx less(long value)
This is an intermediate operation.
value - a value to compare topublic LongStreamEx atMost(long value)
This is an intermediate operation.
value - a value to compare topublic LongStreamEx map(LongUnaryOperator mapper)
java.util.stream.LongStreamThis is an intermediate operation.
map in interface LongStreammapper - a non-interfering,
stateless
function to apply to each elementpublic LongStreamEx mapFirst(LongUnaryOperator mapper)
This is a quasi-intermediate operation.
mapper - a
non-interfering
, stateless
function to apply to the first elementpublic LongStreamEx mapLast(LongUnaryOperator 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 <U> StreamEx<U> mapToObj(LongFunction<? extends U> mapper)
java.util.stream.LongStreamStream consisting of the results of
applying the given function to the elements of this stream.
This is an intermediate operation.
mapToObj in interface LongStreamU - the element type of the new streammapper - a non-interfering,
stateless
function to apply to each elementpublic IntStreamEx mapToInt(LongToIntFunction mapper)
java.util.stream.LongStreamIntStream consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToInt in interface LongStreammapper - a non-interfering,
stateless
function to apply to each elementpublic DoubleStreamEx mapToDouble(LongToDoubleFunction mapper)
java.util.stream.LongStreamDoubleStream consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToDouble in interface LongStreammapper - a non-interfering,
stateless
function to apply to each elementpublic <K,V> EntryStream<K,V> mapToEntry(LongFunction<? extends K> keyMapper, LongFunction<? 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 LongStreamEx flatMap(LongFunction<? extends LongStream> mapper)
java.util.stream.LongStreamclosed 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 LongStreammapper - a non-interfering,
stateless
function to apply to each element which produces a
LongStream of new valuesStream.flatMap(Function)public IntStreamEx flatMapToInt(LongFunction<? extends IntStream> mapper)
IntStreamEx 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 an IntStream of new valuespublic DoubleStreamEx flatMapToDouble(LongFunction<? 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 an DoubleStream of new valuespublic <R> StreamEx<R> flatMapToObj(LongFunction<? 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 LongStreamEx distinct()
java.util.stream.LongStreamThis is a stateful intermediate operation.
distinct in interface LongStreampublic LongStreamEx sorted()
java.util.stream.LongStreamThis is a stateful intermediate operation.
sorted in interface LongStreampublic LongStreamEx sorted(Comparator<Long> 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 LongStreamEx reverseSorted()
This is a stateful intermediate operation.
public <V extends Comparable<? super V>> LongStreamEx sortedBy(LongFunction<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 LongStreamEx sortedByInt(LongToIntFunction 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 LongStreamEx sortedByLong(LongUnaryOperator 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 LongStreamEx sortedByDouble(LongToDoubleFunction 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 LongStreamEx peek(LongConsumer action)
java.util.stream.LongStreamThis 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 LongStreamaction - a
non-interfering action to perform on the elements as
they are consumed from the streampublic LongStreamEx peekFirst(LongConsumer 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 LongStreamEx peekLast(LongConsumer 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 LongStreamEx limit(long maxSize)
java.util.stream.LongStreammaxSize in length.
limit in interface LongStreammaxSize - the number of elements the stream should be limited topublic LongStreamEx skip(long n)
java.util.stream.LongStreamn 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.
skip in interface LongStreamn - the number of leading elements to skippublic LongStreamEx 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(LongConsumer)). This problem was fixed in OracleJDK
8u60.
Also it behaves much better with infinite streams processed in parallel.
For example,
LongStreamEx.iterate(0L, 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(LongConsumer action)
java.util.stream.LongStreamThis 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 LongStreamaction - a
non-interfering action to perform on the elementspublic void forEachOrdered(LongConsumer action)
java.util.stream.LongStreamThis is a terminal operation.
forEachOrdered in interface LongStreamaction - a
non-interfering action to perform on the elementsLongStream.forEach(LongConsumer)public long[] toArray()
java.util.stream.LongStreamThis is a terminal operation.
toArray in interface LongStreampublic long reduce(long identity,
LongBinaryOperator op)
java.util.stream.LongStream
long result = identity;
for (long element : this stream)
result = accumulator.applyAsLong(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 LongStreamidentity - the identity value for the accumulating functionop - an associative,
non-interfering,
stateless
function for combining two valuesLongStream.sum(),
LongStream.min(),
LongStream.max(),
LongStream.average()public OptionalLong reduce(LongBinaryOperator op)
java.util.stream.LongStreamOptionalLong describing the reduced value,
if any. This is equivalent to:
boolean foundAny = false;
long result = null;
for (long element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.applyAsLong(result, element);
}
return foundAny ? OptionalLong.of(result) : OptionalLong.empty();
but is not constrained to execute sequentially.
The accumulator function must be an
associative function.
This is a terminal operation.
reduce in interface LongStreamop - an associative,
non-interfering,
stateless
function for combining two valuesLongStream.reduce(long, LongBinaryOperator)public OptionalLong foldLeft(LongBinaryOperator accumulator)
boolean foundAny = false;
long result = 0;
for (long element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.apply(result, element);
}
return foundAny ? OptionalLong.of(result) : OptionalLong.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(LongBinaryOperator) 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(long, LongBinaryOperator),
reduce(LongBinaryOperator)public long foldLeft(long seed,
LongBinaryOperator accumulator)
long result = seed;
for (long 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(long, LongBinaryOperator)
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(long, LongBinaryOperator),
foldLeft(LongBinaryOperator)public long[] scanLeft(LongBinaryOperator 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(LongBinaryOperator)public long[] scanLeft(long seed,
LongBinaryOperator 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(long, LongBinaryOperator)public <R> R collect(Supplier<R> supplier, ObjLongConsumer<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 (long element : this stream)
accumulator.accept(result, element);
return result;
Like LongStream.reduce(long, LongBinaryOperator), collect operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
collect in interface LongStreamR - 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(LongCollector)public <A,R> R collect(LongCollector<A,R> collector)
LongCollector which encapsulates the supplier,
accumulator and merger functions making easier to reuse collection
strategies.
Like reduce(long, LongBinaryOperator), collect
operations can be parallelized without requiring additional
synchronization.
This is a terminal operation.
A - the intermediate accumulation type of the
LongCollectorR - type of the resultcollector - the LongCollector describing the reductioncollect(Supplier, ObjLongConsumer, BiConsumer)public long sum()
java.util.stream.LongStream
return reduce(0, Long::sum);
This is a terminal operation.
sum in interface LongStreampublic OptionalLong min()
java.util.stream.LongStreamOptionalLong 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(Long::min);
This is a terminal operation.
min in interface LongStreamOptionalLong containing the minimum element of this
stream, or an empty OptionalLong if the stream is emptypublic OptionalLong min(Comparator<Long> comparator)
Comparator.
This is a terminal operation.
comparator - a non-interfering, stateless Comparator to
compare elements of this streamOptionalLong describing the minimum element of this
stream, or an empty OptionalLong if the stream is emptypublic <V extends Comparable<? super V>> OptionalLong minBy(LongFunction<V> keyExtractor)
This is a terminal operation.
V - the type of the Comparable sort keykeyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the lowest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong minByInt(LongToIntFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the lowest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong minByLong(LongUnaryOperator keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the lowest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong minByDouble(LongToDoubleFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the lowest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong max()
java.util.stream.LongStreamOptionalLong 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(Long::max);
This is a terminal operation.
max in interface LongStreamOptionalLong containing the maximum element of this
stream, or an empty OptionalLong if the stream is emptypublic OptionalLong max(Comparator<Long> comparator)
Comparator.
This is a terminal operation.
comparator - a non-interfering, stateless Comparator to
compare elements of this streamOptionalLong describing the maximum element of this
stream, or an empty OptionalLong if the stream is emptypublic <V extends Comparable<? super V>> OptionalLong maxBy(LongFunction<V> keyExtractor)
This is a terminal operation.
V - the type of the Comparable sort keykeyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong maxByInt(LongToIntFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong maxByLong(LongUnaryOperator keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic OptionalLong maxByDouble(LongToDoubleFunction keyExtractor)
This is a terminal operation.
keyExtractor - a non-interfering, stateless functionOptionalLong describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty OptionalLong if the stream is emptypublic long count()
java.util.stream.LongStream
return map(e -> 1L).sum();
This is a terminal operation.
count in interface LongStreampublic OptionalDouble average()
java.util.stream.LongStreamOptionalDouble 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.
average in interface LongStreamOptionalDouble containing the average element of this
stream, or an empty optional if the stream is emptypublic LongSummaryStatistics summaryStatistics()
java.util.stream.LongStreamLongSummaryStatistics 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 LongStreamLongSummaryStatistics describing various summary data
about the elements of this streampublic boolean anyMatch(LongPredicate predicate)
java.util.stream.LongStreamfalse is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
anyMatch in interface LongStreampredicate - 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(LongPredicate predicate)
java.util.stream.LongStreamtrue is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
allMatch in interface LongStreampredicate - 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(LongPredicate predicate)
java.util.stream.LongStreamtrue is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
noneMatch in interface LongStreampredicate - 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 OptionalLong findFirst()
java.util.stream.LongStreamOptionalLong describing the first element of this
stream, or an empty OptionalLong 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.
findFirst in interface LongStreamOptionalLong describing the first element of this
stream, or an empty OptionalLong if the stream is emptypublic OptionalLong findFirst(LongPredicate predicate)
OptionalLong describing 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 first matching element of
this stream, or an empty OptionalLong if there's no
matching elementfindFirst()public OptionalLong findAny()
java.util.stream.LongStreamOptionalLong describing some element of the stream, or
an empty OptionalLong 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 LongStream.findFirst() instead.)
findAny in interface LongStreamOptionalLong describing some element of this stream,
or an empty OptionalLong if the stream is emptyLongStream.findFirst()public OptionalLong findAny(LongPredicate predicate)
OptionalLong describing some element of the stream,
which matches given predicate, or an empty OptionalLong 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(LongPredicate) instead.)
predicate - a
non-interfering
, stateless
predicate which returned value should matchOptionalLong describing some matching element of this
stream, or an empty OptionalLong if there's no matching
elementfindAny(),
findFirst(LongPredicate)public OptionalLong indexOf(long 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(LongPredicate)public OptionalLong indexOf(LongPredicate 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(LongPredicate)public DoubleStreamEx asDoubleStream()
java.util.stream.LongStreamDoubleStream consisting of the elements of this stream,
converted to double.
This is an intermediate operation.
asDoubleStream in interface LongStreamDoubleStream consisting of the elements of this stream,
converted to doublepublic StreamEx<Long> boxed()
java.util.stream.LongStreamStream consisting of the elements of this stream,
each boxed to a Long.
This is an intermediate operation.
boxed in interface LongStreamStream consistent of the elements of this stream,
each boxed to Longpublic LongStreamEx sequential()
java.util.stream.BaseStreamThis is an intermediate operation.
sequential in interface BaseStream<Long,LongStream>sequential in interface LongStreampublic LongStreamEx 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.
parallel in interface BaseStream<Long,LongStream>parallel in interface LongStreampublic LongStreamEx 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.OfLong iterator()
java.util.stream.BaseStreamThis is a terminal operation.
iterator in interface BaseStream<Long,LongStream>iterator in interface LongStreampublic LongStreamEx append(long... values)
LongStreamEx 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 LongStreamEx append(LongStream other)
other - the other streamLongStream.concat(LongStream, LongStream)public LongStreamEx prepend(long... values)
LongStreamEx 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 LongStreamEx prepend(LongStream other)
other - the other streamLongStream.concat(LongStream, LongStream)public LongStreamEx pairMap(LongBinaryOperator 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(long) 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(long) 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 LongStreamEx takeWhile(LongPredicate 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(LongPredicate),
dropWhile(LongPredicate)public LongStreamEx takeWhileInclusive(LongPredicate 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(LongPredicate)public LongStreamEx dropWhile(LongPredicate 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 LongStreamEx prefix(LongBinaryOperator op)
This is a stateful quasi-intermediate operation.
This operation resembles scanLeft(LongBinaryOperator), 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(LongBinaryOperator)public <U> U chain(Function<? super LongStreamEx,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 LongStreamEx empty()
LongStreamEx.empty in interface LongStreampublic static LongStreamEx of(long element)
LongStreamEx containing a single element.of in interface LongStreamelement - the single elementpublic static LongStreamEx of(long... elements)
LongStreamEx whose elements are the
specified values.of in interface LongStreamelements - the elements of the new streampublic static LongStreamEx of(long[] array, int startInclusive, int endExclusive)
LongStreamEx 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 coverLongStreamEx for the array rangeArrayIndexOutOfBoundsException - if startInclusive is
negative, endExclusive is less than
startInclusive, or endExclusive is greater than
the array sizeArrays.stream(long[], int, int)public static LongStreamEx of(Long[] array)
LongStreamEx whose elements are the
unboxed elements of supplied array.array - the array to create the stream from.Arrays.stream(Object[])public static LongStreamEx of(LongBuffer buf)
LongStreamEx whose elements are the
values in the supplied LongBuffer.
The resulting stream covers only a portion of LongBuffer 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 LongBuffer
state.
buf - the LongBuffer to create a stream frompublic static LongStreamEx of(LongStream stream)
LongStreamEx object which wraps given
LongStream.
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 LongStreamEx of(Spliterator.OfLong spliterator)
LongStreamEx created from given
Spliterator.OfLong.spliterator - a spliterator to create the stream from.public static LongStreamEx of(PrimitiveIterator.OfLong iterator)
LongStreamEx created from given
PrimitiveIterator.OfLong.
This method is roughly equivalent to
LongStreamEx.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 LongStreamEx of(OptionalLong optional)
LongStreamEx containing an
OptionalLong value, if present, otherwise returns an empty
LongStreamEx.optional - the optional to create a stream ofOptionalLong value if present, otherwise
an empty streampublic static LongStreamEx of(Collection<Long> collection)
LongStreamEx whose elements are the
unboxed elements of supplied collection.collection - the collection to create the stream from.Collection.stream()public static LongStreamEx of(Random random)
long
values produced by given Random object.
A pseudorandom long value is generated as if it's the result of
calling the method Random.nextLong().
random - a Random object to produce the stream fromlong valuesRandom.longs()public static LongStreamEx of(Random random, long streamSize)
streamSize number of
pseudorandom long values.
A pseudorandom long value is generated as if it's the result of
calling the method Random.nextLong()
random - a Random object to produce the stream fromstreamSize - the number of values to generatelong valuesRandom.longs(long)public static LongStreamEx of(Random random, long randomNumberOrigin, long randomNumberBound)
long
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 valuelong valuesRandom.longs(long, long, long)public static LongStreamEx of(Random random, long streamSize, long randomNumberOrigin, long randomNumberBound)
streamSize number of
pseudorandom long 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 valuelong valuesRandom.longs(long, long, long)public static LongStreamEx iterate(long seed, LongUnaryOperator f)
LongStreamEx 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 LongStreamEx 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 LongStreamseed - the initial elementf - a function to be applied to to the previous element to produce a
new elementLongStreamiterate(long, LongPredicate, LongUnaryOperator)public static LongStreamEx iterate(long seed, LongPredicate predicate, LongUnaryOperator f)
LongStreamEx 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.
LongStreamEx.iterate should produce the same sequence of elements
as produced by the corresponding for-loop:
for (long 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 elementLongStreamExiterate(long, LongUnaryOperator)public static LongStreamEx generate(LongSupplier s)
LongSupplier. This is suitable for
generating constant streams, streams of random elements, etc.generate in interface LongStreams - the LongSupplier for generated elementsLongStreamExLongStream.generate(LongSupplier)public static LongStreamEx produce(Predicate<LongConsumer> 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 LongStreamEx longs()
LongStreamEx from 0 (inclusive) to
Long.MAX_VALUE (exclusive) by an incremental step of 1.LongStreamEx for the range of long
elementsrange(long, long)public static LongStreamEx range(long endExclusive)
LongStreamEx from 0 (inclusive) to
endExclusive (exclusive) by an incremental step of 1.endExclusive - the exclusive upper boundLongStreamEx for the range of int
elementsrange(long, long)public static LongStreamEx range(long startInclusive, long endExclusive)
LongStreamEx from
startInclusive (inclusive) to endExclusive (exclusive) by
an incremental step of 1.range in interface LongStreamstartInclusive - the (inclusive) initial valueendExclusive - the exclusive upper boundLongStreamEx for the range of long
elementsLongStream.range(long, long)public static LongStreamEx range(long startInclusive, long endExclusive, long step)
LongStreamEx 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.LongStreamEx for the range of long
elementsIllegalArgumentException - if step is zerorange(long, long)public static LongStreamEx rangeClosed(long startInclusive, long endInclusive)
LongStreamEx from
startInclusive (inclusive) to endInclusive (inclusive) by
an incremental step of 1.rangeClosed in interface LongStreamstartInclusive - the (inclusive) initial valueendInclusive - the inclusive upper boundLongStreamEx for the range of long
elementsLongStream.rangeClosed(long, long)public static LongStreamEx rangeClosed(long startInclusive, long endInclusive, long step)
LongStreamEx 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
LongStreamEx.rangeClosed(0, 5, 2) will yield the stream of three
numbers: 0L, 2L and 4L.
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.LongStreamEx for the range of long
elementsIllegalArgumentException - if step is zerorangeClosed(long, long)public static LongStreamEx constant(long value, long length)
LongStreamEx of given length which
elements are equal to supplied value.value - the constant valuelength - the length of the streamLongStreamExpublic static LongStreamEx zip(long[] first, long[] second, LongBinaryOperator mapper)
LongStreamEx 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.LongStreamExIllegalArgumentException - 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.