org.knowceans.util
Class SetArrayList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by org.knowceans.util.SetArrayList<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, java.util.Set<E>

public class SetArrayList<E>
extends java.util.ArrayList<E>
implements java.util.Set<E>

A Collection that implements both the List and the Set interface. Based on the implementation of Vector, this class ensures uniqueness of items. The strategy is conservative, which means duplication between a modifying argument and an existing element will result in avoiding the modification.

Version:
rc1
Author:
heinrich TODO: test. Compare performance to TreeSet.
See Also:
Serialized Form

Constructor Summary
SetArrayList()
           
SetArrayList(java.util.Collection<? extends E> c)
          Initialise the SetVector, getting rid of duplicate elements where duplicates
SetArrayList(int initialCapacity)
           
 
Method Summary
 boolean add(E o)
          adds a new element at the end of the list iff this element does not exist yet in the object.
 void add(int index, E o)
          adds a new element at index i iff this element does not exist yet in the object.
 boolean addAll(java.util.Collection<? extends E> c)
          add all elements from the Collection that are not contained yet in the SetVector to the end of the object.
 void addElement(E obj)
          same as add(Object).
static void main(java.lang.String[] args)
           
 E set(int index, E element)
          Replaces the element at the specified position in this Vector with the specified element iff the element uniqueness is obeyed by this operation.
 void setElementAt(E obj, int index)
          Replaces the element at the specified position in this Vector with the specified element iff the element uniqueness is obeyed by this operation.
 
Methods inherited from class java.util.ArrayList
addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, 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
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

SetArrayList

public SetArrayList()

SetArrayList

public SetArrayList(int initialCapacity)
Parameters:
initialCapacity -

SetArrayList

public SetArrayList(java.util.Collection<? extends E> c)
Initialise the SetVector, getting rid of duplicate elements where duplicates

Parameters:
c -
Method Detail

add

public void add(int index,
                E o)
adds a new element at index i iff this element does not exist yet in the object. (does not return if the addition was successful).

Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.ArrayList<E>

addElement

public void addElement(E obj)
same as add(Object).


add

public boolean add(E o)
adds a new element at the end of the list iff this element does not exist yet in the object.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Specified by:
add in interface java.util.Set<E>
Overrides:
add in class java.util.ArrayList<E>

addAll

public boolean addAll(java.util.Collection<? extends E> c)
add all elements from the Collection that are not contained yet in the SetVector to the end of the object. If there is a duplicate, the old element is kept and the new one ignored, preserving the order of the collection. Use remove() to make sure the collection is inserted entirely.

Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Specified by:
addAll in interface java.util.Set<E>
Overrides:
addAll in class java.util.ArrayList<E>
Returns:
true if the SetVector is changed.

set

public E set(int index,
             E element)
Replaces the element at the specified position in this Vector with the specified element iff the element uniqueness is obeyed by this operation.

Specified by:
set in interface java.util.List<E>
Overrides:
set in class java.util.ArrayList<E>
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position or null if the Set already contains the element.

setElementAt

public void setElementAt(E obj,
                         int index)
Replaces the element at the specified position in this Vector with the specified element iff the element uniqueness is obeyed by this operation.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.

main

public static void main(java.lang.String[] args)