Package ste.lloop

Class IndexedSequence<T>

Type Parameters:
T - the type of the elements in the array
Direct Known Subclasses:
ArraySequence, ListSequence

public abstract class IndexedSequence<T> extends AbstractSequence<IndexedSequence<T>>
A loop over an array that can be configured with a starting and ending index.

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.

  • Constructor Details

    • IndexedSequence

      protected IndexedSequence()
      Constructs a new IndexedSequence instance.
  • Method Details

    • loop

      public abstract <R> R loop(BiConsumer<Integer,T> consumer)
      Executes the given consumer for each element in the loop.

      If the array provided to the constructor was null, this method will do nothing.

      Type Parameters:
      R - the type of the return value
      Parameters:
      consumer - the consumer to execute for each element
      Returns:
      the value passed to Loop.brk(Object), or null if the loop completes without a brk
    • loop

      public <R> R loop(Consumer<T> consumer)
      Executes the given consumer for each element in the loop.

      If the array provided to the constructor was null, this method will do nothing.

      Type Parameters:
      R - the type of the return value
      Parameters:
      consumer - the consumer to execute for each element
      Returns:
      the value passed to Loop.brk(Object), or null if the loop completes without a brk