Package ste.lloop

Class NumericSeries

java.lang.Object
ste.lloop.NumericSeries

public class NumericSeries extends Object
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 Details

    • from

      protected int from
      The starting value of the loop (inclusive).
    • to

      protected Integer to
      The ending value of the loop (inclusive).
    • step

      protected int step
      The step of the loop.
  • Constructor Details

    • NumericSeries

      public NumericSeries()
      Constructs a new NumericSeries instance.
  • Method Details

    • from

      public NumericSeries from(int from)
      Sets the starting value of the loop (inclusive).
      Parameters:
      from - the starting value
      Returns:
      this NumericSeries instance
    • to

      public NumericSeries to(int to)
      Sets the ending value of the loop (inclusive).
      Parameters:
      to - the ending value
      Returns:
      this NumericSeries instance
    • step

      public NumericSeries step(int 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 from to to. If the step is negative, the loop will go from to to from.

      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 NumericSeries instance
    • loop

      public void loop(Consumer<Integer> consumer)
      Executes the given consumer for each value in the loop. If from and to are equal, the loop will not execute.
      Parameters:
      consumer - the consumer to execute for each value