cz.psika.utils
Class UniqueArrayList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by cz.psika.utils.UniqueArrayList<T>
Type Parameters:
T - list item type
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess

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

Extended ArrayList class to hold unique values only. Use method 'add' only, which is safe enough, some other methods should be overloaded to achieve proper extended functionality. Code retrieved from dangertree techblog (http://weblog.dangertree.net/2007/06/09/unique-arraylist/) and slightly modified to make it compilable and as much simple as possible.

Author:
Tomas Psika
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
UniqueArrayList()
           
 
Method Summary
 boolean add(T obj)
          Add the object to the list if there is no other copy of it.
 
Methods inherited from class java.util.ArrayList
add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, set, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, 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
 

Constructor Detail

UniqueArrayList

public UniqueArrayList()
Method Detail

add

public boolean add(T obj)
Add the object to the list if there is no other copy of it. Values of type null are ignored.

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.ArrayList<T>
Parameters:
obj - item of list
Returns:
true on success, false when item already exists in the list or null value given