Class LongStreamEx
- Object
-
- LongStreamEx
-
- All Implemented Interfaces:
AutoCloseable,BaseStream<Long,LongStream>,LongStream
public class LongStreamEx extends Object implements LongStream
ALongStreamimplementation with additional functionality- Author:
- Tagir Valeev
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLongStreamEx.LongEmitterA helper interface to build a new stream by emitting elements and creating new emitters in a chain.-
Nested classes/interfaces inherited from interface LongStream
LongStream.Builder
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallMatch(LongPredicate predicate)booleananyMatch(LongPredicate predicate)LongStreamExappend(long... values)Returns a newLongStreamExwhich is a concatenation of this stream and the stream containing supplied valuesLongStreamExappend(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.DoubleStreamExasDoubleStream()LongStreamExatLeast(long value)Returns a stream consisting of the elements of this stream that greater than or equal to the specified value.LongStreamExatMost(long value)Returns a stream consisting of the elements of this stream that less than or equal to the specified value.OptionalDoubleaverage()StreamEx<Long>boxed()<U> Uchain(Function<? super LongStreamEx,U> mapper)Applies the supplied function to this stream and returns the result of the function.voidclose()<R> Rcollect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R,R> combiner)<A,R>
Rcollect(LongCollector<A,R> collector)Performs a mutable reduction operation on the elements of this stream using anLongCollectorwhich encapsulates the supplier, accumulator and merger functions making easier to reuse collection strategies.static LongStreamExconstant(long value, long length)Returns a sequential unorderedLongStreamExof given length which elements are equal to supplied value.longcount()LongStreamExdistinct()LongStreamExdropWhile(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 LongStreamExempty()Returns an empty sequentialLongStreamEx.LongStreamExfilter(LongPredicate predicate)OptionalLongfindAny()OptionalLongfindAny(LongPredicate predicate)Returns anOptionalLongdescribing some element of the stream, which matches given predicate, or an emptyOptionalLongif there's no matching element.OptionalLongfindFirst()OptionalLongfindFirst(LongPredicate predicate)Returns anOptionalLongdescribing the first element of this stream, which matches given predicate, or an emptyOptionalLongif there's no matching element.LongStreamExflatMap(LongFunction<? extends LongStream> mapper)DoubleStreamExflatMapToDouble(LongFunction<? extends DoubleStream> mapper)Returns aDoubleStreamExconsisting 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.IntStreamExflatMapToInt(LongFunction<? extends IntStream> mapper)Returns anIntStreamExconsisting 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 aStreamExconsisting 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.longfoldLeft(long seed, LongBinaryOperator accumulator)Folds the elements of this stream using the provided seed object and accumulation function, going left to right.OptionalLongfoldLeft(LongBinaryOperator accumulator)Folds the elements of this stream using the provided accumulation function, going left to right.voidforEach(LongConsumer action)voidforEachOrdered(LongConsumer action)static LongStreamExgenerate(LongSupplier s)Returns an infinite sequential unordered stream where each element is generated by the providedLongSupplier.LongStreamExgreater(long value)Returns a stream consisting of the elements of this stream that strictly greater than the specified value.booleanhas(long value)Returns true if this stream contains the specified valueOptionalLongindexOf(long value)Returns anOptionalLongdescribing the zero-based index of the first element of this stream, which equals to the given value, or an emptyOptionalLongif there's no matching element.OptionalLongindexOf(LongPredicate predicate)Returns anOptionalLongdescribing the zero-based index of the first element of this stream, which matches given predicate, or an emptyOptionalLongif there's no matching element.LongStreamExintersperse(int delimiter)Returns a new stream containing all the elements of the original stream interspersed with given delimiter.booleanisParallel()static LongStreamExiterate(long seed, LongPredicate predicate, LongUnaryOperator f)Returns a sequential orderedLongStreamExproduced by iterative application of a function to an initial element, conditioned on satisfying the supplied predicate.static LongStreamExiterate(long seed, LongUnaryOperator f)Returns an infinite sequential orderedLongStreamExproduced by iterative application of a functionfto an initial elementseed, producing a stream consisting ofseed,f(seed),f(f(seed)), etc.PrimitiveIterator.OfLongiterator()Stringjoining(CharSequence delimiter)Returns aStringwhich is the concatenation of the results of callingString.valueOf(long)on each element of this stream, separated by the specified delimiter, in encounter order.Stringjoining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)Returns aStringwhich is the concatenation of the results of callingString.valueOf(long)on each element of this stream, separated by the specified delimiter, with the specified prefix and suffix in encounter order.LongStreamExless(long value)Returns a stream consisting of the elements of this stream that strictly less than the specified value.LongStreamExlimit(long maxSize)static LongStreamExlongs()Returns a sequential orderedLongStreamExfrom 0 (inclusive) toLong.MAX_VALUE(exclusive) by an incremental step of1.LongStreamExmap(LongUnaryOperator mapper)LongStreamExmapFirst(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.LongStreamExmapLast(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.DoubleStreamExmapToDouble(LongToDoubleFunction mapper)<K,V>
EntryStream<K,V>mapToEntry(LongFunction<? extends K> keyMapper, LongFunction<? extends V> valueMapper)Returns anEntryStreamconsisting of theMap.Entryobjects which keys and values are results of applying the given functions to the elements of this stream.IntStreamExmapToInt(LongToIntFunction mapper)<U> StreamEx<U>mapToObj(LongFunction<? extends U> mapper)OptionalLongmax()OptionalLongmax(Comparator<Long> comparator)Returns the maximum element of this stream according to the providedComparator.<V extends Comparable<? super V>>
OptionalLongmaxBy(LongFunction<V> keyExtractor)Returns the maximum element of this stream according to the provided key extractor function.OptionalLongmaxByDouble(LongToDoubleFunction keyExtractor)Returns the maximum element of this stream according to the provided key extractor function.OptionalLongmaxByInt(LongToIntFunction keyExtractor)Returns the maximum element of this stream according to the provided key extractor function.OptionalLongmaxByLong(LongUnaryOperator keyExtractor)Returns the maximum element of this stream according to the provided key extractor function.OptionalLongmin()OptionalLongmin(Comparator<Long> comparator)Returns the minimum element of this stream according to the providedComparator.<V extends Comparable<? super V>>
OptionalLongminBy(LongFunction<V> keyExtractor)Returns the minimum element of this stream according to the provided key extractor function.OptionalLongminByDouble(LongToDoubleFunction keyExtractor)Returns the minimum element of this stream according to the provided key extractor function.OptionalLongminByInt(LongToIntFunction keyExtractor)Returns the minimum element of this stream according to the provided key extractor function.OptionalLongminByLong(LongUnaryOperator keyExtractor)Returns the minimum element of this stream according to the provided key extractor function.booleannoneMatch(LongPredicate predicate)static LongStreamExof(long element)Returns a sequentialLongStreamExcontaining a single element.static LongStreamExof(long... elements)Returns a sequential orderedLongStreamExwhose elements are the specified values.static LongStreamExof(long[] array, int startInclusive, int endExclusive)Returns a sequentialLongStreamExwith the specified range of the specified array as its source.static LongStreamExof(Long[] array)Returns a sequential orderedLongStreamExwhose elements are the unboxed elements of supplied array.static LongStreamExof(LongBuffer buf)Returns a sequential orderedLongStreamExwhose elements are the values in the suppliedLongBuffer.static LongStreamExof(Collection<Long> collection)Returns a sequential orderedLongStreamExwhose elements are the unboxed elements of supplied collection.static LongStreamExof(OptionalLong optional)Returns a sequentialLongStreamExcontaining anOptionalLongvalue, if present, otherwise returns an emptyLongStreamEx.static LongStreamExof(PrimitiveIterator.OfLong iterator)Returns a sequential, orderedLongStreamExcreated from givenPrimitiveIterator.OfLong.static LongStreamExof(Random random)Returns an effectively unlimited stream of pseudorandomlongvalues produced by givenRandomobject.static LongStreamExof(Random random, long streamSize)Returns a stream producing the givenstreamSizenumber of pseudorandomlongvalues.static LongStreamExof(Random random, long randomNumberOrigin, long randomNumberBound)Returns an effectively unlimited stream of pseudorandomlongvalues, each conforming to the given origin (inclusive) and bound (exclusive).static LongStreamExof(Random random, long streamSize, long randomNumberOrigin, long randomNumberBound)Returns a stream producing the givenstreamSizenumber of pseudorandomlongvalues, each conforming to the given origin (inclusive) and bound (exclusive).static LongStreamExof(Spliterator.OfLong spliterator)Returns a sequentialLongStreamExcreated from givenSpliterator.OfLong.static LongStreamExof(LongStream stream)Returns aLongStreamExobject which wraps givenLongStream.LongStreamExonClose(Runnable closeHandler)LongStreamExpairMap(LongBinaryOperator mapper)Returns a stream consisting of the results of applying the given function to the every adjacent pair of elements of this stream.LongStreamExparallel()LongStreamExparallel(ForkJoinPool fjp)Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool.LongStreamExpeek(LongConsumer action)LongStreamExpeekFirst(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.LongStreamExpeekLast(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.LongStreamExprefix(LongBinaryOperator op)Returns a stream containing cumulative results of applying the accumulation function going left to right.LongStreamExprepend(long... values)Returns a newLongStreamExwhich is a concatenation of the stream containing supplied values and this streamLongStreamExprepend(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 LongStreamExproduce(Predicate<LongConsumer> producer)Return an ordered stream produced by consecutive calls of the supplied producer until it returns false.static LongStreamExrange(long endExclusive)Returns a sequential orderedLongStreamExfrom 0 (inclusive) toendExclusive(exclusive) by an incremental step of1.static LongStreamExrange(long startInclusive, long endExclusive)Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendExclusive(exclusive) by an incremental step of1.static LongStreamExrange(long startInclusive, long endExclusive, long step)Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendExclusive(exclusive) by the specified incremental step.static LongStreamExrangeClosed(long startInclusive, long endInclusive)Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendInclusive(inclusive) by an incremental step of1.static LongStreamExrangeClosed(long startInclusive, long endInclusive, long step)Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendInclusive(inclusive) by the specified incremental step.longreduce(long identity, LongBinaryOperator op)OptionalLongreduce(LongBinaryOperator op)LongStreamExremove(LongPredicate predicate)Returns a stream consisting of the elements of this stream that don't match the given predicate.LongStreamExreverseSorted()Returns a stream consisting of the elements of this stream in reverse sorted order.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.long[]scanLeft(LongBinaryOperator accumulator)Produces an array containing cumulative results of applying the accumulation function going left to right.LongStreamExsequential()LongStreamExskip(long n)LongStreamExsorted()LongStreamExsorted(Comparator<Long> comparator)Returns a stream consisting of the elements of this stream sorted according to the given comparator.<V extends Comparable<? super V>>
LongStreamExsortedBy(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.LongStreamExsortedByDouble(LongToDoubleFunction keyExtractor)Returns a stream consisting of the elements of this stream, sorted according to the double values extracted by provided function.LongStreamExsortedByInt(LongToIntFunction keyExtractor)Returns a stream consisting of the elements of this stream, sorted according to the int values extracted by provided function.LongStreamExsortedByLong(LongUnaryOperator keyExtractor)Returns a stream consisting of the elements of this stream, sorted according to the long values extracted by provided function.SPLTRspliterator()longsum()LongSummaryStatisticssummaryStatistics()LongStreamExtakeWhile(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.LongStreamExtakeWhileInclusive(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()LongStreamExunordered()LongStreamExwithout(long value)Returns a stream consisting of the elements of this stream that don't equal to the given value.LongStreamExwithout(long... values)Returns a stream consisting of the elements of this stream that don't equal to any of the supplied values.static LongStreamExzip(long[] first, long[] second, LongBinaryOperator mapper)Returns a sequentialLongStreamExcontaining the results of applying the given function to the corresponding pairs of values in given two arrays.-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface BaseStream
close, isParallel
-
Methods inherited from interface LongStream
spliterator
-
-
-
-
Method Detail
-
unordered
public LongStreamEx unordered()
- Specified by:
unorderedin interfaceBaseStream<Long,LongStream>
-
onClose
public LongStreamEx onClose(Runnable closeHandler)
- Specified by:
onClosein interfaceBaseStream<Long,LongStream>
-
filter
public LongStreamEx filter(LongPredicate predicate)
- Specified by:
filterin interfaceLongStream
-
remove
public LongStreamEx remove(LongPredicate predicate)
Returns a stream consisting of the elements of this stream that don't match the given predicate.This is an intermediate operation.
- Parameters:
predicate- a non-interfering, stateless predicate to apply to each element to determine if it should be excluded- Returns:
- the new stream
-
has
public boolean has(long value)
Returns true if this stream contains the specified valueThis is a short-circuiting terminal operation.
- Parameters:
value- the value too look for in the stream- Returns:
- true if this stream contains the specified value
- See Also:
LongStream.anyMatch(LongPredicate)
-
without
public LongStreamEx without(long value)
Returns a stream consisting of the elements of this stream that don't equal to the given value.This is an intermediate operation.
- Parameters:
value- the value to remove from the stream.- Returns:
- the new stream
- Since:
- 0.2.2
- See Also:
without(long...),remove(LongPredicate)
-
without
public LongStreamEx without(long... values)
Returns a stream consisting of the elements of this stream that don't equal to any of the supplied 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
valuesarray 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.- Parameters:
values- the values to remove from the stream.- Returns:
- the new stream
- Since:
- 0.5.5
- See Also:
without(long),remove(LongPredicate)
-
greater
public LongStreamEx greater(long value)
Returns a stream consisting of the elements of this stream that strictly greater than the specified value.This is an intermediate operation.
- Parameters:
value- a value to compare to- Returns:
- the new stream
- Since:
- 0.2.3
-
atLeast
public LongStreamEx atLeast(long value)
Returns a stream consisting of the elements of this stream that greater than or equal to the specified value.This is an intermediate operation.
- Parameters:
value- a value to compare to- Returns:
- the new stream
- Since:
- 0.2.3
-
less
public LongStreamEx less(long value)
Returns a stream consisting of the elements of this stream that strictly less than the specified value.This is an intermediate operation.
- Parameters:
value- a value to compare to- Returns:
- the new stream
- Since:
- 0.2.3
-
atMost
public LongStreamEx atMost(long value)
Returns a stream consisting of the elements of this stream that less than or equal to the specified value.This is an intermediate operation.
- Parameters:
value- a value to compare to- Returns:
- the new stream
- Since:
- 0.2.3
-
map
public LongStreamEx map(LongUnaryOperator mapper)
- Specified by:
mapin interfaceLongStream
-
mapFirst
public 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.This is a quasi-intermediate operation.
- Parameters:
mapper- a non-interfering , stateless function to apply to the first element- Returns:
- the new stream
- Since:
- 0.4.1
-
mapLast
public 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.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.
- Parameters:
mapper- a non-interfering , stateless function to apply to the last element- Returns:
- the new stream
- Since:
- 0.4.1
-
mapToObj
public <U> StreamEx<U> mapToObj(LongFunction<? extends U> mapper)
- Specified by:
mapToObjin interfaceLongStream
-
mapToInt
public IntStreamEx mapToInt(LongToIntFunction mapper)
- Specified by:
mapToIntin interfaceLongStream
-
mapToDouble
public DoubleStreamEx mapToDouble(LongToDoubleFunction mapper)
- Specified by:
mapToDoublein interfaceLongStream
-
mapToEntry
public <K,V> EntryStream<K,V> mapToEntry(LongFunction<? extends K> keyMapper, LongFunction<? extends V> valueMapper)
Returns anEntryStreamconsisting of theMap.Entryobjects which keys and values are results of applying the given functions to the elements of this stream.This is an intermediate operation.
- Type Parameters:
K- TheEntrykey typeV- TheEntryvalue type- Parameters:
keyMapper- a non-interfering, stateless function to apply to each elementvalueMapper- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
- Since:
- 0.3.1
-
flatMap
public LongStreamEx flatMap(LongFunction<? extends LongStream> mapper)
- Specified by:
flatMapin interfaceLongStream
-
flatMapToInt
public IntStreamEx flatMapToInt(LongFunction<? extends IntStream> mapper)
Returns anIntStreamExconsisting 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 isnullan empty stream is used, instead.)This is an intermediate operation.
- Parameters:
mapper- a non-interfering, stateless function to apply to each element which produces anIntStreamof new values- Returns:
- the new stream
- Since:
- 0.3.0
-
flatMapToDouble
public DoubleStreamEx flatMapToDouble(LongFunction<? extends DoubleStream> mapper)
Returns aDoubleStreamExconsisting 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 isnullan empty stream is used, instead.)This is an intermediate operation.
- Parameters:
mapper- a non-interfering, stateless function to apply to each element which produces anDoubleStreamof new values- Returns:
- the new stream
- Since:
- 0.3.0
-
flatMapToObj
public <R> StreamEx<R> flatMapToObj(LongFunction<? extends Stream<R>> mapper)
Returns aStreamExconsisting 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 isnullan empty stream is used, instead.)This is an intermediate operation.
- Type Parameters:
R- The element type of the new stream- Parameters:
mapper- a non-interfering, stateless function to apply to each element which produces aStreamof new values- Returns:
- the new stream
- Since:
- 0.3.0
-
intersperse
public LongStreamEx intersperse(int delimiter)
Returns a new stream containing all the elements of the original stream interspersed with given delimiter.For example,
LongStreamEx.of(1, 2, 3).intersperse(4)will yield a stream containing five elements: 1, 4, 2, 4, 3.This is an intermediate operation.
- Parameters:
delimiter- a delimiter to be inserted between each pair of elements- Returns:
- the new stream
- Since:
- 0.6.6
-
distinct
public LongStreamEx distinct()
- Specified by:
distinctin interfaceLongStream
-
sorted
public LongStreamEx sorted()
- Specified by:
sortedin interfaceLongStream
-
sorted
public LongStreamEx sorted(Comparator<Long> comparator)
Returns a stream consisting of the elements of this stream sorted according to the given comparator. Stream elements are boxed before passing to the comparator.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
comparator- a non-interfering , statelessComparatorto be used to compare stream elements- Returns:
- the new stream
-
reverseSorted
public LongStreamEx reverseSorted()
Returns a stream consisting of the elements of this stream in reverse sorted order.This is a stateful intermediate operation.
- Returns:
- the new stream
- Since:
- 0.0.8
-
sortedBy
public <V extends Comparable<? super V>> LongStreamEx 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.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Type Parameters:
V- the type of theComparablesort key- Parameters:
keyExtractor- a non-interfering , stateless function to be used to extract sorting keys- Returns:
- the new stream
-
sortedByInt
public LongStreamEx sortedByInt(LongToIntFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the int values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
keyExtractor- a non-interfering , stateless function to be used to extract sorting keys- Returns:
- the new stream
-
sortedByLong
public LongStreamEx sortedByLong(LongUnaryOperator keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the long values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
keyExtractor- a non-interfering , stateless function to be used to extract sorting keys- Returns:
- the new stream
-
sortedByDouble
public LongStreamEx sortedByDouble(LongToDoubleFunction keyExtractor)
Returns a stream consisting of the elements of this stream, sorted according to the double values extracted by provided function.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
keyExtractor- a non-interfering , stateless function to be used to extract sorting keys- Returns:
- the new stream
-
peek
public LongStreamEx peek(LongConsumer action)
- Specified by:
peekin interfaceLongStream
-
peekFirst
public 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.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.
- Parameters:
action- a non-interfering action to perform on the first stream element as it is consumed from the stream- Returns:
- the new stream
- Since:
- 0.6.0
-
peekLast
public 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.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.
- Parameters:
action- a non-interfering action to perform on the first stream element as it is consumed from the stream- Returns:
- the new stream
- Since:
- 0.6.0
-
limit
public LongStreamEx limit(long maxSize)
- Specified by:
limitin interfaceLongStream
-
skip
public LongStreamEx skip(long n)
- Specified by:
skipin interfaceLongStream
-
forEach
public void forEach(LongConsumer action)
- Specified by:
forEachin interfaceLongStream
-
forEachOrdered
public void forEachOrdered(LongConsumer action)
- Specified by:
forEachOrderedin interfaceLongStream
-
toArray
public long[] toArray()
- Specified by:
toArrayin interfaceLongStream
-
reduce
public long reduce(long identity, LongBinaryOperator op)- Specified by:
reducein interfaceLongStream
-
reduce
public OptionalLong reduce(LongBinaryOperator op)
- Specified by:
reducein interfaceLongStream
-
foldLeft
public OptionalLong foldLeft(LongBinaryOperator accumulator)
Folds the elements of this stream using the provided accumulation function, going left to right. This is equivalent to: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.
- Parameters:
accumulator- a non-interfering , stateless function for incorporating an additional element into a result- Returns:
- the result of the folding
- Since:
- 0.4.0
- See Also:
foldLeft(long, LongBinaryOperator),reduce(LongBinaryOperator)
-
foldLeft
public long foldLeft(long seed, LongBinaryOperator accumulator)Folds the elements of this stream using the provided seed object and accumulation function, going left to right. This is equivalent to: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.
- Parameters:
seed- the starting valueaccumulator- a non-interfering , stateless function for incorporating an additional element into a result- Returns:
- the result of the folding
- Since:
- 0.4.0
- See Also:
reduce(long, LongBinaryOperator),foldLeft(LongBinaryOperator)
-
scanLeft
public long[] scanLeft(LongBinaryOperator accumulator)
Produces an array containing cumulative results of applying the accumulation function going left to right.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.
- Parameters:
accumulator- a non-interfering , stateless function for incorporating an additional element into a result- Returns:
- the array where the first element is the first element of this stream and every successor element is the result of applying accumulator function to the previous array element and the corresponding stream element. The resulting array has the same length as this stream.
- Since:
- 0.5.1
- See Also:
foldLeft(LongBinaryOperator)
-
scanLeft
public 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.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.
- Parameters:
seed- the starting valueaccumulator- a non-interfering , stateless function for incorporating an additional element into a result- Returns:
- the array where the first element is the seed and every successor element is the result of applying accumulator function to the previous array element and the corresponding stream element. The resulting array is one element longer than this stream.
- Since:
- 0.5.1
- See Also:
foldLeft(long, LongBinaryOperator)
-
collect
public <R> R collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R,R> combiner)
- Specified by:
collectin interfaceLongStream- See Also:
collect(LongCollector)
-
collect
public <A,R> R collect(LongCollector<A,R> collector)
Performs a mutable reduction operation on the elements of this stream using anLongCollectorwhich encapsulates the supplier, accumulator and merger functions making easier to reuse collection strategies.Like
reduce(long, LongBinaryOperator),collectoperations can be parallelized without requiring additional synchronization.This is a terminal operation.
- Type Parameters:
A- the intermediate accumulation type of theLongCollectorR- type of the result- Parameters:
collector- theLongCollectordescribing the reduction- Returns:
- the result of the reduction
- Since:
- 0.3.0
- See Also:
collect(Supplier, ObjLongConsumer, BiConsumer)
-
sum
public long sum()
- Specified by:
sumin interfaceLongStream
-
min
public OptionalLong min()
- Specified by:
minin interfaceLongStream
-
min
public OptionalLong min(Comparator<Long> comparator)
Returns the minimum element of this stream according to the providedComparator.This is a terminal operation.
- Parameters:
comparator- a non-interfering, statelessComparatorto compare elements of this stream- Returns:
- an
OptionalLongdescribing the minimum element of this stream, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
minBy
public <V extends Comparable<? super V>> OptionalLong minBy(LongFunction<V> keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
- Type Parameters:
V- the type of theComparablesort key- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
minByInt
public OptionalLong minByInt(LongToIntFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
minByLong
public OptionalLong minByLong(LongUnaryOperator keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
minByDouble
public OptionalLong minByDouble(LongToDoubleFunction keyExtractor)
Returns the minimum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the lowest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
max
public OptionalLong max()
- Specified by:
maxin interfaceLongStream
-
max
public OptionalLong max(Comparator<Long> comparator)
Returns the maximum element of this stream according to the providedComparator.This is a terminal operation.
- Parameters:
comparator- a non-interfering, statelessComparatorto compare elements of this stream- Returns:
- an
OptionalLongdescribing the maximum element of this stream, or an emptyOptionalLongif the stream is empty
-
maxBy
public <V extends Comparable<? super V>> OptionalLong maxBy(LongFunction<V> keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
- Type Parameters:
V- the type of theComparablesort key- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
maxByInt
public OptionalLong maxByInt(LongToIntFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
maxByLong
public OptionalLong maxByLong(LongUnaryOperator keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
maxByDouble
public OptionalLong maxByDouble(LongToDoubleFunction keyExtractor)
Returns the maximum element of this stream according to the provided key extractor function.This is a terminal operation.
- Parameters:
keyExtractor- a non-interfering, stateless function- Returns:
- an
OptionalLongdescribing the first element of this stream for which the highest value was returned by key extractor, or an emptyOptionalLongif the stream is empty - Since:
- 0.1.2
-
count
public long count()
- Specified by:
countin interfaceLongStream
-
average
public OptionalDouble average()
- Specified by:
averagein interfaceLongStream
-
summaryStatistics
public LongSummaryStatistics summaryStatistics()
- Specified by:
summaryStatisticsin interfaceLongStream
-
anyMatch
public boolean anyMatch(LongPredicate predicate)
- Specified by:
anyMatchin interfaceLongStream
-
allMatch
public boolean allMatch(LongPredicate predicate)
- Specified by:
allMatchin interfaceLongStream
-
noneMatch
public boolean noneMatch(LongPredicate predicate)
- Specified by:
noneMatchin interfaceLongStream
-
findFirst
public OptionalLong findFirst()
- Specified by:
findFirstin interfaceLongStream
-
findFirst
public OptionalLong findFirst(LongPredicate predicate)
Returns anOptionalLongdescribing the first element of this stream, which matches given predicate, or an emptyOptionalLongif there's no matching element.This is a short-circuiting terminal operation.
- Parameters:
predicate- a non-interfering , stateless predicate which returned value should match- Returns:
- an
OptionalLongdescribing the first matching element of this stream, or an emptyOptionalLongif there's no matching element - See Also:
findFirst()
-
findAny
public OptionalLong findAny()
- Specified by:
findAnyin interfaceLongStream
-
findAny
public OptionalLong findAny(LongPredicate predicate)
Returns anOptionalLongdescribing some element of the stream, which matches given predicate, or an emptyOptionalLongif 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.)- Parameters:
predicate- a non-interfering , stateless predicate which returned value should match- Returns:
- an
OptionalLongdescribing some matching element of this stream, or an emptyOptionalLongif there's no matching element - See Also:
findAny(),findFirst(LongPredicate)
-
indexOf
public OptionalLong indexOf(long value)
Returns anOptionalLongdescribing the zero-based index of the first element of this stream, which equals to the given value, or an emptyOptionalLongif there's no matching element.This is a short-circuiting terminal operation.
- Parameters:
value- a value to look for- Returns:
- an
OptionalLongdescribing the index of the first matching element of this stream, or an emptyOptionalLongif there's no matching element. - Since:
- 0.4.0
- See Also:
indexOf(LongPredicate)
-
indexOf
public OptionalLong indexOf(LongPredicate predicate)
Returns anOptionalLongdescribing the zero-based index of the first element of this stream, which matches given predicate, or an emptyOptionalLongif there's no matching element.This is a short-circuiting terminal operation.
- Parameters:
predicate- a non-interfering , stateless predicate which returned value should match- Returns:
- an
OptionalLongdescribing the index of the first matching element of this stream, or an emptyOptionalLongif there's no matching element. - Since:
- 0.4.0
- See Also:
findFirst(LongPredicate)
-
asDoubleStream
public DoubleStreamEx asDoubleStream()
- Specified by:
asDoubleStreamin interfaceLongStream
-
boxed
public StreamEx<Long> boxed()
- Specified by:
boxedin interfaceLongStream
-
sequential
public LongStreamEx sequential()
- Specified by:
sequentialin interfaceBaseStream<Long,LongStream>- Specified by:
sequentialin interfaceLongStream
-
parallel
public LongStreamEx parallel()
If this stream was created using
parallel(ForkJoinPool), the new stream forgets about supplied customForkJoinPooland its terminal operation will be executed in common pool.- Specified by:
parallelin interfaceBaseStream<Long,LongStream>- Specified by:
parallelin interfaceLongStream
-
parallel
public LongStreamEx parallel(ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool.This is an intermediate operation.
The terminal operation of this stream or any derived stream (except the streams created via
BaseStream.parallel()orBaseStream.sequential()methods) will be executed inside the suppliedForkJoinPool. If current thread does not belong to that pool, it will wait till calculation finishes.- Parameters:
fjp- aForkJoinPoolto submit the stream operation to.- Returns:
- a parallel stream bound to the supplied
ForkJoinPool
-
iterator
public PrimitiveIterator.OfLong iterator()
- Specified by:
iteratorin interfaceBaseStream<Long,LongStream>- Specified by:
iteratorin interfaceLongStream
-
append
public LongStreamEx append(long... values)
Returns a newLongStreamExwhich is a concatenation of this stream and the stream containing supplied valuesThis is a quasi-intermediate operation.
- Parameters:
values- the values to append to the stream- Returns:
- the new stream
-
append
public 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. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers for both input streams are invoked.- Parameters:
other- the other stream- Returns:
- this stream appended by the other stream
- See Also:
LongStream.concat(LongStream, LongStream)
-
prepend
public LongStreamEx prepend(long... values)
Returns a newLongStreamExwhich is a concatenation of the stream containing supplied values and this streamThis is a quasi-intermediate operation.
- Parameters:
values- the values to prepend to the stream- Returns:
- the new stream
-
prepend
public 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. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers for both input streams are invoked.- Parameters:
other- the other stream- Returns:
- this stream prepended by the other stream
- See Also:
LongStream.concat(LongStream, LongStream)
-
pairMap
public 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.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.
- Parameters:
mapper- a non-interfering, stateless function to apply to each adjacent pair of this stream elements.- Returns:
- the new stream
- Since:
- 0.2.1
-
joining
public String joining(CharSequence delimiter)
Returns aStringwhich is the concatenation of the results of callingString.valueOf(long)on each element of this stream, separated by the specified delimiter, in encounter order.This is a terminal operation.
- Parameters:
delimiter- the delimiter to be used between each element- Returns:
- the result of concatenation. For empty input stream empty String is returned.
- Since:
- 0.3.1
-
joining
public String joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Returns aStringwhich is the concatenation of the results of callingString.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.
- Parameters:
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 result- Returns:
- the result of concatenation. For empty input stream
prefix + suffixis returned. - Since:
- 0.3.1
-
takeWhile
public 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.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.
- Specified by:
takeWhilein interfaceLongStream- Parameters:
predicate- a non-interfering, stateless predicate to apply to elements.- Returns:
- the new stream.
- Since:
- 0.3.6
- See Also:
takeWhileInclusive(LongPredicate),dropWhile(LongPredicate)
-
takeWhileInclusive
public 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).This is a quasi-intermediate operation.
While this operation is quite cheap for sequential stream, it can be quite expensive on parallel pipelines.
- Parameters:
predicate- a non-interfering, stateless predicate to apply to elements.- Returns:
- the new stream.
- Since:
- 0.5.5
- See Also:
takeWhile(LongPredicate)
-
dropWhile
public 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. If the predicate is true for all stream elements, an empty stream is returned.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.
- Specified by:
dropWhilein interfaceLongStream- Parameters:
predicate- a non-interfering, stateless predicate to apply to elements.- Returns:
- the new stream.
- Since:
- 0.3.6
-
prefix
public LongStreamEx prefix(LongBinaryOperator op)
Returns a stream containing cumulative results of applying the accumulation function going left to right.This is a stateful quasi-intermediate operation.
This operation resembles
scanLeft(LongBinaryOperator), but unlikescanLeftthis 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.- Parameters:
op- an associative , non-interfering , stateless function for computing the next element based on the previous one- Returns:
- the new stream.
- Since:
- 0.6.1
- See Also:
scanLeft(LongBinaryOperator)
-
chain
public <U> U chain(Function<? super LongStreamEx,U> mapper)
Applies the supplied function to this stream and returns the result of the function.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 writebatches(StreamEx.of(input).map(...), 10).filter(...). Using thechain()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(...).- Type Parameters:
U- the type of the function result.- Parameters:
mapper- function to invoke.- Returns:
- the result of the function invocation.
-
empty
public static LongStreamEx empty()
Returns an empty sequentialLongStreamEx.- Returns:
- an empty sequential stream
-
of
public static LongStreamEx of(long element)
Returns a sequentialLongStreamExcontaining a single element.- Parameters:
element- the single element- Returns:
- a singleton sequential stream
-
of
public static LongStreamEx of(long... elements)
Returns a sequential orderedLongStreamExwhose elements are the specified values.- Parameters:
elements- the elements of the new stream- Returns:
- the new stream
-
of
public static LongStreamEx of(long[] array, int startInclusive, int endExclusive)
Returns a sequentialLongStreamExwith the specified range of the specified array as its source.- Parameters:
array- the array, assumed to be unmodified during usestartInclusive- the first index to cover, inclusiveendExclusive- index immediately past the last index to cover- Returns:
- an
LongStreamExfor the array range - Throws:
ArrayIndexOutOfBoundsException- ifstartInclusiveis negative,endExclusiveis less thanstartInclusive, orendExclusiveis greater than the array size- Since:
- 0.1.1
- See Also:
Arrays.stream(long[], int, int)
-
of
public static LongStreamEx of(Long[] array)
Returns a sequential orderedLongStreamExwhose elements are the unboxed elements of supplied array.- Parameters:
array- the array to create the stream from.- Returns:
- the new stream
- Since:
- 0.5.0
- See Also:
Arrays.stream(Object[])
-
of
public static LongStreamEx of(LongBuffer buf)
Returns a sequential orderedLongStreamExwhose elements are the values in the suppliedLongBuffer.The resulting stream covers only a portion of
LongBuffercontent 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
LongBufferstate.- Parameters:
buf- theLongBufferto create a stream from- Returns:
- the new stream
- Since:
- 0.6.2
-
of
public static LongStreamEx of(LongStream stream)
Returns aLongStreamExobject which wraps givenLongStream.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.
- Parameters:
stream- original stream- Returns:
- the wrapped stream
- Since:
- 0.0.8
-
of
public static LongStreamEx of(Spliterator.OfLong spliterator)
Returns a sequentialLongStreamExcreated from givenSpliterator.OfLong.- Parameters:
spliterator- a spliterator to create the stream from.- Returns:
- the new stream
- Since:
- 0.3.4
-
of
public static LongStreamEx of(PrimitiveIterator.OfLong iterator)
Returns a sequential, orderedLongStreamExcreated from givenPrimitiveIterator.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.
- Parameters:
iterator- an iterator to create the stream from.- Returns:
- the new stream
- Since:
- 0.5.1
-
of
public static LongStreamEx of(OptionalLong optional)
Returns a sequentialLongStreamExcontaining anOptionalLongvalue, if present, otherwise returns an emptyLongStreamEx.- Parameters:
optional- the optional to create a stream of- Returns:
- a stream with an
OptionalLongvalue if present, otherwise an empty stream - Since:
- 0.1.1
-
of
public static LongStreamEx of(Collection<Long> collection)
Returns a sequential orderedLongStreamExwhose elements are the unboxed elements of supplied collection.- Parameters:
collection- the collection to create the stream from.- Returns:
- the new stream
- See Also:
Collection.stream()
-
of
public static LongStreamEx of(Random random)
Returns an effectively unlimited stream of pseudorandomlongvalues produced by givenRandomobject.A pseudorandom
longvalue is generated as if it's the result of calling the methodRandom.nextLong().- Parameters:
random- aRandomobject to produce the stream from- Returns:
- a stream of pseudorandom
longvalues - See Also:
Random.longs()
-
of
public static LongStreamEx of(Random random, long streamSize)
Returns a stream producing the givenstreamSizenumber of pseudorandomlongvalues.A pseudorandom
longvalue is generated as if it's the result of calling the methodRandom.nextLong()- Parameters:
random- aRandomobject to produce the stream fromstreamSize- the number of values to generate- Returns:
- a stream of pseudorandom
longvalues - See Also:
Random.longs(long)
-
of
public static LongStreamEx of(Random random, long randomNumberOrigin, long randomNumberBound)
Returns an effectively unlimited stream of pseudorandomlongvalues, each conforming to the given origin (inclusive) and bound (exclusive).- Parameters:
random- aRandomobject to produce the stream fromrandomNumberOrigin- the origin (inclusive) of each random valuerandomNumberBound- the bound (exclusive) of each random value- Returns:
- a stream of pseudorandom
longvalues - See Also:
Random.longs(long, long, long)
-
of
public static LongStreamEx of(Random random, long streamSize, long randomNumberOrigin, long randomNumberBound)
Returns a stream producing the givenstreamSizenumber of pseudorandomlongvalues, each conforming to the given origin (inclusive) and bound (exclusive).- Parameters:
random- aRandomobject to produce the stream fromstreamSize- the number of values to generaterandomNumberOrigin- the origin (inclusive) of each random valuerandomNumberBound- the bound (exclusive) of each random value- Returns:
- a stream of pseudorandom
longvalues - See Also:
Random.longs(long, long, long)
-
iterate
public static LongStreamEx iterate(long seed, LongUnaryOperator f)
Returns an infinite sequential orderedLongStreamExproduced by iterative application of a functionfto an initial elementseed, producing a stream consisting ofseed,f(seed),f(f(seed)), etc.The first element (position
0) in theLongStreamExwill be the providedseed. Forn > 0, the element at positionn, will be the result of applying the functionfto the element at positionn - 1.- Parameters:
seed- the initial elementf- a function to be applied to to the previous element to produce a new element- Returns:
- A new sequential
LongStream - See Also:
iterate(long, LongPredicate, LongUnaryOperator)
-
iterate
public static LongStreamEx iterate(long seed, LongPredicate predicate, LongUnaryOperator f)
Returns a sequential orderedLongStreamExproduced 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.iterateshould 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.
- Parameters:
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 element- Returns:
- a new sequential
LongStreamEx - Since:
- 0.6.0
- See Also:
iterate(long, LongUnaryOperator)
-
generate
public static LongStreamEx generate(LongSupplier s)
Returns an infinite sequential unordered stream where each element is generated by the providedLongSupplier. This is suitable for generating constant streams, streams of random elements, etc.- Parameters:
s- theLongSupplierfor generated elements- Returns:
- a new infinite sequential unordered
LongStreamEx - See Also:
LongStream.generate(LongSupplier)
-
produce
public static LongStreamEx produce(Predicate<LongConsumer> producer)
Return an ordered stream produced by consecutive calls of the supplied producer until it returns false.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.
- Parameters:
producer- a predicate which calls the passed consumer to emit stream element(s) and returns true if it producer should be applied again.- Returns:
- the new stream
- Since:
- 0.6.0
-
longs
public static LongStreamEx longs()
Returns a sequential orderedLongStreamExfrom 0 (inclusive) toLong.MAX_VALUE(exclusive) by an incremental step of1.- Returns:
- a sequential
LongStreamExfor the range oflongelements - Since:
- 0.5.5
- See Also:
range(long, long)
-
range
public static LongStreamEx range(long endExclusive)
Returns a sequential orderedLongStreamExfrom 0 (inclusive) toendExclusive(exclusive) by an incremental step of1.- Parameters:
endExclusive- the exclusive upper bound- Returns:
- a sequential
LongStreamExfor the range ofintelements - Since:
- 0.1.1
- See Also:
range(long, long)
-
range
public static LongStreamEx range(long startInclusive, long endExclusive)
Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendExclusive(exclusive) by an incremental step of1.- Parameters:
startInclusive- the (inclusive) initial valueendExclusive- the exclusive upper bound- Returns:
- a sequential
LongStreamExfor the range oflongelements - See Also:
LongStream.range(long, long)
-
range
public static LongStreamEx range(long startInclusive, long endExclusive, long step)
Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendExclusive(exclusive) by the specified incremental step. The negative step values are also supported. In this case, thestartInclusiveshould be greater thanendExclusive.- Parameters:
startInclusive- the (inclusive) initial valueendExclusive- the exclusive upper (for positive step) or lower (for negative step) boundstep- the non-zero value which designates the difference between the consecutive values of the resulting stream.- Returns:
- a sequential
LongStreamExfor the range oflongelements - Throws:
IllegalArgumentException- if step is zero- Since:
- 0.4.0
- See Also:
range(long, long)
-
rangeClosed
public static LongStreamEx rangeClosed(long startInclusive, long endInclusive)
Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendInclusive(inclusive) by an incremental step of1.- Parameters:
startInclusive- the (inclusive) initial valueendInclusive- the inclusive upper bound- Returns:
- a sequential
LongStreamExfor the range oflongelements - See Also:
LongStream.rangeClosed(long, long)
-
rangeClosed
public static LongStreamEx rangeClosed(long startInclusive, long endInclusive, long step)
Returns a sequential orderedLongStreamExfromstartInclusive(inclusive) toendInclusive(inclusive) by the specified incremental step. The negative step values are also supported. In this case, thestartInclusiveshould be not less thanendInclusive.Note that depending on the step value the
endInclusivebound may still not be reached. For exampleLongStreamEx.rangeClosed(0, 5, 2)will yield the stream of three numbers: 0L, 2L and 4L.- Parameters:
startInclusive- the (inclusive) initial valueendInclusive- the inclusive upper (for positive step) or lower (for negative step) boundstep- the non-zero value which designates the difference between the consecutive values of the resulting stream.- Returns:
- a sequential
LongStreamExfor the range oflongelements; an empty stream if startInclusive is greater than endInclusive for positive step, or if startInclusive is less than endInclusive for negative step. - Throws:
IllegalArgumentException- if step is zero- Since:
- 0.4.0
- See Also:
rangeClosed(long, long)
-
constant
public static LongStreamEx constant(long value, long length)
Returns a sequential unorderedLongStreamExof given length which elements are equal to supplied value.- Parameters:
value- the constant valuelength- the length of the stream- Returns:
- a new
LongStreamEx - Since:
- 0.1.2
-
zip
public static LongStreamEx zip(long[] first, long[] second, LongBinaryOperator mapper)
Returns a sequentialLongStreamExcontaining the results of applying the given function to the corresponding pairs of values in given two arrays.- Parameters:
first- the first arraysecond- the second arraymapper- a non-interfering, stateless function to apply to each pair of the corresponding array elements.- Returns:
- a new
LongStreamEx - Throws:
IllegalArgumentException- if length of the arrays differs.- Since:
- 0.2.1
-
spliterator
public SPLTR spliterator()
- Specified by:
spliteratorin interfaceBaseStream<T,S extends BaseStream<T,S>>
-
isParallel
public boolean isParallel()
- Specified by:
isParallelin interfaceBaseStream<T,S extends BaseStream<T,S>>
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBaseStream<T,S extends BaseStream<T,S>>
-
-