Package org.powertac.util
Class RingArray<T>
- java.lang.Object
-
- org.powertac.util.RingArray<T>
-
public class RingArray<T> extends Object
Implements essentially an ArrayList of fixed size in which only the elements from (high-size) to high are kept. So for example, if you want to keep at most 48 elements indexed by timeslot, every time you add an element at some timeslot t, all elements older than t-48 would be discarded. Attempts to retrieve elements outside the current "window" will return null. Attempts to insert elements below the current window will produce an IndexOutOfBoundsException.- Author:
- John Collins
-
-
Constructor Summary
Constructors Constructor Description RingArray(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<T>asList(int start)Returns the current active elements as an AbstractList.voidclean(int startIndex)Cleans the "unused" portion of the array, from the current maxIndex to the given indexvoidclear()Clears all data out of the arrayTget(int index)Returns the element at the given index, or null if index is out of rangeT[]getActiveArray(int startIndex)Returns the "active" elements of the ring as a simple ArrayintgetActiveLength(int startIndex)Returns the "active length" of the array starting at the specified indexvoidset(int index, T element)Sets the element at the given index, potentially overwriting elements with index less than index-size.
-
-
-
Method Detail
-
clear
public void clear()
Clears all data out of the array
-
clean
public void clean(int startIndex)
Cleans the "unused" portion of the array, from the current maxIndex to the given index
-
getActiveLength
public int getActiveLength(int startIndex)
Returns the "active length" of the array starting at the specified index
-
set
public void set(int index, T element)Sets the element at the given index, potentially overwriting elements with index less than index-size. Attempts to add elements below the current window will fail silently.
-
get
public T get(int index)
Returns the element at the given index, or null if index is out of range
-
getActiveArray
public T[] getActiveArray(int startIndex)
Returns the "active" elements of the ring as a simple Array
-
-