org.geworkbench.bison.datastructure.complex.panels
Class CSItemList<T extends DSNamed>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by org.geworkbench.bison.datastructure.complex.panels.CSItemList<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, DSItemList<T>, DSIdentifiable
Direct Known Subclasses:
CSPanel, CSSequentialItemList

public class CSItemList<T extends DSNamed>
extends java.util.ArrayList<T>
implements DSItemList<T>

A default DSItemList implementation that is backed by an ArrayList and a HashMap.

See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable<java.lang.String,T> objectMap
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
CSItemList()
           
 
Method Summary
 void add(int index, T item)
          Inserts the item at the specified index.
 boolean add(T item)
          Adds a new item to the item list, if it does not already exist.
 boolean addAll(java.util.Collection<? extends T> ts)
           
 void clear()
          Clears the contents of this item list.
 boolean equals(java.lang.Object o)
           
 T get(java.lang.String label)
          Gets an item by label, using the HashMap.
 T get(T item)
          Gets an item by item template.
 java.lang.String getID()
          Gets the ID for this object.
 int hashCode()
           
 boolean remove(java.lang.Object item)
          Removes the object from the item list.
 void rename(T t, java.lang.String label)
          Renames the given named item.
 void setID(java.lang.String id)
          Sets the ID for this object.
 
Methods inherited from class java.util.ArrayList
addAll, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
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
addAll, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, set, size, subList, toArray, toArray
 

Field Detail

objectMap

protected java.util.Hashtable<java.lang.String,T extends DSNamed> objectMap
Constructor Detail

CSItemList

public CSItemList()
Method Detail

get

public T get(java.lang.String label)
Gets an item by label, using the HashMap.

Specified by:
get in interface DSItemList<T extends DSNamed>
Parameters:
label - the label of the item.
Returns:
the item found or null if not found.

add

public boolean add(T item)
Adds a new item to the item list, if it does not already exist.

Specified by:
add in interface java.util.Collection<T extends DSNamed>
Specified by:
add in interface java.util.List<T extends DSNamed>
Overrides:
add in class java.util.ArrayList<T extends DSNamed>
Parameters:
item - the item to add.
Returns:
true always.

addAll

public boolean addAll(java.util.Collection<? extends T> ts)
Specified by:
addAll in interface java.util.Collection<T extends DSNamed>
Specified by:
addAll in interface java.util.List<T extends DSNamed>
Overrides:
addAll in class java.util.ArrayList<T extends DSNamed>

add

public void add(int index,
                T item)
Inserts the item at the specified index. watkin - note: this violates the contract for List-- it does not add if index < size(), but replaces!

Specified by:
add in interface java.util.List<T extends DSNamed>
Overrides:
add in class java.util.ArrayList<T extends DSNamed>
Parameters:
index - the index at which to insert the item.
item - the item to insert.

get

public T get(T item)
Gets an item by item template. Only the DSNamed.getLabel() method is called.

Specified by:
get in interface DSItemList<T extends DSNamed>
Parameters:
item - the template item.
Returns:
the full item, or null if it was not found.

remove

public boolean remove(java.lang.Object item)
Removes the object from the item list.

Specified by:
remove in interface java.util.Collection<T extends DSNamed>
Specified by:
remove in interface java.util.List<T extends DSNamed>
Overrides:
remove in class java.util.ArrayList<T extends DSNamed>
Parameters:
item - the item to remove
Returns:
true if the item was found and removed, false if it was not found.

getID

public java.lang.String getID()
Gets the ID for this object.

Specified by:
getID in interface DSIdentifiable
Returns:
the id of this item list.

setID

public void setID(java.lang.String id)
Sets the ID for this object.

Specified by:
setID in interface DSIdentifiable
Parameters:
id - the new id for this item list.

clear

public void clear()
Clears the contents of this item list.

Specified by:
clear in interface java.util.Collection<T extends DSNamed>
Specified by:
clear in interface java.util.List<T extends DSNamed>
Overrides:
clear in class java.util.ArrayList<T extends DSNamed>

rename

public void rename(T t,
                   java.lang.String label)
Description copied from interface: DSItemList
Renames the given named item. Map-based item lists can update their mapping.

Specified by:
rename in interface DSItemList<T extends DSNamed>
Parameters:
t - item to be renamed (but has not yet been renamed). Must be a member of the list.
label - new name for item.

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<T extends DSNamed>
Specified by:
equals in interface java.util.List<T extends DSNamed>
Overrides:
equals in class java.util.AbstractList<T extends DSNamed>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<T extends DSNamed>
Specified by:
hashCode in interface java.util.List<T extends DSNamed>
Overrides:
hashCode in class java.util.AbstractList<T extends DSNamed>