facets.util
Class ItemList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by facets.util.ItemList<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess
Direct Known Subclasses:
ItemList.TreeItems

public class ItemList<T>
extends java.util.ArrayList<T>

An array-friendly List.

ItemList extends ArrayList with methods that encapsulate the complications of adding and extracting simple arrays from a List.

The problem of constructing generic arrays is circumvented by passing in the storage type during construction. Run-time checking protects against the unlikely error of passing in the wrong type; compile-time checking of the generics type protects against more subtle code weaknesses.

ItemList<Integer> ints = new ItemList(Integer.class);
ints.addItems(1,2,3);
ints.addItem(4);
Integer[] items = ints.items();

See Also:
Serialized Form

Nested Class Summary
static class ItemList.TreeItems<C>
          ItemList that can traverse a generic tree.
 
Field Summary
protected static int defaultSize
           
 java.lang.Class itemType
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ItemList(java.lang.Class itemType)
          Unique constructor.
ItemList(T[] src)
           
 
Method Summary
 void addItem(T item)
          Add item which must be non-null and of the type passed to the constructor.
 void addItems(T... items)
          Add items which must be an array of the type passed to the constructor.
 T[] items()
          Returns an array of the storage type passed to the constructor.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

defaultSize

protected static final int defaultSize
See Also:
Constant Field Values

itemType

public final java.lang.Class itemType
Constructor Detail

ItemList

public ItemList(java.lang.Class itemType)
Unique constructor.

Sets initial size as specified by class constant defaultSize.

Parameters:
itemType - - the type of object to be allowed in the list

ItemList

public ItemList(T[] src)
Method Detail

addItem

public final void addItem(T item)
Add item which must be non-null and of the type passed to the constructor.

Wraps List.add(Object).


addItems

public final void addItems(T... items)
Add items which must be an array of the type passed to the constructor.

Wraps List.addAll(Collection).


items

public final T[] items()
Returns an array of the storage type passed to the constructor.

Wraps ).