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
-
UniqueVector()
- Constructs an empty UniqueVector.
-
UniqueVector(int)
- Constructs an empty UniqueVector with the specified initial capacity.
-
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.
-
capacity()
- Returns the current capacity of this vector.
-
clone()
- Returns a clone of this vector.
-
contains(Object)
- Tests if the specified object is a component in this vector.
-
copyInto(Object[])
- Copies the components of this vector into the specified array.
-
elementAt(int)
- Returns the component at the specified index.
-
elements()
- Returns an enumeration of the components of this vector.
-
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.
-
firstElement()
- Returns the first component of this vector.
-
indexOf(Object)
-
Returns the first (and only) occurrence of the given argument, testing
for equality using the
equals
method.
-
indexOf(Object, int)
- Returns the first occurrence of the given argument, beginning the search
at
index
, and testing for equality using the
equals
method.
-
insertElementAt(Object, int)
- Inserts the specified object as a component in this vector at the
specified
index
.
-
isEmpty()
- Tests if this vector has no components.
-
lastElement()
- Returns the last component of the vector.
-
lastIndexOf(Object)
- Returns the index of the last (and only) occurrence of the specified
object in this vector.
-
lastIndexOf(Object, int)
- Searches backwards for the specified object, starting from the
specified index, and returns an index to it.
-
removeAllElements()
- Removes all components from this vector and sets its size to zero.
-
removeElement(Object)
- Removes the first (and only) occurance of the argument from this
vector.
-
removeElementAt(int)
- Deletes the component at the specified index.
-
setElementAt(Object, int)
- Sets the component at the specified
index
of this vector
to be the specified object.
-
size()
- Returns the number of components in this vector.
-
toString()
- Returns a string representation of this vector.
-
trimToSize()
- Trims the capacity of this vector to be the vector's current size.
UniqueVector
public UniqueVector()
- Constructs an empty UniqueVector.
UniqueVector
public UniqueVector(int initialCapacity)
- Constructs an empty UniqueVector with the specified initial capacity.
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.
capacity
public int capacity()
- Returns the current capacity of this vector.
- Returns:
- the current capacity of this vector.
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
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.
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.
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.
elements
public synchronized Enumeration elements()
- Returns an enumeration of the components of this vector.
- Returns:
- an enumeration of the components of this vector.
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.
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.
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.
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.
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.
isEmpty
public boolean isEmpty()
- Tests if this vector has no components.
- Returns:
-
true
if this vector has no components;
false
otherwise.
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.
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.
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.
removeAllElements
public synchronized void removeAllElements()
- Removes all components from this vector and sets its size to zero.
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.
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.
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.
size
public int size()
- Returns the number of components in this vector.
- Returns:
- the number of components in this vector.
toString
public synchronized String toString()
- Returns a string representation of this vector.
- Returns:
- a string representation of this vector.
- Overrides:
- toString in class Object
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