danbikel.util
Class FixedSizeArrayList
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList
danbikel.util.AbstractFixedSizeList
danbikel.util.FixedSizeArrayList
- All Implemented Interfaces:
- FixedSizeList, Serializable, Iterable, Collection, List
public class FixedSizeArrayList
- extends AbstractFixedSizeList
- implements Serializable
A fixed-size list of objects backed by an array. By providing a
constant-time shift(Object)
method, this implementation supports
an efficient implementation of a circular buffer.
- See Also:
- Serialized Form
Method Summary |
Object |
get(int index)
|
protected void |
initialize(int size)
Initializes this list to be of the specified size. |
Object |
set(int index,
Object obj)
Sets the specified object to be at the specified index in this fixed-size
list. |
boolean |
shift(Object obj)
Shifts the specified object to the beginning of the list, that is,
causes the specified object to be the value at index 0,
causes the object at index size() - 1 to be removed and
causes the index of all other objects to be increased by 1. |
int |
size()
|
Methods inherited from interface java.util.List |
contains, containsAll, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, subList, toArray, toArray |
data
protected Object[] data
startIdx
protected int startIdx
FixedSizeArrayList
public FixedSizeArrayList(int size)
FixedSizeArrayList
public FixedSizeArrayList(Collection c)
initialize
protected void initialize(int size)
- Description copied from class:
AbstractFixedSizeList
- Initializes this list to be of the specified size. As per the general
contract of
FixedSizeList
, all elements will initially be
null
. Implementors should take care not to invoke this
method subsequent to construction of a fixed-size list, as such an
invocation would violate the general contract of FixedSizeList
.
- Specified by:
initialize
in class AbstractFixedSizeList
- Parameters:
size
- the size of this list
get
public Object get(int index)
- Specified by:
get
in interface List
- Specified by:
get
in class AbstractList
set
public Object set(int index,
Object obj)
- Description copied from class:
AbstractFixedSizeList
- Sets the specified object to be at the specified index in this fixed-size
list.
- Specified by:
set
in interface List
- Specified by:
set
in class AbstractFixedSizeList
- Parameters:
index
- the index at which to set the specified objectobj
- the object to be set at the specified index
- Returns:
- the object that was formerly at the specified index
size
public int size()
- Specified by:
size
in interface Collection
- Specified by:
size
in interface List
- Specified by:
size
in class AbstractCollection
shift
public boolean shift(Object obj)
- Description copied from interface:
FixedSizeList
- Shifts the specified object to the beginning of the list, that is,
causes the specified object to be the value at index 0,
causes the object at index size() - 1 to be removed and
causes the index of all other objects to be increased by 1.
Implementation advice: This method may be implemented to take
constant (that is, O(1)) time if the employed data struture is a
circular buffer.
- Specified by:
shift
in interface FixedSizeList
- Specified by:
shift
in class AbstractFixedSizeList
- Parameters:
obj
- the object to be shifted into this list
- Returns:
- true (as per the general contract of the
Collection.add
method)
Author: Dan Bikel.