org.knowceans.util
Class SetVector<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector<E>
              extended by org.knowceans.util.SetVector<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 SetVector<E>
extends java.util.Vector<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
SetVector()
           
SetVector(java.util.Collection<? extends E> c)
          Initialise the SetVector, getting rid of duplicate elements where duplicates
SetVector(int initialCapacity)
           
SetVector(int initialCapacity, int capacityIncrement)
           
 
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.
 boolean addAll(int index, java.util.Collection<? extends E> c)
          add all elements from the Collection at the index that are not contained yet in the SetVector.
 void addElement(E obj)
          same as add(Object).
 void insertElementAt(E obj, int index)
          same add add(int, 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.Vector
capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, retainAll, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
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
iterator, listIterator, listIterator
 

Constructor Detail

SetVector

public SetVector()

SetVector

public SetVector(int initialCapacity)
Parameters:
initialCapacity -

SetVector

public SetVector(int initialCapacity,
                 int capacityIncrement)
Parameters:
initialCapacity -
capacityIncrement -

SetVector

public SetVector(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.Vector<E>

addElement

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

Overrides:
addElement in class java.util.Vector<E>

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.Vector<E>

insertElementAt

public void insertElementAt(E obj,
                            int index)
same add add(int, Object).

Overrides:
insertElementAt in class java.util.Vector<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.Vector<E>
Returns:
true if the SetVector is changed.

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends E> c)
add all elements from the Collection at the index that are not contained yet in the SetVector. 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.List<E>
Overrides:
addAll in class java.util.Vector<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.Vector<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.

Overrides:
setElementAt in class java.util.Vector<E>
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)