org.apache.commons.collections.map
Class SingletonMap
java.lang.Object
org.apache.commons.collections.map.SingletonMap
- Cloneable, IterableMap, Map, BoundedMap, KeyValue, OrderedMap, Serializable
public class SingletonMap
extends java.lang.Object
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:
- normal Map methods and views
- the
MapIterator
, see mapIterator()
- the
KeyValue
interface (just cast - no object creation)
$Revision: 1.1 $ $Date: 2004/04/09 14:46:35 $SingletonMap() - Constructor that creates a map of
null to null .
|
SingletonMap(Map map) - Constructor copying elements from another map.
|
SingletonMap(Map.Entry entry) - Constructor specifying the key and value as a
MapEntry .
|
SingletonMap(Object key, Object value) - Constructor specifying the key and value.
|
SingletonMap(KeyValue keyValue) - Constructor specifying the key and value as a
KeyValue .
|
void | clear() - Unsupported operation.
|
Object | clone() - Clones the map without cloning the key or value.
|
boolean | containsKey(Object key) - Checks whether the map contains the specified key.
|
boolean | containsValue(Object value) - Checks whether the map contains the specified value.
|
Set | entrySet() - Gets the entrySet view of the map.
|
boolean | equals(Object obj) - Compares this map with another.
|
Object | firstKey() - Gets the first (and only) key in the map.
|
Object | get(Object key) - Gets the value mapped to the key specified.
|
Object | getKey() - Gets the key.
|
Object | getValue() - Gets the value.
|
int | hashCode() - Gets the standard Map hashCode.
|
boolean | isEmpty() - Checks whether the map is currently empty, which it never is.
|
protected boolean | isEqualKey(Object key) - Compares the specified key to the stored key.
|
protected boolean | isEqualValue(Object value) - Compares the specified value to the stored value.
|
boolean | isFull() - Is the map currently full, always true.
|
Set | keySet() - Gets the unmodifiable keySet view of the map.
|
Object | lastKey() - Gets the last (and only) key in the map.
|
MapIterator | mapIterator() - Gets an iterator over the map.
|
int | maxSize() - Gets the maximum size of the map, always 1.
|
Object | nextKey(Object key) - Gets the next key after the key specified, always null.
|
OrderedMapIterator | orderedMapIterator() - Obtains an
OrderedMapIterator over the map.
|
Object | previousKey(Object key) - Gets the previous key before the key specified, always null.
|
Object | put(Object key, Object value) - Puts a key-value mapping into this map where the key must match the existing key.
|
void | putAll(Map map) - Puts the values from the specified map into this map.
|
Object | remove(Object key) - Unsupported operation.
|
Object | setValue(Object value) - Sets the value.
|
int | size() - Gets the size of the map, always 1.
|
String | toString() - Gets the map as a String.
|
Collection | values() - Gets the unmodifiable values view of the map.
|
SingletonMap
public SingletonMap()
Constructor that creates a map of null
to null
.
SingletonMap
public SingletonMap(Map map)
Constructor copying elements from another map.
map
- the map to copy, must be size 1
SingletonMap
public SingletonMap(Map.Entry entry)
Constructor specifying the key and value as a MapEntry
.
SingletonMap
public SingletonMap(Object key,
Object value)
Constructor specifying the key and value.
key
- the key to usevalue
- the value to use
SingletonMap
public SingletonMap(KeyValue keyValue)
Constructor specifying the key and value as a KeyValue
.
keyValue
- the key value pair to use
clear
public void clear()
Unsupported operation.
clone
public Object clone()
Clones the map without cloning the key or value.
containsKey
public boolean containsKey(Object key)
Checks whether the map contains the specified key.
key
- the key to search for
- true if the map contains the key
containsValue
public boolean containsValue(Object value)
Checks whether the map contains the specified value.
value
- the value to search for
- true if the map contains the key
entrySet
public Set entrySet()
Gets the entrySet view of the map.
Changes made via
setValue
affect this map.
To simply iterate through the entries, use
mapIterator()
.
equals
public boolean equals(Object obj)
Compares this map with another.
obj
- the object to compare to
firstKey
public Object firstKey()
Gets the first (and only) key in the map.
- firstKey in interface OrderedMap
get
public Object get(Object key)
Gets the value mapped to the key specified.
- the mapped value, null if no match
getKey
public Object getKey()
Gets the key.
- getKey in interface KeyValue
hashCode
public int hashCode()
Gets the standard Map hashCode.
- the hash code defined in the Map interface
isEmpty
public boolean isEmpty()
Checks whether the map is currently empty, which it never is.
isEqualKey
protected boolean isEqualKey(Object key)
Compares the specified key to the stored key.
isEqualValue
protected boolean isEqualValue(Object value)
Compares the specified value to the stored value.
value
- the value to compare
isFull
public boolean isFull()
Is the map currently full, always true.
- isFull in interface BoundedMap
keySet
public Set keySet()
Gets the unmodifiable keySet view of the map.
Changes made to the view affect this map.
To simply iterate through the keys, use
mapIterator()
.
lastKey
public Object lastKey()
Gets the last (and only) key in the map.
- lastKey in interface OrderedMap
mapIterator
public MapIterator 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.
- mapIterator in interface IterableMap
maxSize
public int maxSize()
Gets the maximum size of the map, always 1.
- maxSize in interface BoundedMap
nextKey
public Object nextKey(Object key)
Gets the next key after the key specified, always null.
- nextKey in interface OrderedMap
orderedMapIterator
public OrderedMapIterator orderedMapIterator()
Obtains an
OrderedMapIterator
over the map.
A ordered map iterator is an efficient way of iterating over maps
in both directions.
- orderedMapIterator in interface OrderedMap
previousKey
public Object previousKey(Object key)
Gets the previous key before the key specified, always null.
- previousKey in interface OrderedMap
put
public Object put(Object key,
Object value)
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 mapvalue
- the value to set
- the value previously mapped to this key, null if none
putAll
public void putAll(Map map)
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
remove
public Object remove(Object key)
Unsupported operation.
key
- the mapping to remove
- the value mapped to the removed key, null if key not in map
setValue
public Object setValue(Object value)
Sets the value.
value
- the new value to set
size
public int size()
Gets the size of the map, always 1.
toString
public String toString()
Gets the map as a String.
- a string version of the map
values
public Collection values()
Gets the unmodifiable values view of the map.
Changes made to the view affect this map.
To simply iterate through the values, use
mapIterator()
.
Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.