Parsing Engine

danbikel.util
Class AbstractFixedSizeList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by danbikel.util.AbstractFixedSizeList
All Implemented Interfaces:
FixedSizeList, Iterable, Collection, List
Direct Known Subclasses:
FixedSizeArrayList, FixedSizeSingletonList

public abstract class AbstractFixedSizeList
extends AbstractList
implements FixedSizeList

Provides a convenient default implementation for most of the methods of List and FixedSizeList.


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected AbstractFixedSizeList()
          No-arg constructor, for use only for Serialization of derived, concrete classes.
protected AbstractFixedSizeList(Collection c)
          Initializes this new list to contain all elements of the specified collection.
protected AbstractFixedSizeList(int size)
          Initializes this new list to have the specified number of elements.
 
Method Summary
 boolean add(Object obj)
          A synonym for FixedSizeList.shift(Object).
 boolean addAll(Collection c)
          Sets the first n elements of this list to be the elements of the specified collection, where n is the minimum of the size of the collection and the (fixed) size of this list.
 boolean addAll(int index, Collection c)
          Implementors should simply throw an UnsupportedOperationException.
 boolean equals(Object o)
          Compres this FixedSizeList to the specified object for equality.
 int hashCode()
          Generates a hash code for this list.
protected abstract  void initialize(int size)
          Initializes this list to be of the specified size.
 boolean removeAll(Collection c)
          Implementors should simply throw an UnsupportedOperationException.
abstract  Object set(int index, Object element)
          Sets the specified object to be at the specified index in this fixed-size list.
abstract  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.
 
Methods inherited from class java.util.AbstractList
add, clear, get, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, retainAll, size, 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, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, size, subList, toArray, toArray
 

Constructor Detail

AbstractFixedSizeList

protected AbstractFixedSizeList()
No-arg constructor, for use only for Serialization of derived, concrete classes.


AbstractFixedSizeList

protected AbstractFixedSizeList(int size)
Initializes this new list to have the specified number of elements. As per the contract of FixedSizeList, all elements will initially be null.

Parameters:
size - the number of elements that this fixed-size list will have

AbstractFixedSizeList

protected AbstractFixedSizeList(Collection c)
Initializes this new list to contain all elements of the specified collection.

Parameters:
c - a collection whose elements are to become the elements of this fixed-size list
Method Detail

initialize

protected abstract void initialize(int size)
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.

Parameters:
size - the size of this list

add

public boolean add(Object obj)
Description copied from interface: FixedSizeList
A synonym for FixedSizeList.shift(Object).

Specified by:
add in interface FixedSizeList
Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class AbstractList
Parameters:
obj - the object to be shifted into the first position of this list
Returns:
true (as per the general contract of the Collection.add method)

addAll

public boolean addAll(Collection c)
Description copied from interface: FixedSizeList
Sets the first n elements of this list to be the elements of the specified collection, where n is the minimum of the size of the collection and the (fixed) size of this list.

Specified by:
addAll in interface FixedSizeList
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Overrides:
addAll in class AbstractCollection
Parameters:
c - the collection whose elements are to become the elements of this list
Returns:
true if this list was modified as a result of the call

addAll

public boolean addAll(int index,
                      Collection c)
Description copied from interface: FixedSizeList
Implementors should simply throw an UnsupportedOperationException.

Specified by:
addAll in interface FixedSizeList
Specified by:
addAll in interface List
Overrides:
addAll in class AbstractList

removeAll

public boolean removeAll(Collection c)
Description copied from interface: FixedSizeList
Implementors should simply throw an UnsupportedOperationException.

Specified by:
removeAll in interface FixedSizeList
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
Overrides:
removeAll in class AbstractCollection

set

public abstract Object set(int index,
                           Object element)
Sets the specified object to be at the specified index in this fixed-size list.

Specified by:
set in interface List
Overrides:
set in class AbstractList
Parameters:
index - the index at which to set the specified object
element - the object to be set at the specified index
Returns:
the object that was formerly at the specified index

shift

public abstract 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
Parameters:
obj - the object to be shifted into this list
Returns:
true (as per the general contract of the Collection.add method)

equals

public boolean equals(Object o)
Compres this FixedSizeList to the specified object for equality. This implementation assumes that the get(int) and size() methods take constant time.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class AbstractList
Parameters:
o - the object to test for equality with this object
Returns:
whether the specified object is equal to this object

hashCode

public int hashCode()
Generates a hash code for this list. This implementation assumes that the get(int) and size() methods take constant time.

Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class AbstractList
Returns:
the hash code of this fixed-size list

Parsing Engine

Author: Dan Bikel.