Package ste.lloop
Class NumericSequence
java.lang.Object
ste.lloop.NumericSequence
A numeric loop that can be configured with a starting and ending value.
This class is not meant to be instantiated directly. Use Loop.on() to start building a
numeric loop.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
from
protected int fromThe starting value of the loop (inclusive). -
to
The ending value of the loop (inclusive). -
step
protected int stepThe step of the loop.
-
-
Constructor Details
-
NumericSequence
public NumericSequence()Constructs a newNumericSequenceinstance.
-
-
Method Details
-
from
Sets the starting value of the loop (inclusive).- Parameters:
from- the starting value- Returns:
- this
NumericSequenceinstance
-
to
Sets the ending value of the loop (inclusive).- Parameters:
to- the ending value- Returns:
- this
NumericSequenceinstance - Throws:
IllegalArgumentException- if a negative step is set
-
step
Sets the step of the loop.A negative step is allowed only if
tois not set, in which case the loop will go backwards.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
NumericSequenceinstance - Throws:
IllegalArgumentException- if a negative step is set whentois also set
-
loop
Executes the given consumer for each value in the loop.If
tois set (finite loop) andfromandtoare equal, the loop will not execute.If
tois not set (infinite loop), the loop will continue indefinitely untilLoop.brk(Object)is called.- Type Parameters:
R- the type of the return value- Parameters:
consumer- the consumer to execute for each value- Returns:
- the value passed to
Loop.brk(Object), ornullif the loop completes without abrk
-