public class IndexMap
extends java.lang.Object
Class IndexMap is a map whose keys are a bounded set of
non-negative integers and whose values are integers.
Class IndexMap supports a clear() method, but it does not
support a remove() method.
Class IndexMap is not thread-safe.
| Constructor and Description |
|---|
IndexMap(int maxKey,
int nil)
Creates a new instance of
IndexMap whose nil() method
will return the specified nil value. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all key-value pairs from the map.
|
int |
enumeratedKey(int index)
Returns the specified key in an enumeration of the keys in the map.
|
int |
enumeratedValue(int index)
Returns the value associated with the specified key
in an enumeration of the keys in the map.
|
int |
get(int key)
Returns the value associated with the specified key, or
this.nil() if the specified key is not contained in the map. |
int |
maxKey()
Returns the maximum key.
|
int |
nil()
Returns the value that is returned by
this.get() if
a key has no assigned value. |
int |
put(int key,
int value)
Adds the specified key and value to the map.
|
int |
size()
Returns the number of key-value pairs in the map.
|
java.lang.String |
toString()
Returns a string representation of
this. |
public IndexMap(int maxKey,
int nil)
IndexMap whose nil() method
will return the specified nil value.maxKey - the maximum keynil - the value that will be returned by the instance's
get() method if a key has no assigned valuejava.lang.IllegalArgumentException - if maxKey < 0public int nil()
this.get() if
a key has no assigned value.this.get() if
a key has no assigned valuepublic int put(int key,
int value)
key - the keyvalue - the valuekey, or
this.nil() if no such previous value existsjava.lang.IllegalArgumentException - if value == this.nil()java.lang.IndexOutOfBoundsException - if
key < 0 || key > this.maxKey()public int get(int key)
this.nil() if the specified key is not contained in the map.key - the keythis.nil() if the specified key is not contained in the map.java.lang.IndexOutOfBoundsException - if
key < 0 || key > this.maxKey()public int size()
public int maxKey()
public void clear()
public int enumeratedKey(int index)
index - an index of an element in the enumerationjava.lang.IndexOutOfBoundsException - if
index < 0 || index >= this.size()public int enumeratedValue(int index)
(index >= 0 && index < this.size()), then the returned value
will satisfy:
this.get(this.enumeratedKey(index)==this.enumeratedValue(index).index - an index of an element in the enumerationjava.lang.IndexOutOfBoundsException - if
index < 0 || index >= this.size()public java.lang.String toString()
this. The exact
details of the representation are unspecified and subject to change.toString in class java.lang.Objectthis.