| java.lang.Object org.apache.commons.collections.map.SingletonMap
SingletonMap | public class SingletonMap implements OrderedMap,BoundedMap,KeyValue,Serializable,Cloneable(Code) | | 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
SingletonMap.mapIterator() - the
KeyValue interface (just cast - no object creation)
since: Commons Collections 3.1 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Stephen Colebourne |
Method Summary | |
public void | clear() Unsupported operation. | public Object | clone() Clones the map without cloning the key or value. | public boolean | containsKey(Object key) Checks whether the map contains the specified key. | public boolean | containsValue(Object value) Checks whether the map contains the specified value. | public Set | entrySet() Gets the entrySet view of the map. | public boolean | equals(Object obj) Compares this map with another. | public Object | firstKey() Gets the first (and only) key in the map. | public Object | get(Object key) Gets the value mapped to the key specified. | public Object | getKey() Gets the key. | public Object | getValue() Gets the value. | public int | hashCode() Gets the standard Map hashCode. | public 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. | public boolean | isFull() Is the map currently full, always true. | public Set | keySet() Gets the unmodifiable keySet view of the map. | public Object | lastKey() Gets the last (and only) key in the map. | 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. | public int | maxSize() Gets the maximum size of the map, always 1. | public Object | nextKey(Object key) Gets the next key after the key specified, always null. | public OrderedMapIterator | orderedMapIterator() Obtains an OrderedMapIterator over the map. | public Object | previousKey(Object key) Gets the previous key before the key specified, always null. | public Object | put(Object key, Object value) Puts a key-value mapping into this map where the key must match the existing key. | public void | putAll(Map map) Puts the values from the specified map into this map. | public Object | remove(Object key) Unsupported operation. | public Object | setValue(Object value) Sets the value. | public int | size() Gets the size of the map, always 1. | public String | toString() Gets the map as a String. | public Collection | values() Gets the unmodifiable values view of the map. |
SingletonMap | public SingletonMap()(Code) | | Constructor that creates a map of null to null .
|
SingletonMap | public SingletonMap(Object key, Object value)(Code) | | Constructor specifying the key and value.
Parameters: key - the key to use Parameters: value - the value to use |
SingletonMap | public SingletonMap(KeyValue keyValue)(Code) | | Constructor specifying the key and value as a KeyValue .
Parameters: keyValue - the key value pair to use |
SingletonMap | public SingletonMap(Map.Entry mapEntry)(Code) | | Constructor specifying the key and value as a MapEntry .
Parameters: mapEntry - the mapEntry to use |
clear | public void clear()(Code) | | Unsupported operation.
|
clone | public Object clone()(Code) | | Clones the map without cloning the key or value.
a shallow clone |
containsKey | public boolean containsKey(Object key)(Code) | | Checks whether the map contains the specified key.
Parameters: key - the key to search for true if the map contains the key |
containsValue | public boolean containsValue(Object value)(Code) | | Checks whether the map contains the specified value.
Parameters: value - the value to search for true if the map contains the key |
entrySet | public Set entrySet()(Code) | | Gets the entrySet view of the map.
Changes made via setValue affect this map.
To simply iterate through the entries, use
SingletonMap.mapIterator() .
the entrySet view |
equals | public boolean equals(Object obj)(Code) | | Compares this map with another.
Parameters: obj - the object to compare to true if equal |
firstKey | public Object firstKey()(Code) | | Gets the first (and only) key in the map.
the key |
get | public Object get(Object key)(Code) | | Gets the value mapped to the key specified.
Parameters: key - the key the mapped value, null if no match |
getValue | public Object getValue()(Code) | | Gets the value.
the value |
hashCode | public int hashCode()(Code) | | Gets the standard Map hashCode.
the hash code defined in the Map interface |
isEmpty | public boolean isEmpty()(Code) | | Checks whether the map is currently empty, which it never is.
false always |
isEqualKey | protected boolean isEqualKey(Object key)(Code) | | Compares the specified key to the stored key.
Parameters: key - the key to compare true if equal |
isEqualValue | protected boolean isEqualValue(Object value)(Code) | | Compares the specified value to the stored value.
Parameters: value - the value to compare true if equal |
isFull | public boolean isFull()(Code) | | Is the map currently full, always true.
true always |
keySet | public Set keySet()(Code) | | Gets the unmodifiable keySet view of the map.
Changes made to the view affect this map.
To simply iterate through the keys, use
SingletonMap.mapIterator() .
the keySet view |
lastKey | public Object lastKey()(Code) | | Gets the last (and only) key in the map.
the key |
mapIterator | public MapIterator mapIterator()(Code) | | 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.
the map iterator |
maxSize | public int maxSize()(Code) | | Gets the maximum size of the map, always 1.
1 always |
nextKey | public Object nextKey(Object key)(Code) | | Gets the next key after the key specified, always null.
Parameters: key - the next key null always |
orderedMapIterator | public OrderedMapIterator orderedMapIterator()(Code) | | Obtains an OrderedMapIterator over the map.
A ordered map iterator is an efficient way of iterating over maps
in both directions.
an ordered map iterator |
previousKey | public Object previousKey(Object key)(Code) | | Gets the previous key before the key specified, always null.
Parameters: key - the next key null always |
put | public Object put(Object key, Object value)(Code) | | 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.
Parameters: key - the key to set, must be the key of the map Parameters: value - the value to set the value previously mapped to this key, null if none throws: IllegalArgumentException - if the key does not match |
putAll | public void putAll(Map map)(Code) | | 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.
Parameters: map - the map to add, must be size 0 or 1, and the key must match throws: NullPointerException - if the map is null throws: IllegalArgumentException - if the key does not match |
setValue | public Object setValue(Object value)(Code) | | Sets the value.
Parameters: value - the new value to set the old value |
size | public int size()(Code) | | Gets the size of the map, always 1.
the size of 1 |
toString | public String toString()(Code) | | Gets the map as a String.
a string version of the map |
values | public Collection values()(Code) | | Gets the unmodifiable values view of the map.
Changes made to the view affect this map.
To simply iterate through the values, use
SingletonMap.mapIterator() .
the values view |
|
|