Interface Cycle<E>

Type Parameters:
E - the element type

public interface Cycle<E>
An infinite cycle of elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of this cycle.
    Gets the current element
    int
    Gets the current position of the cursor, as as index relating to a position in the backing list.
    Gets the list currently backing this cycle
    Advances the cursor, and returns the next element.
    int
    Returns the index of the next position in the cycle.
    static <E> Cycle<E>
    of(List<E> objects)
    Creates a new cycle of elements.
    Returns the next element without advancing the cursor.
    Returns the previous element without retreating the cursor.
    Retreats the counter, and returns the previous element.
    int
    Returns the index of the previous position in the cycle.
    void
    setCursor(int index)
    Sets the cursor to a given index
  • Method Details

    • of

      @Nonnull static <E> Cycle<E> of(@Nonnull List<E> objects)
      Creates a new cycle of elements.

      Changes to the supplying list are not reflected in the cycle.

      Type Parameters:
      E - the element type
      Parameters:
      objects - the objects to form the cycle from
      Returns:
      the cycle
    • cursor

      int cursor()
      Gets the current position of the cursor, as as index relating to a position in the backing list.
      Returns:
      the cursor position
    • setCursor

      void setCursor(int index)
      Sets the cursor to a given index
      Parameters:
      index - the index to set the cursor to
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • current

      @Nonnull E current()
      Gets the current element
      Returns:
      the current element
    • next

      @Nonnull E next()
      Advances the cursor, and returns the next element.
      Returns:
      the next element
    • previous

      @Nonnull E previous()
      Retreats the counter, and returns the previous element.
      Returns:
      the previous element
    • nextPosition

      int nextPosition()
      Returns the index of the next position in the cycle.
      Returns:
      the next position
    • previousPosition

      int previousPosition()
      Returns the index of the previous position in the cycle.
      Returns:
      the previous position
    • peekNext

      @Nonnull E peekNext()
      Returns the next element without advancing the cursor.
      Returns:
      the next element
    • peekPrevious

      @Nonnull E peekPrevious()
      Returns the previous element without retreating the cursor.
      Returns:
      the previous element
    • getBacking

      @Nonnull List<E> getBacking()
      Gets the list currently backing this cycle

      The returned list is immutable.

      Returns:
      the backing list
    • copy

      Cycle<E> copy()
      Creates a copy of this cycle.

      The returned cycle will contain the same elements as this cycle, but its cursor will be reset to zero.

      Returns:
      a copy of this cycle