public interface IntIterable extends Iterable<Integer>
Iterable<Integer>
providing a PrimitiveIterator.OfInt
which allows iteration over a
(possibly infinite) amount of unboxed primitive values.IntStream
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 int[]
array.int[]
array, IntegerRange
, or one of the
generator functions generate
and iterate
.Modifier and Type | Method and Description |
---|---|
default void |
forEachInt(IntConsumer consumer)
Iterates over all elements of the iterable and calls
consumer for
each element. |
static IntIterable |
generate(Functions.Function0<? extends IntSupplier> s)
Creates a new IntIterable that will produce an infinite
PrimitiveIterator.OfInt or IntStream based on the IntSupplier provided by supplier s . |
static IntIterable |
iterate(int seed,
IntPredicate hasNext,
IntUnaryOperator next)
Creates
IntIterable an which works similar to a traditional for-loop. |
static IntIterable |
iterate(int seed,
IntUnaryOperator op)
Creates
IntIterable 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.OfInt |
iterator()
Returns a primitive iterator over elements of type
int . |
default IntStream |
stream()
Returns an
IntStream based on the elements in the iterable. |
forEach, spliterator
PrimitiveIterator.OfInt iterator()
int
. This
method specializes the super-interface method.default void forEachInt(IntConsumer 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 be thrown if iterator()
returns null
.default IntStream stream()
IntStream
based on the elements in the iterable. PrimitiveIteratorExtensions.streamRemaining(PrimitiveIterator.OfInt)
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 IntIterable generate(Functions.Function0<? extends IntSupplier> s)
PrimitiveIterator.OfInt
or IntStream
based on the IntSupplier
provided by supplier s
.s
- supplier, that provides an IntSupplier
for each
iterator or stream created.s
.static IntIterable iterate(int seed, IntUnaryOperator op)
IntIterable
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.applyAsInt(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.IntIterable
providing infinite source of numbers
based on seed
and op
.static IntIterable iterate(int seed, IntPredicate hasNext, IntUnaryOperator next)
IntIterable
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 OfInt#next()
method will return the
boolean value provided by IntPredicate
on the potentially next value.
This also means that if IntPredicate
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.