Parsing Engine

danbikel.util
Class FixedSizeSingletonList

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

public class FixedSizeSingletonList
extends AbstractFixedSizeList
implements Serializable

A FixedSizeList implementation for a singleton list (a list with only one element).

See Also:
Serialized Form

Field Summary
protected  Object obj
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FixedSizeSingletonList(Collection c)
          Constructs a new fixed-size list containing the element in the specified collection.
FixedSizeSingletonList(int size)
          Constructs a new fixed-size list with the specified size.
 
Method Summary
 Object get(int index)
          Returns the sole object in this list.
 int hashCode()
          Generates a hash code for this list.
protected  void initialize(int size)
          Initializes this singleton list.
 Object set(int index, Object obj)
          Sets the object wrapped by this singleton list.
 boolean shift(Object obj)
          Shifts the old object wrapped by this list “away” and causes this list to wrap the specified object.
 int size()
          Returns 1.
 
Methods inherited from class danbikel.util.AbstractFixedSizeList
add, addAll, addAll, equals, 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

obj

protected Object obj
Constructor Detail

FixedSizeSingletonList

public FixedSizeSingletonList(int size)
Constructs a new fixed-size list with the specified size.

Parameters:
size - the size of the list to create
Throws:
IllegalArgumentException - if the specified size is greater than 1

FixedSizeSingletonList

public FixedSizeSingletonList(Collection c)
Constructs a new fixed-size list containing the element in the specified collection.

Parameters:
c - a collection containing at most one element
Throws:
IllegalArgumentException - if the specified collection contains more than one element
Method Detail

initialize

protected void initialize(int size)
Initializes this singleton list.

Specified by:
initialize in class AbstractFixedSizeList
Parameters:
size - the size of this list (must be 1)
Throws:
IllegalArgumentException - if the specified size is greater than 1

size

public int size()
Returns 1.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
1

get

public Object get(int index)
Returns the sole object in this list.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
index - the index of the object to return (ignored)
Returns:
the sole object in this list

set

public Object set(int index,
                  Object obj)
Sets the object wrapped by this singleton list.

Specified by:
set in interface List
Specified by:
set in class AbstractFixedSizeList
Parameters:
index - the index of the object to wrap (ignored)
obj - the object that this list should wrap
Returns:
the old object wrapped by this singleton list

hashCode

public int hashCode()
Description copied from class: AbstractFixedSizeList
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 AbstractFixedSizeList
Returns:
the hash code of this fixed-size list

shift

public boolean shift(Object obj)
Shifts the old object wrapped by this list “away” and causes this list to wrap the specified object. This method modifies this list in the same way that set(int, java.lang.Object) does.

Specified by:
shift in interface FixedSizeList
Specified by:
shift in class AbstractFixedSizeList
Parameters:
obj - the object to shift into this singleton list
Returns:
true under all circumstances

Parsing Engine

Author: Dan Bikel.