java.lang.Object | |
↳ | org.apache.commons.collections.map.SingletonMap |
A Map
implementation that holds a single item and is fixed size.
The single key/value pair is specified at creation.
The map is fixed size so any action that would change the size is disallowed.
However, the put
or setValue
methods can change
the value associated with the key.
If trying to remove or clear the map, an UnsupportedOperationException is thrown. If trying to put a new mapping into the map, an IllegalArgumentException is thrown. The put method will only suceed if the key specified is the same as the singleton key.
The key and value can be obtained by:
MapIterator
, see mapIterator()
KeyValue
interface (just cast - no object creation)
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that creates a map of
null to null . | |||||||||||
Constructor specifying the key and value.
| |||||||||||
Constructor specifying the key and value as a
KeyValue . | |||||||||||
Constructor specifying the key and value as a
MapEntry . | |||||||||||
Constructor copying elements from another map.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Unsupported operation.
| |||||||||||
Clones the map without cloning the key or value.
| |||||||||||
Checks whether the map contains the specified key.
| |||||||||||
Checks whether the map contains the specified value.
| |||||||||||
Gets the entrySet view of the map.
| |||||||||||
Compares this map with another.
| |||||||||||
Gets the first (and only) key in the map.
| |||||||||||
Gets the value mapped to the key specified.
| |||||||||||
Gets the key.
| |||||||||||
Gets the value.
| |||||||||||
Gets the standard Map hashCode.
| |||||||||||
Checks whether the map is currently empty, which it never is.
| |||||||||||
Is the map currently full, always true.
| |||||||||||
Gets the unmodifiable keySet view of the map.
| |||||||||||
Gets the last (and only) key in the map.
| |||||||||||
Gets an iterator over the map.
| |||||||||||
Gets the maximum size of the map, always 1.
| |||||||||||
Gets the next key after the key specified, always null.
| |||||||||||
Obtains an
OrderedMapIterator over the map. | |||||||||||
Gets the previous key before the key specified, always null.
| |||||||||||
Puts a key-value mapping into this map where the key must match the existing key.
| |||||||||||
Puts the values from the specified map into this map.
| |||||||||||
Unsupported operation.
| |||||||||||
Sets the value.
| |||||||||||
Gets the size of the map, always 1.
| |||||||||||
Gets the map as a String.
| |||||||||||
Gets the unmodifiable values view of the map.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares the specified key to the stored key.
| |||||||||||
Compares the specified value to the stored value.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
org.apache.commons.collections.BoundedMap
| |||||||||||
From interface
org.apache.commons.collections.IterableMap
| |||||||||||
From interface
org.apache.commons.collections.KeyValue
| |||||||||||
From interface
org.apache.commons.collections.OrderedMap
|
Constructor that creates a map of null
to null
.
Constructor specifying the key and value.
key | the key to use |
---|---|
value | the value to use |
Constructor specifying the key and value as a KeyValue
.
keyValue | the key value pair to use |
---|
Constructor specifying the key and value as a MapEntry
.
mapEntry | the mapEntry to use |
---|
Constructor copying elements from another map.
map | the map to copy, must be size 1 |
---|
NullPointerException | if the map is null |
---|---|
IllegalArgumentException | if the size is not 1 |
Unsupported operation.
Checks whether the map contains the specified key.
key | the key to search for |
---|
Checks whether the map contains the specified value.
value | the value to search for |
---|
Gets the entrySet view of the map.
Changes made via setValue
affect this map.
To simply iterate through the entries, use mapIterator()
.
Compares this map with another.
obj | the object to compare to |
---|
Gets the value mapped to the key specified.
key | the key |
---|
Gets the standard Map hashCode.
Checks whether the map is currently empty, which it never is.
Is the map currently full, always true.
Gets the unmodifiable keySet view of the map.
Changes made to the view affect this map.
To simply iterate through the keys, use mapIterator()
.
Gets an iterator over the map.
Changes made to the iterator using setValue
affect this map.
The remove
method is unsupported.
A MapIterator returns the keys in the map. It also provides convenient methods to get the key and value, and set the value. It avoids the need to create an entrySet/keySet/values object. It also avoids creating the Map Entry object.
Gets the maximum size of the map, always 1.
Gets the next key after the key specified, always null.
key | the next key |
---|
Obtains an OrderedMapIterator
over the map.
A ordered map iterator is an efficient way of iterating over maps in both directions.
Gets the previous key before the key specified, always null.
key | the next key |
---|
Puts a key-value mapping into this map where the key must match the existing key.
An IllegalArgumentException is thrown if the key does not match as the map is fixed size.
key | the key to set, must be the key of the map |
---|---|
value | the value to set |
IllegalArgumentException | if the key does not match |
---|
Puts the values from the specified map into this map.
The map must be of size 0 or size 1. If it is size 1, the key must match the key of this map otherwise an IllegalArgumentException is thrown.
map | the map to add, must be size 0 or 1, and the key must match |
---|
NullPointerException | if the map is null |
---|---|
IllegalArgumentException | if the key does not match |
Unsupported operation.
key | the mapping to remove |
---|
UnsupportedOperationException | always |
---|
Sets the value.
value | the new value to set |
---|
Gets the size of the map, always 1.
Gets the unmodifiable values view of the map.
Changes made to the view affect this map.
To simply iterate through the values, use mapIterator()
.
Compares the specified key to the stored key.
key | the key to compare |
---|
Compares the specified value to the stored value.
value | the value to compare |
---|