|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IndexedSet
Data structure that behaves like a set, except that its elements also have consecutive indices starting at zero. Different implementations may assign these indices in different ways: for example, according to the ordering on elements defined by a Comparator object, or according to the order in which objects were added. Indices are not guaranteed to remain stable when the IndexedSet is modified. In some implementations, adding or removing elements may change the indices of other elements.
IndexedSet extends the Set interface with additional methods
get
and indexOf
, which behave like the
corresponding methods in the List interface. Also, iterators over an
IndexedSet go in the order defined by the indices. The only thing that
invalidates an iterator is removing an element without going through the
iterator's remove
method. Notably, adding elements does
not invalidate iterators.
One advantage of using an IndexedSet is that you can sample an element uniformly at random in constant time (by getting the element at a random index n). Another is that you can iterate over it just by incrementing an integer index.
Nested Class Summary | |
---|---|
static class |
IndexedSet.EmptyIndexedSet
|
Field Summary | |
---|---|
static IndexedSet |
EMPTY_INDEXED_SET
An unmodifiable, empty indexed set. |
Method Summary | |
---|---|
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. |
Methods inherited from interface java.util.Set |
---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
Field Detail |
---|
static final IndexedSet EMPTY_INDEXED_SET
Method Detail |
---|
java.lang.Object get(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()
)int indexOf(java.lang.Object o)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |