| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(LongPredicate predicate)
Tests whether all elements match the given predicate.
|
boolean |
anyMatch(LongPredicate predicate)
Tests whether all elements match the given predicate.
|
Stream<Long> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to an Long. |
<R> R |
collect(Supplier<R> supplier,
ObjLongConsumer<R> accumulator)
Collects elements to
supplier provided container by applying the given accumulation function. |
static LongStream |
concat(LongStream a,
LongStream b)
Concatenates two streams.
|
long |
count()
Returns the count of elements in this stream.
|
<R> R |
custom(Function<LongStream,R> function)
Applies custom operator on stream.
|
LongStream |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
LongStream |
dropWhile(LongPredicate predicate)
Drops elements while the predicate is true and returns the rest.
|
static LongStream |
empty()
Returns an empty stream.
|
LongStream |
filter(LongPredicate predicate)
Returns
LongStream with elements that satisfy the given predicate. |
LongStream |
filterNot(LongPredicate predicate)
Returns
LongStream with elements that does not satisfy the given predicate. |
OptionalLong |
findFirst()
Returns the first element wrapped by
OptionalLong class. |
OptionalLong |
findSingle()
Returns the single element wrapped by
OptionalLong class. |
LongStream |
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.
|
void |
forEach(LongConsumer action)
Performs an action for each element of this stream.
|
static LongStream |
generate(LongSupplier s)
Creates a
LongStream by elements that generated by LongSupplier. |
static LongStream |
iterate(long seed,
LongPredicate predicate,
LongUnaryOperator op)
Creates an
LongStream by iterative application LongUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate. |
static LongStream |
iterate(long seed,
LongUnaryOperator f)
Creates a
LongStream by iterative application LongUnaryOperator function
to an initial element seed. |
PrimitiveIterator.OfLong |
iterator()
Returns internal
LongStream iterator. |
LongStream |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
LongStream |
map(LongUnaryOperator mapper)
Returns an
LongStream consisting of the results of applying the given
function to the elements of this stream. |
DoubleStream |
mapToDouble(LongToDoubleFunction mapper)
Returns an
DoubleStream consisting of the results of applying the given
function to the elements of this stream. |
IntStream |
mapToInt(LongToIntFunction mapper)
Returns an
IntStream consisting of the results of applying the given
function to the elements of this stream. |
<R> Stream<R> |
mapToObj(LongFunction<? extends R> mapper)
Returns a
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 |
min()
Returns an
OptionalLong describing the minimum element of this
stream, or an empty optional if this stream is empty. |
boolean |
noneMatch(LongPredicate predicate)
Tests whether no elements match the given predicate.
|
static LongStream |
of(long... values)
Creates a
LongStream from the specified values. |
static LongStream |
of(long t)
Returns stream which contains single element passed as param
|
static LongStream |
of(PrimitiveIterator.OfLong iterator)
Creates a
LongStream from PrimitiveIterator.OfLong. |
LongStream |
peek(LongConsumer action)
Performs provided action on each element.
|
static LongStream |
range(long startInclusive,
long endExclusive)
Returns a sequential ordered
LongStream from startInclusive
(inclusive) to endExclusive (exclusive) by an incremental step of
1. |
static LongStream |
rangeClosed(long startInclusive,
long endInclusive)
Returns a sequential ordered
LongStream from startInclusive
(inclusive) to endInclusive (inclusive) by an incremental step of
1. |
OptionalLong |
reduce(LongBinaryOperator accumulator)
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 accumulator)
Performs a reduction on the elements of this stream, using the provided
identity value and an associative accumulation function, and returns the
reduced value.
|
LongStream |
sample(int stepWidth)
Samples the
LongStream by emitting every n-th element. |
long |
single()
Returns the single element of stream.
|
LongStream |
skip(long n)
Skips first
n elements and returns Stream with remaining elements. |
LongStream |
sorted()
Returns a stream consisting of the elements of this stream in sorted order.
|
LongStream |
sorted(Comparator<Long> comparator)
Returns a stream consisting of the elements of this stream
in sorted order as determinated by provided
Comparator. |
long |
sum()
Returns the sum of elements in this stream.
|
LongStream |
takeWhile(LongPredicate predicate)
Takes elements while the predicate is true.
|
long[] |
toArray()
Returns an array containing the elements of this stream.
|
public static LongStream empty()
public static LongStream of(PrimitiveIterator.OfLong iterator)
LongStream from PrimitiveIterator.OfLong.iterator - the iterator with elements to be passed to streamLongStreamNullPointerException - if iterator is nullpublic static LongStream of(long... values)
LongStream from the specified values.values - the elements of the new streamNullPointerException - if values is nullpublic static LongStream of(long t)
t - element of the streampublic static LongStream range(long startInclusive, long endExclusive)
LongStream from startInclusive
(inclusive) to endExclusive (exclusive) by an incremental step of
1.startInclusive - the (inclusive) initial valueendExclusive - the exclusive upper boundLongStream for the range of long
elementspublic static LongStream rangeClosed(long startInclusive, long endInclusive)
LongStream from startInclusive
(inclusive) to endInclusive (inclusive) by an incremental step of
1.startInclusive - the (inclusive) initial valueendInclusive - the inclusive upper boundLongStream for the range of long
elementspublic static LongStream generate(LongSupplier s)
LongStream by elements that generated by LongSupplier.s - the LongSupplier for generated elementsLongStreamNullPointerException - if s is nullpublic static LongStream iterate(long seed, LongUnaryOperator f)
LongStream by iterative application LongUnaryOperator function
to an initial element seed. Produces LongStream consisting of
seed, f(seed), f(f(seed)), etc.
The first element (position 0) in the LongStream 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.
Example:
seed: 1 f: (a) -> a + 5 result: [1, 6, 11, 16, ...]
seed - the initial elementf - a function to be applied to the previous element to produce a new elementLongStreamNullPointerException - if f is nullpublic static LongStream iterate(long seed, LongPredicate predicate, LongUnaryOperator op)
LongStream by iterative application LongUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate.
Example:
seed: 0 predicate: (a) -> a < 20 f: (a) -> a + 5 result: [0, 5, 10, 15]
seed - the initial valuepredicate - a predicate to determine when the stream must terminateop - operator to produce new element by previous oneNullPointerException - if op is nullpublic static LongStream concat(LongStream a, LongStream b)
Example:
stream a: [1, 2, 3, 4] stream b: [5, 6] result: [1, 2, 3, 4, 5, 6]
a - the first streamb - the second streamNullPointerException - if a or b is nullpublic PrimitiveIterator.OfLong iterator()
LongStream iterator.LongStream iterator.public <R> R custom(Function<LongStream,R> function)
LongStream for intermediate operations,
or any value for terminal operation.
Operator examples:
// Intermediate operator
public class Zip implements Function<LongStream, LongStream> {
private final LongStream secondStream;
private final LongBinaryOperator combiner;
public Zip(LongStream secondStream, LongBinaryOperator combiner) {
this.secondStream = secondStream;
this.combiner = combiner;
}
@Override
public LongStream apply(LongStream firstStream) {
final PrimitiveIterator.OfLong it1 = firstStream.iterator();
final PrimitiveIterator.OfLong it2 = secondStream.iterator();
return LongStream.of(new PrimitiveIterator.OfLong() {
@Override
public boolean hasNext() {
return it1.hasNext() && it2.hasNext();
}
@Override
public long nextLong() {
return combiner.applyAsLong(it1.nextLong(), it2.nextLong());
}
});
}
}
// Intermediate operator based on existing stream operators
public class SkipAndLimit implements UnaryOperator<LongStream> {
private final int skip, limit;
public SkipAndLimit(int skip, int limit) {
this.skip = skip;
this.limit = limit;
}
@Override
public LongStream apply(LongStream stream) {
return stream.skip(skip).limit(limit);
}
}
// Terminal operator
public class LongSummaryStatistics implements Function<LongStream, long[]> {
@Override
public long[] apply(LongStream stream) {
long count = 0;
long sum = 0;
final PrimitiveIterator.OfLong it = stream.iterator();
while (it.hasNext()) {
count++;
sum += it.nextLong();
}
return new long[] {count, sum};
}
}
R - the type of the resultfunction - a transforming functionNullPointerException - if function is nullStream.custom(com.annimon.stream.function.Function)public Stream<Long> boxed()
Stream consisting of the elements of this stream,
each boxed to an Long.
This is an lazy intermediate operation.
Stream consistent of the elements of this stream,
each boxed to an Longpublic LongStream filter(LongPredicate predicate)
LongStream with elements that satisfy the given predicate.
This is an intermediate operation.
Example:
predicate: (a) -> a > 2 stream: [1, 2, 3, 4, -8, 0, 11] result: [3, 4, 11]
predicate - the predicate used to filter elementspublic LongStream filterNot(LongPredicate predicate)
LongStream with elements that does not satisfy the given predicate.
This is an intermediate operation.
predicate - the predicate used to filter elementspublic LongStream map(LongUnaryOperator mapper)
LongStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
Example:
mapper: (a) -> a + 5 stream: [1, 2, 3, 4] result: [6, 7, 8, 9]
mapper - the mapper function used to apply to each elementStream.map(com.annimon.stream.function.Function)public <R> Stream<R> mapToObj(LongFunction<? extends R> mapper)
Stream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
R - the type resultmapper - the mapper function used to apply to each elementStreampublic IntStream mapToInt(LongToIntFunction mapper)
IntStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
mapper - the mapper function used to apply to each elementIntStreampublic DoubleStream mapToDouble(LongToDoubleFunction mapper)
DoubleStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
mapper - the mapper function used to apply to each elementDoubleStreampublic LongStream flatMap(LongFunction<? extends LongStream> mapper)
This is an intermediate operation.
Example:
mapper: (a) -> [a, a + 5] stream: [1, 2, 3, 4] result: [1, 6, 2, 7, 3, 8, 4, 9]
mapper - the mapper function used to apply to each elementStream.flatMap(com.annimon.stream.function.Function)public LongStream distinct()
This is a stateful intermediate operation.
Example:
stream: [1, 4, 2, 3, 3, 4, 1] result: [1, 4, 2, 3]
public LongStream sorted()
This is a stateful intermediate operation.
Example:
stream: [3, 4, 1, 2] result: [1, 2, 3, 4]
public LongStream sorted(Comparator<Long> comparator)
Comparator.
This is a stateful intermediate operation.
Example:
comparator: (a, b) -> -a.compareTo(b) stream: [1, 2, 3, 4] result: [4, 3, 2, 1]
comparator - the Comparator to compare elementsLongStreampublic LongStream sample(int stepWidth)
LongStream by emitting every n-th element.
This is an intermediate operation.
Example:
stepWidth: 3 stream: [1, 2, 3, 4, 5, 6, 7, 8] result: [1, 4, 7]
stepWidth - step widthLongStreamIllegalArgumentException - if stepWidth is zero or negativeStream.sample(int)public LongStream peek(LongConsumer action)
This is an intermediate operation.
action - the action to be performed on each elementpublic LongStream takeWhile(LongPredicate predicate)
This is an intermediate operation.
Example:
predicate: (a) -> a < 3 stream: [1, 2, 3, 4, 1, 2, 3, 4] result: [1, 2]
predicate - the predicate used to take elementsLongStreampublic LongStream dropWhile(LongPredicate predicate)
This is an intermediate operation.
Example:
predicate: (a) -> a < 3 stream: [1, 2, 3, 4, 1, 2, 3, 4] result: [3, 4, 1, 2, 3, 4]
predicate - the predicate used to drop elementsLongStreampublic LongStream limit(long maxSize)
maxSize in length.
This is a short-circuiting stateful intermediate operation.
Example:
maxSize: 3 stream: [1, 2, 3, 4, 5] result: [1, 2, 3] maxSize: 10 stream: [1, 2] result: [1, 2]
maxSize - the number of elements the stream should be limited toIllegalArgumentException - if maxSize is negativepublic LongStream skip(long n)
n elements and returns Stream with remaining elements.
If this stream contains fewer than n elements, then an
empty stream will be returned.
This is a stateful intermediate operation.
Example:
n: 3 stream: [1, 2, 3, 4, 5] result: [4, 5] n: 10 stream: [1, 2] result: []
n - the number of elements to skipIllegalArgumentException - if n is negativepublic void forEach(LongConsumer action)
This is a terminal operation.
action - the action to be performed on each elementpublic long reduce(long identity,
LongBinaryOperator accumulator)
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.
Example:
identity: 0 accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: 15
public OptionalLong reduce(LongBinaryOperator accumulator)
OptionalLong
describing the reduced value, if any.
The accumulator function must be an associative function.
This is a terminal operation.
accumulator - the accumulation functionreduce(com.annimon.stream.function.LongBinaryOperator)public long[] toArray()
This is a terminal operation.
public <R> R collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator)
supplier provided container by applying the given accumulation function.
This is a terminal operation.
R - the type of the resultsupplier - the supplier function that provides containeraccumulator - the accumulation functionStream.collect(com.annimon.stream.function.Supplier, com.annimon.stream.function.BiConsumer)public long sum()
public OptionalLong min()
OptionalLong describing the minimum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
public OptionalLong max()
OptionalLong describing the maximum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
public long count()
This is a terminal operation.
public boolean anyMatch(LongPredicate predicate)
false is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: true predicate: (a) -> a == 5 stream: [5, 5, 5] result: true
predicate - the predicate used to match elementstrue if any elements of the stream match the provided
predicate, otherwise falsepublic boolean allMatch(LongPredicate predicate)
true is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: false predicate: (a) -> a == 5 stream: [5, 5, 5] result: true
predicate - the predicate used to match elementstrue if either all elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic boolean noneMatch(LongPredicate predicate)
true is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: false predicate: (a) -> a == 5 stream: [1, 2, 3] result: true
predicate - the predicate used to match elementstrue if either no elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic OptionalLong findFirst()
OptionalLong class.
If stream is empty, returns OptionalLong.empty().
This is a short-circuiting terminal operation.
OptionalLong with first element
or OptionalLong.empty() if stream is emptypublic long single()
NoSuchElementException.
If stream contains more than one element, throws IllegalStateException.
This is a short-circuiting terminal operation.
Example:
stream: [] result: NoSuchElementException stream: [1] result: 1 stream: [1, 2, 3] result: IllegalStateException
NoSuchElementException - if stream is emptyIllegalStateException - if stream contains more than one elementpublic OptionalLong findSingle()
OptionalLong class.
If stream is empty, returns OptionalLong.empty().
If stream contains more than one element, throws IllegalStateException.
This is a short-circuiting terminal operation.
Example:
stream: [] result: OptionalLong.empty() stream: [1] result: OptionalLong.of(1) stream: [1, 2, 3] result: IllegalStateException
OptionalLong with single element
or OptionalLong.empty() if stream is emptyIllegalStateException - if stream contains more than one elementCopyright © 2017. All rights reserved.