Package dev.demeng.pluginbase.bucket
Interface Cycle<E>
- Type Parameters:
E- the element type
public interface Cycle<E>
An infinite cycle of elements.
-
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this cycle.current()Gets the current elementintcursor()Gets the current position of the cursor, as as index relating to a position in the backing list.Gets the list currently backing this cyclenext()Advances the cursor, and returns the next element.intReturns the index of the next position in the cycle.static <E> Cycle<E>Creates a new cycle of elements.peekNext()Returns the next element without advancing the cursor.Returns the previous element without retreating the cursor.previous()Retreats the counter, and returns the previous element.intReturns the index of the previous position in the cycle.voidsetCursor(int index) Sets the cursor to a given index
-
Method Details
-
of
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
Gets the current element- Returns:
- the current element
-
next
Advances the cursor, and returns the next element.- Returns:
- the next element
-
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
Returns the next element without advancing the cursor.- Returns:
- the next element
-
peekPrevious
Returns the previous element without retreating the cursor.- Returns:
- the previous element
-
getBacking
Gets the list currently backing this cycleThe returned list is immutable.
- Returns:
- the backing list
-
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
-