Class Sequence<T>
- Type Parameters:
T- the type of the elements in the array
This class is not meant to be instantiated directly. Use Loop.on(Object[]) to start
building an array loop.
The loop can be configured with a from index, a to index, and a step value.
If from and to are equal, the loop will not execute.
The loop can be executed by calling one of the two loop methods: one that provides both the index and the element, and one that provides only the element.
-
Method Summary
Modifier and TypeMethodDescriptionfrom(int from) Sets the starting index of the loop (inclusive).voidloop(BiConsumer<Integer, T> consumer) Executes the given consumer for each element in the loop.voidExecutes the given consumer for each element in the loop.step(int step) Sets the step of the loop.to(int to) Sets the ending index of the loop (inclusive).
-
Method Details
-
step
Sets the step of the loop. The sign of the step determines the direction of the loop.If the step is positive, the loop will go from
fromtoto. If the step is negative, the loop will go fromtotofrom.The absolute value of the step is used as the increment. If the step is zero, the loop will not execute.
- Parameters:
step- the step value- Returns:
- this
Sequenceinstance
-
from
Sets the starting index of the loop (inclusive).- Parameters:
from- the starting index- Returns:
- this
Sequenceinstance - Throws:
IndexOutOfBoundsException- if the 'from' value is less than zero
-
to
Sets the ending index of the loop (inclusive).- Parameters:
to- the ending index- Returns:
- this
Sequenceinstance
-
loop
Executes the given consumer for each element in the loop.If the array provided to the constructor was
null, this method will do nothing.- Parameters:
consumer- the consumer to execute for each element
-
loop
Executes the given consumer for each element in the loop.If the array provided to the constructor was
null, this method will do nothing.- Parameters:
consumer- the consumer to execute for each element
-