|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<T>
org.javasimon.callback.lastsplits.CircularList<T>
public class CircularList<T>
Ring/circular buffer, fixed size FIFO list. Stores values as a fixed size array looping insertion point when array is full. Warnings:
| Nested Class Summary | |
|---|---|
private class |
CircularList.EmptyIterator
Empty iterator used when the list is empty |
private class |
CircularList.MainIterator
Main iterator user when the list contains at least one element |
| Field Summary | |
|---|---|
private T[] |
elements
Elements |
private int |
firstIndex
Index of the the first element. |
private int |
lastIndex
Index + 1 of the last element. |
private int |
size
Number of element stored in this list. |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
CircularList(int capacity)
Contructor |
|
| Method Summary | ||
|---|---|---|
boolean |
add(T newElement)
Add an element to the list, overwriting last added element when list's capacity is reached |
|
boolean |
addAll(Collection<? extends T> newElements)
Insert a collection of elements, looping on them |
|
void |
clear()
Removes all elements from the list |
|
private int |
convertIndex(int index)
Converts an index starting from 0 into an index starting from first |
|
private
|
copy(X[] elementsCopy)
Copy elements in a target array |
|
T |
first()
Get the first (inserted) element |
|
T |
get(int index)
Get element by index |
|
int |
getCapacity()
Get capacity (buffer size). |
|
private int |
incrementIndex(int index,
int maxIndex)
Increment an index |
|
boolean |
isEmpty()
Tells whether the list is empty |
|
private boolean |
isFull()
|
|
Iterator<T> |
iterator()
Create a new iterator to browse elements |
|
T |
last()
Get the last (inserted) element |
|
T |
removeFirst()
Remove the first (inserted) element of the collection |
|
int |
size()
Return the number of elements in the list |
|
Object[] |
toArray()
|
|
|
toArray(T[] elementsCopy)
|
|
| Methods inherited from class java.util.AbstractList |
|---|
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
contains, containsAll, remove, removeAll, retainAll, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
contains, containsAll, remove, removeAll, retainAll |
| Field Detail |
|---|
private final T[] elements
private int lastIndex
private int firstIndex
private int size
| Constructor Detail |
|---|
public CircularList(int capacity)
capacity - Size of the ring buffer| Method Detail |
|---|
public int getCapacity()
private int convertIndex(int index)
index - Index
public T get(int index)
get in interface List<T>get in class AbstractList<T>index - Index
public int size()
size in interface Collection<T>size in interface List<T>size in class AbstractCollection<T>public boolean isEmpty()
isEmpty in interface Collection<T>isEmpty in interface List<T>isEmpty in class AbstractCollection<T>
private int incrementIndex(int index,
int maxIndex)
index - Input indexmaxIndex - Assigned value when capacity is reached
public boolean add(T newElement)
add in interface Collection<T>add in interface List<T>add in class AbstractList<T>newElement - Element to add
private boolean isFull()
public boolean addAll(Collection<? extends T> newElements)
addAll in interface Collection<T>addAll in interface List<T>addAll in class AbstractCollection<T>newElements - Collection of elements to add
public T removeFirst()
public T first()
public T last()
public void clear()
clear in interface Collection<T>clear in interface List<T>clear in class AbstractList<T>public Iterator<T> iterator()
iterator in interface Iterable<T>iterator in interface Collection<T>iterator in interface List<T>iterator in class AbstractList<T>private <X> void copy(X[] elementsCopy)
elementsCopy - Target arraypublic Object[] toArray()
toArray in interface Collection<T>toArray in interface List<T>toArray in class AbstractCollection<T>public <T> T[] toArray(T[] elementsCopy)
toArray in interface Collection<T>toArray in interface List<T>toArray in class AbstractCollection<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||