All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class harpoon.Util.UniqueVector

java.lang.Object
   |
   +----harpoon.Util.UniqueVector

public class UniqueVector
extends Object
implements Cloneable
A unique vector refuses to addElement duplicates.

Version:
$Id: UniqueVector.java,v 1.6 1998/10/11 03:01:19 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Vector, Hashtable

Constructor Index

 o UniqueVector()
Constructs an empty UniqueVector.
 o UniqueVector(int)
Constructs an empty UniqueVector with the specified initial capacity.

Method Index

 o addElement(Object)
Adds the specified component to the end of this vector, increasing its size by one, if it doesn't already exist in the vector.
 o capacity()
Returns the current capacity of this vector.
 o clone()
Returns a clone of this vector.
 o contains(Object)
Tests if the specified object is a component in this vector.
 o copyInto(Object[])
Copies the components of this vector into the specified array.
 o elementAt(int)
Returns the component at the specified index.
 o elements()
Returns an enumeration of the components of this vector.
 o ensureCapacity(int)
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
 o firstElement()
Returns the first component of this vector.
 o indexOf(Object)
Returns the first (and only) occurrence of the given argument, testing for equality using the equals method.
 o indexOf(Object, int)
Returns the first occurrence of the given argument, beginning the search at index, and testing for equality using the equals method.
 o insertElementAt(Object, int)
Inserts the specified object as a component in this vector at the specified index.
 o isEmpty()
Tests if this vector has no components.
 o lastElement()
Returns the last component of the vector.
 o lastIndexOf(Object)
Returns the index of the last (and only) occurrence of the specified object in this vector.
 o lastIndexOf(Object, int)
Searches backwards for the specified object, starting from the specified index, and returns an index to it.
 o removeAllElements()
Removes all components from this vector and sets its size to zero.
 o removeElement(Object)
Removes the first (and only) occurance of the argument from this vector.
 o removeElementAt(int)
Deletes the component at the specified index.
 o setElementAt(Object, int)
Sets the component at the specified index of this vector to be the specified object.
 o size()
Returns the number of components in this vector.
 o toString()
Returns a string representation of this vector.
 o trimToSize()
Trims the capacity of this vector to be the vector's current size.

Constructors

 o UniqueVector
 public UniqueVector()
Constructs an empty UniqueVector.

 o UniqueVector
 public UniqueVector(int initialCapacity)
Constructs an empty UniqueVector with the specified initial capacity.

Methods

 o addElement
 public synchronized void addElement(Object obj)
Adds the specified component to the end of this vector, increasing its size by one, if it doesn't already exist in the vector. Duplicate elements are thrown away. The capacity of the vector is increased if necessary.

Parameters:
obj - the component to be added.
 o capacity
 public int capacity()
Returns the current capacity of this vector.

Returns:
the current capacity of this vector.
 o clone
 public synchronized Object clone() throws CloneNotSupportedException
Returns a clone of this vector.

Returns:
a clone of this vector.
Throws: CloneNotSupportedException
if the UniqueVector cannot be cloned.
Overrides:
clone in class Object
 o contains
 public boolean contains(Object elem)
Tests if the specified object is a component in this vector.

Parameters:
elem - an object
Returns:
true if the specified object is a component in this vector; false otherwise.
 o copyInto
 public synchronized void copyInto(Object anArray[])
Copies the components of this vector into the specified array. The array must be big enough to hold all the objects in this vector.

Parameters:
anArray - the array into which the components get copied.
 o elementAt
 public synchronized Object elementAt(int index)
Returns the component at the specified index.

Parameters:
index - an index into this vector.
Returns:
the component at the specified index.
Throws: ArrayIndexOutOfBoundsException
if an invalid index was given.
 o elements
 public synchronized Enumeration elements()
Returns an enumeration of the components of this vector.

Returns:
an enumeration of the components of this vector.
 o ensureCapacity
 public synchronized void ensureCapacity(int minCapacity)
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.
 o firstElement
 public synchronized Object firstElement()
Returns the first component of this vector.

Returns:
the first component of this vector.
Throws: NoSuchElementException
if this vector has no components.
 o indexOf
 public synchronized int indexOf(Object elem)
Returns the first (and only) occurrence of the given argument, testing for equality using the equals method.

Parameters:
elem - an object
Returns:
the index of the first occurrence of the argument in this vector; returns -1 if the object is not found.
 o indexOf
 public synchronized int indexOf(Object elem,
                                 int index)
Returns the first occurrence of the given argument, beginning the search at index, and testing for equality using the equals method.

Parameters:
elem - an object.
index - the index to start searching from.
Returns:
the index of the first occurrence of the object argument in this vector at position index or later in the vector; returns -1 if the object is not found.
 o insertElementAt
 public synchronized void insertElementAt(Object obj,
                                          int index)
Inserts the specified object as a component in this vector at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

The index must be a value greater than or equal to 0 and less than or equal to the current size of the vector.

To maintain uniqueness, removed any previous instance of the component in the vector before insertion.

Parameters:
obj - the component to insert.
index - where to insert the new component.
Throws: ArrayIndexOutOfBoundsException
if the index was invalid.
 o isEmpty
 public boolean isEmpty()
Tests if this vector has no components.

Returns:
true if this vector has no components; false otherwise.
 o lastElement
 public synchronized Object lastElement()
Returns the last component of the vector.

Returns:
the last component of the vector, i.e., the component at index size()-1.
Throws: NoSuchElementException
if this vector is empty.
 o lastIndexOf
 public int lastIndexOf(Object elem)
Returns the index of the last (and only) occurrence of the specified object in this vector.

Parameters:
elem - the desired component.
Returns:
the index of the last occurrence of the specified object in this vector; returns -1 if the object is not found.
 o lastIndexOf
 public synchronized int lastIndexOf(Object elem,
                                     int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it.

Parameters:
elem - the desired component.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified object in this vector at position less than index in the vector; -1 if the object is not found.
 o removeAllElements
 public synchronized void removeAllElements()
Removes all components from this vector and sets its size to zero.

 o removeElement
 public final synchronized boolean removeElement(Object obj)
Removes the first (and only) occurance of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.

Parameters:
obj - the component to be removed.
Returns:
true if the argument was a component of this vector; false otherwise.
 o removeElementAt
 public synchronized void removeElementAt(int index)
Deletes the component at the specified index. Each component in this vector with an index greater than or equal to the specified index is shifted downward to have an index one smaller than the value it had previously.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

Parameters:
index - the index of the object to remove.
Throws: ArrayIndexOutOfBoundsException
if the index was invalid.
 o setElementAt
 public synchronized void setElementAt(Object obj,
                                       int index)
Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

Nothing is done if the component at index is equal to obj. To maintain uniqueness, any component equal to obj is removed before the setElementAt() is done.

Parameters:
obj - what the component is to be set to.
index - the specified index.
Throws: ArrayIndexOutOfBoundsException
if the index was invalid.
 o size
 public int size()
Returns the number of components in this vector.

Returns:
the number of components in this vector.
 o toString
 public synchronized String toString()
Returns a string representation of this vector.

Returns:
a string representation of this vector.
Overrides:
toString in class Object
 o trimToSize
 public synchronized void trimToSize()
Trims the capacity of this vector to be the vector's current size. An application can use this operation to minimize the storage of a vector.


All Packages  Class Hierarchy  This Package  Previous  Next  Index