Parsing Engine

danbikel.util
Class FixedSizeArrayList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by danbikel.util.AbstractFixedSizeList
              extended by 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

Field Summary
protected  Object[] data
           
protected  int startIdx
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FixedSizeArrayList(Collection c)
           
FixedSizeArrayList(int size)
           
 
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 class danbikel.util.AbstractFixedSizeList
add, addAll, addAll, equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractList
add, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface danbikel.util.FixedSizeList
add, clear, remove, remove, retainAll
 
Methods inherited from interface java.util.List
contains, containsAll, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, subList, toArray, toArray
 

Field Detail

data

protected Object[] data

startIdx

protected int startIdx
Constructor Detail

FixedSizeArrayList

public FixedSizeArrayList(int size)

FixedSizeArrayList

public FixedSizeArrayList(Collection c)
Method Detail

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 object
obj - 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)

Parsing Engine

Author: Dan Bikel.