import java.util.ArrayList; import java.util.List; /** * Storage class for circularly looping over a list. */ public class CircularList { /** * How we actually store the data. */ private List list; /** * The current index in the list. */ private int index; public CircularList() { list = new ArrayList(); index = 0; } /** * Add an item to the end of the list. */ public void add(T newItem) { list.add(newItem); } /** * Access the item at the current index. */ public T current() { return list.get(index); } /** * Increment the index and get that item. */ public T next() { index = (index + 1) % list.size(); return list.get(index); } /** * Remove all items from the list and reset the index. */ public void clear() { list.clear(); index = 0; } /** * Get the list we're actually using. * This may not be the best thing, but it works for now. */ public List getList() { return list; } }