public interface LongIterable extends Iterable<Long>
Iterable<Long>
providing a PrimitiveIterator.OfLong
which allows iteration over a (possibly infinite) amount of unboxed primitive values.LongStream
would
be appropriate, but the user has to be able to create the stream multiple
times. It can also be used as an immutable view on an long[]
array.Modifier and Type | Method and Description |
---|---|
default void |
forEachLong(LongConsumer consumer)
Iterates over all elements of the iterable and calls
consumer for
each element. |
static LongIterable |
generate(Functions.Function0<? extends LongSupplier> s)
Creates a new LongIterable that will produce an infinite
PrimitiveIterator.OfLong or LongStream based on the LongSupplier provided by supplier s . |
static LongIterable |
iterate(long seed,
LongPredicate hasNext,
LongUnaryOperator next)
Creates
LongIterable an which works similar to a traditional for-loop. |
static LongIterable |
iterate(long seed,
LongUnaryOperator op)
Creates
LongIterable an infinite providing an infinite source of
numbers, starting with the given seed value and in every
subsequent step the result of the given operator applied on the
last step's value. |
PrimitiveIterator.OfLong |
iterator()
Returns a primitive iterator over elements of type
long . |
default LongStream |
stream()
Returns an
LongStream based on the elements in the iterable. |
forEach, spliterator
PrimitiveIterator.OfLong iterator()
long
. This
method specializes the super-interface method.default void forEachLong(LongConsumer consumer)
consumer
for
each element. The default implementation uses iterator()
to get
the elements of the iterable. Implementations are encouraged to overwrite
this method with a more efficient implementation.consumer
throws an exception or terminates the runtime.consumer
- the action to be called for each element in the iterable.NullPointerException
- may throw if iterator()
returns null
.default LongStream stream()
LongStream
based on the elements in the iterable. PrimitiveIteratorExtensions.streamRemaining(PrimitiveIterator.OfLong)
with the iterator from iterator()
to construct the resulting stream. It is highly
recommended for the implementations of this interface to provide an own
implementation of this method.NullPointerException
- may be thrown if iterator()
returns null
.static LongIterable generate(Functions.Function0<? extends LongSupplier> s)
PrimitiveIterator.OfLong
or LongStream
based on the LongSupplier
provided by supplier s
.s
- supplier, that provides an LongSupplier
for each
iterator or stream created.s
.static LongIterable iterate(long seed, LongUnaryOperator op)
LongIterable
an infinite providing an infinite source of
numbers, starting with the given seed
value and in every
subsequent step the result of the given operator
applied on the
last step's value. So in the second step this would beop.applyAsLong(seed)
and so on.seed
- first value to be provided and used as seed fed to op
in second step.op
- this operator must be side-effect free.LongIterable
providing infinite source of numbers
based on seed
and op
.static LongIterable iterate(long seed, LongPredicate hasNext, LongUnaryOperator next)
LongIterable
an which works similar to a traditional for-loop.
The first value provided by an iterator provided by the created iterable will be seed
value.
The iterator's OfLong#next()
method will return the
boolean value provided by LongPredicate
on the potentially next value.
This also means that if LongPredicate
does not hold for the first value
the iterator will not provide any value. The next value provided after the initial
one is next
applied to the initial value. All following values provided by
the iterator will be computed from the last value by applying next
.seed
- initial value to be provided by iteratorshasNext
- method to check if iterator should provide a next valuenext
- value mapping previous value provided by iterator to next value providedseed
, hasNext
, and next
.Copyright © 2019. All rights reserved.