|
JUtil | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
net.cscott.jutil.UniqueVector<E>
public class UniqueVector<E>
A unique vector refuses to addElement duplicates.
Conforms to the JDK 1.2 Collections API.
Vector
,
Hashtable
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
UniqueVector()
Constructs an empty UniqueVector. |
|
UniqueVector(Collection<? extends E> c)
Constructs a vector containing the elements of the specified Collection , in the order they are returned by the
collection's iterator. |
|
UniqueVector(int initialCapacity)
Constructs an empty UniqueVector with the specified initial capacity. |
Method Summary | ||
---|---|---|
boolean |
add(E 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. |
|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this list. |
|
void |
addElement(E 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. |
|
int |
capacity()
Returns the current capacity of this vector. |
|
void |
clear()
Removes all of the elements from this collection. |
|
UniqueVector<E> |
clone()
Returns a clone of this vector. |
|
boolean |
contains(Object elem)
Tests if the specified object is a component in this vector. |
|
void |
copyInto(Object[] anArray)
Copies the components of this vector into the specified array. |
|
E |
elementAt(int index)
Returns the component at the specified index. |
|
Enumeration<E> |
elements()
Returns an enumeration of the components of this vector. |
|
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. |
|
boolean |
equals(Object o)
|
|
E |
firstElement()
Returns the first component of this vector. |
|
E |
get(int index)
Returns the element at the specified posision in this vector. |
|
int |
hashCode()
|
|
int |
indexOf(Object elem)
Returns the first (and only) occurrence of the given argument, testing for equality using the equals method. |
|
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. |
|
void |
insertElementAt(E obj,
int index)
Inserts the specified object as a component in this vector at the specified index . |
|
boolean |
isEmpty()
Tests if this vector has no components. |
|
E |
lastElement()
Returns the last component of the vector. |
|
int |
lastIndexOf(Object elem)
Returns the index of the last (and only) occurrence of the specified object in this vector. |
|
int |
lastIndexOf(Object elem,
int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it. |
|
E |
remove(int index)
Removes the element at the specified position in this vector. |
|
void |
removeAllElements()
Removes all components from this vector and sets its size to zero. |
|
boolean |
removeElement(Object obj)
Removes the first (and only) occurance of the argument from this vector. |
|
void |
removeElementAt(int index)
Deletes the component at the specified index. |
|
E |
set(int index,
E obj)
Replaces the element at the specified position in this vector with the specified element. |
|
void |
setElementAt(E obj,
int index)
Sets the component at the specified index of this vector
to be the specified object. |
|
int |
size()
Returns the number of components in this vector. |
|
Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
String |
toString()
Returns a string representation of this vector. |
|
void |
trimToSize()
Trims the capacity of this vector to be the vector's current size. |
Methods inherited from class java.util.AbstractList |
---|
addAll, iterator, listIterator, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, remove, removeAll, retainAll |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, iterator, remove, removeAll, retainAll |
Methods inherited from interface java.util.List |
---|
addAll, containsAll, remove, removeAll, retainAll |
Constructor Detail |
---|
public UniqueVector()
public UniqueVector(int initialCapacity)
public UniqueVector(Collection<? extends E> c)
Collection
, in the order they are returned by the
collection's iterator. Duplicate elements are skipped.
Method Detail |
---|
public void addElement(E obj)
obj
- the component to be added.public void add(int index, E element)
add
in interface List<E>
add
in class AbstractList<E>
index
- the specified position.element
- the element to be inserted.public boolean add(E obj)
add
in interface Collection<E>
add
in interface List<E>
add
in interface Set<E>
add
in class AbstractList<E>
obj
- the component to be added.public int capacity()
UnsupportedOperationException
- not supported.public UniqueVector<E> clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- if the UniqueVector cannot be cloned.public boolean contains(Object elem)
contains
in interface Collection<E>
contains
in interface List<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
elem
- an object
true
if the specified object is a component in
this vector; false
otherwise.public void copyInto(Object[] anArray)
anArray
- the array into which the components get copied.public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public E elementAt(int index)
index
- an index into this vector.
ArrayIndexOutOfBoundsException
- if an invalid index was given.public E get(int index)
get
in interface List<E>
get
in class AbstractList<E>
public Enumeration<E> elements()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public E firstElement()
NoSuchElementException
- if this vector has no components.public int indexOf(Object elem)
equals
method.
indexOf
in interface List<E>
indexOf
in class AbstractList<E>
elem
- an object
-1
if the object is not found.public int indexOf(Object elem, int index)
index
, and testing for equality using the
equals
method.
elem
- an object.index
- the index to start searching from.
index
or later in the vector;
returns -1
if the object is not found.public void insertElementAt(E obj, int index)
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.
obj
- the component to insert.index
- where to insert the new component.
ArrayIndexOutOfBoundsException
- if the index was invalid.public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface List<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
true
if this vector has no components;
false
otherwise.public E lastElement()
size()-1
.
NoSuchElementException
- if this vector is empty.public int lastIndexOf(Object elem)
lastIndexOf
in interface List<E>
lastIndexOf
in class AbstractList<E>
elem
- the desired component.
-1
if the object is not
found.public int lastIndexOf(Object elem, int index)
elem
- the desired component.index
- the index to start searching from.
index
in
the vector; -1
if the object is not found.public void removeAllElements()
public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in interface Set<E>
clear
in class AbstractList<E>
public final boolean removeElement(Object obj)
obj
- the component to be removed.
true
if the argument was a component of this vector;
false
otherwise.public void removeElementAt(int index)
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.
index
- the index of the object to remove.
ArrayIndexOutOfBoundsException
- if the index was invalid.public E remove(int index)
remove
in interface List<E>
remove
in class AbstractList<E>
public void setElementAt(E obj, int index)
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.
obj
- what the component is to be set to.index
- the specified index.
ArrayIndexOutOfBoundsException
- if the index was invalid.public E set(int index, E obj)
set
in interface List<E>
set
in class AbstractList<E>
public int size()
size
in interface Collection<E>
size
in interface List<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public void trimToSize()
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in interface List<E>
hashCode
in interface Set<E>
hashCode
in class AbstractList<E>
public boolean equals(Object o)
equals
in interface Collection<E>
equals
in interface List<E>
equals
in interface Set<E>
equals
in class AbstractList<E>
|
JUtil | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |