public class IndexSet
extends java.lang.Object
Class IndexSet is a set that stores non-negative indices that are
less than or equal to a specified maximum value.
Class IndexSet supports a clear() method, but it does not
support a remove() method.
Class IndexSet is not thread-safe.
| Constructor and Description |
|---|
IndexSet(int max)
Creates a new instance of
IndexSet that can contain
non-negative integer indices that are less than or equal to the specified
maximum value. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int element)
Adds the specified element to the set.
|
void |
clear()
Removes all elements from the set.
|
boolean |
contains(int element)
Returns
true if the set contains the specified element,
and returns false otherwise. |
int |
enumeratedValue(int enumIndex)
Returns the specified element in an enumeration of the elements in the
set.
|
int |
maxPermittedElement()
Returns the maximum permitted element in the set.
|
int |
size()
Returns the number of elements in this set.
|
int[] |
toArray()
Returns an array containing the elements in this set.
|
java.lang.String |
toString()
Returns
java.util.Arrays.toString(this.toArray()). |
public IndexSet(int max)
IndexSet that can contain
non-negative integer indices that are less than or equal to the specified
maximum value.max - the maximum element that is permitted in the set.java.lang.IllegalArgumentException - if max < 0public boolean add(int element)
element - an element to add to this set.true if the set was changed by the operation, and
false otherwise.java.lang.IndexOutOfBoundsException - if
index < 0 || index > this.maxPermittedIndex()public boolean contains(int element)
true if the set contains the specified element,
and returns false otherwise.element - an elementtrue if the set contains the specified elementjava.lang.IndexOutOfBoundsException - if
index < 0 || index > this.maxPermittedIndex()public int size()
public int maxPermittedElement()
public void clear()
public int enumeratedValue(int enumIndex)
enumIndex - an index of an element in the enumerationjava.lang.IndexOutOfBoundsException - if
enumIndex < 0 || enumIndex >= this.size()public int[] toArray()
public java.lang.String toString()
java.util.Arrays.toString(this.toArray()).toString in class java.lang.Objectjava.util.Arrays.toString(this.toArray())