|
|||||||||
| 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.Collectionsize in interface java.util.Setsize in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Setiterator in class java.util.AbstractCollectionpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in interface java.util.Setcontains in class java.util.AbstractCollectionpublic boolean add(java.lang.Object o)
add in interface java.util.Collectionadd in interface java.util.Setadd in class java.util.AbstractCollectionpublic boolean remove(java.lang.Object o)
remove in interface java.util.Collectionremove in interface java.util.Setremove in class java.util.AbstractCollectionpublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Setclear in class java.util.AbstractCollectionpublic java.lang.Object get(int index)
get in interface IndexedSetjava.lang.IndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size())public int indexOf(java.lang.Object o)
indexOf in interface IndexedSetpublic java.lang.Object clone()
clone in class java.lang.Objectpublic static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||