|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet
common.IndexedHashSet
public class IndexedHashSet
Implementation of the IndexedSet interface that stores objects in a list, and uses a HashMap to map objects to their indices. Indices are assigned to objects consecutively as they are added. When an object is removed, the last element is swapped in to fill its index; thus, removing an element that is not the last one may change the index of the last element. Getting the element at a given index takes constant time.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface common.IndexedSet |
---|
IndexedSet.EmptyIndexedSet |
Field Summary |
---|
Fields inherited from interface common.IndexedSet |
---|
EMPTY_INDEXED_SET |
Constructor Summary | |
---|---|
IndexedHashSet()
Creates a new, empty IndexedSet. |
|
IndexedHashSet(java.util.Collection c)
Creates a new IndexedSet whose elements are those in the given collection, ordered according to the collection's iterator order. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object o)
Adds the given object to this IndexedSet, with an index equal to the previous size of the set. |
void |
clear()
|
java.lang.Object |
clone()
|
boolean |
contains(java.lang.Object o)
|
java.lang.Object |
get(int index)
Returns the object with the specified index in this IndexedSet. |
int |
indexOf(java.lang.Object o)
Returns the index of the given object in this IndexedSet, or -1 if this IndexedSet does not contain the given object. |
java.util.Iterator |
iterator()
|
static void |
main(java.lang.String[] args)
Test program. |
boolean |
remove(java.lang.Object o)
Removes the given object from this IndexedSet if it was present. |
int |
size()
|
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
Constructor Detail |
---|
public IndexedHashSet()
public IndexedHashSet(java.util.Collection c)
Method Detail |
---|
public int size()
size
in interface java.util.Collection
size
in interface java.util.Set
size
in class java.util.AbstractCollection
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.Set
iterator
in class java.util.AbstractCollection
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
contains
in interface java.util.Set
contains
in class java.util.AbstractCollection
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
add
in interface java.util.Set
add
in class java.util.AbstractCollection
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
remove
in interface java.util.Set
remove
in class java.util.AbstractCollection
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.Set
clear
in class java.util.AbstractCollection
public java.lang.Object get(int index)
get
in interface IndexedSet
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()
)public int indexOf(java.lang.Object o)
indexOf
in interface IndexedSet
public java.lang.Object clone()
clone
in class java.lang.Object
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |