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 succeed 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)
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final K | key
Singleton key |
| private static final long | serialVersionUID
Serialization version |
| private V | value
Singleton value |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SingletonMap(final K
the key to use key, final V the value to use value)Constructor specifying the key and value. |
| public | SingletonMap(final KeyValue<K, V>
the key value pair to use keyValue)Constructor specifying the key and value as a |
| public | SingletonMap(final Map.
the mapEntry to use mapEntryConstructor specifying the key and value as a |
| public | SingletonMap(final Map<? extends K, ? extends V>
the map to copy, must be size 1 map)Constructor copying elements from another map. |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Implements java. |
| public SingletonMap | Returns: a shallow cloneOverrides java. |
| public boolean | Returns: true if the map contains the keythe key to search for key)Implements java. |
| public boolean | Returns: true if the map contains the keythe value to search for value)Implements java. |
| public Set | Returns: the entrySet viewImplements java. |
| public boolean | Returns: true if equalthe object to compare to obj)Overrides java. Implements java. |
| public K | Returns: the keyImplements org. |
| public V | Returns: the mapped value, null if no matchthe key key)Implements java. |
| public K | |
| public V | Returns: the valueImplements org. |
| public int | Returns: the hash code defined in the Map interfaceOverrides java. Implements java. |
| public boolean | Returns: false alwaysImplements java. |
| protected boolean | Returns: true if equalthe key to compare key)Compares the specified key to the stored key. |
| protected boolean | Returns: true if equalthe value to compare value)Compares the specified value to the stored value. |
| public boolean | Returns: true alwaysImplements org. |
| public Set | Returns: the keySet viewImplements java. |
| public K | Returns: the keyImplements org. |
| public OrderedMapIterator | mapIterator()
Implements org. OrderedMapIterator over the map.
|
| public int | Returns: 1 alwaysImplements org. |
| public K | Returns: null alwaysthe next key key)Implements org. |
| public K | Returns: null alwaysthe next key key)Implements org. |
| public V | Returns: the value previously mapped to this key, null if nonethe key to set, must be the key of the map key, final V the value to set value)Implements java. |
| public void | putAll(final Map<? extends K, ? extends V>
the map to add, must be size 0 or 1, and the key must match map)Implements java. |
| public V | Returns: the value mapped to the removed key, null if key not in mapthe mapping to remove key)Implements java. |
| public V | |
| public int | Returns: the size of 1Implements java. |
| public String | Returns: a string version of the mapOverrides java. |
| public Collection | Returns: the values viewImplements java. |
| key | back to summary |
|---|---|
| private final K key Singleton key | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| value | back to summary |
|---|---|
| private V value Singleton value | |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap() Constructor that creates a map of | |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap(final K key, final V value) Constructor specifying the key and value.
| |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap(final KeyValue<K, V> keyValue) Constructor specifying the key and value as a
| |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap(final Map. Constructor specifying the key and value as a | |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap(final Map<? extends K, ? extends V> map) Constructor copying elements from another map.
| |
| clear | back to summary |
|---|---|
| public void clear() Implements java. Unsupported operation.
| |
| clone | back to summary |
|---|---|
| public SingletonMap Overrides java. Clones the map without cloning the key or value.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(final Object key) Implements java. Checks whether the map contains the specified key. | |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(final Object value) Implements java. Checks whether the map contains the specified value. | |
| entrySet | back to summary |
|---|---|
| public Set Implements java. Gets the entrySet view of the map.
Changes made via | |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Implements java. Compares this map with another. | |
| firstKey | back to summary |
|---|---|
| public K firstKey() Implements org. Gets the first (and only) key in the map.
| |
| get | back to summary |
|---|---|
| public V get(final Object key) Implements java. Gets the value mapped to the key specified. | |
| getKey | back to summary |
|---|---|
| public K getKey() Implements org. Gets the key.
| |
| getValue | back to summary |
|---|---|
| public V getValue() Implements org. Gets the value.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Gets the standard Map hashCode.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Checks whether the map is currently empty, which it never is.
| |
| isEqualKey | back to summary |
|---|---|
| protected boolean isEqualKey(final Object key) Compares the specified key to the stored key.
| |
| isEqualValue | back to summary |
|---|---|
| protected boolean isEqualValue(final Object value) Compares the specified value to the stored value.
| |
| isFull | back to summary |
|---|---|
| public boolean isFull() Implements org. Is the map currently full, always true.
| |
| keySet | back to summary |
|---|---|
| public Set Implements java. Gets the unmodifiable keySet view of the map.
Changes made to the view affect this map.
To simply iterate through the keys, use | |
| lastKey | back to summary |
|---|---|
| public K lastKey() Implements org. Gets the last (and only) key in the map.
| |
| mapIterator | back to summary |
|---|---|
| public OrderedMapIterator Implements org. Doc from org. Obtains an A ordered map iterator is an efficient way of iterating over maps in both directions.
| |
| maxSize | back to summary |
|---|---|
| public int maxSize() Implements org. Gets the maximum size of the map, always 1.
| |
| nextKey | back to summary |
|---|---|
| public K nextKey(final K key) Implements org. Gets the next key after the key specified, always null.
| |
| previousKey | back to summary |
|---|---|
| public K previousKey(final K key) Implements org. Gets the previous key before the key specified, always null.
| |
| put | back to summary |
|---|---|
| public V put(final K key, final V value) Implements java. 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.
| |
| putAll | back to summary |
|---|---|
| public void putAll(final Map<? extends K, ? extends V> map) Implements java. 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.
| |
| remove | back to summary |
|---|---|
| public V remove(final Object key) Implements java. Unsupported operation.
| |
| setValue | back to summary |
|---|---|
| public V setValue(final V value) Sets the value.
| |
| size | back to summary |
|---|---|
| public int size() Implements java. Gets the size of the map, always 1.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Gets the map as a String. | |
| values | back to summary |
|---|---|
| public Collection Implements java. Gets the unmodifiable values view of the map.
Changes made to the view affect this map.
To simply iterate through the values, use
| |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private boolean | |
| private final SingletonMap |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public K | getKey()
Implements org. next().
|
| public V | getValue()
Implements org. next().
|
| public boolean | hasNext()
Implements org. |
| public boolean | hasPrevious()
Implements org. |
| public K | next()
Implements org. Map.
|
| public K | previous()
Implements org. Map.
|
| public void | remove()
Overrides default java. Implements org. Map (optional operation).
|
| public void | reset()
Implements org. |
| public V | setValue(final V
the new value value)Implements org. |
| public String |
| canGetSet | back to summary |
|---|---|
| private boolean canGetSet | |
| hasNext | back to summary |
|---|---|
| private boolean hasNext | |
| parent | back to summary |
|---|---|
| private final SingletonMap<K, V> parent | |
| SingletonMapIterator | back to summary |
|---|---|
| pack-priv SingletonMapIterator(final SingletonMap<K, V> parent) | |
| getKey | back to summary |
|---|---|
| public K getKey() Implements org. Doc from org. Gets the current key, which is the key returned by the last call
to
| |
| getValue | back to summary |
|---|---|
| public V getValue() Implements org. Doc from org. Gets the current value, which is the value associated with the last key
returned by
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements org. Doc from org. Checks to see if there are more entries still to be iterated.
| |
| hasPrevious | back to summary |
|---|---|
| public boolean hasPrevious() Implements org. Doc from org. Checks to see if there is a previous entry that can be iterated to.
| |
| next | back to summary |
|---|---|
| public K next() Implements org. Doc from org. Gets the next key from the
| |
| previous | back to summary |
|---|---|
| public K previous() Implements org. Doc from org. Gets the previous key from the
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Implements org. Doc from org. Removes the last returned key from the underlying
This method can be called once per call to
| |
| reset | back to summary |
|---|---|
| public void reset() Implements org. Doc from org. Resets the iterator back to the position at which the iterator was created.
| |
| setValue | back to summary |
|---|---|
| public V setValue(final V value) Implements org. Doc from org. Sets the value associated with the current key (optional operation).
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private final SingletonMap | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides java. Implements java. |
| public boolean | contains(final Object
element whose presence in this set is to be tested object)Overrides java. Implements java. true if this set contains the specified element.
|
| public boolean | isEmpty()
Overrides java. Implements java. true if this set contains no elements.
|
| public Iterator | iterator()
Implements abstract java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| parent | back to summary |
|---|---|
| private final SingletonMap<?, V> parent | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| SingletonValues | back to summary |
|---|---|
| pack-priv SingletonValues(final SingletonMap<?, V> parent) | |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the elements from this set (optional operation). The set will be empty after this call returns.
| |
| contains | back to summary |
|---|---|
| public boolean contains(final Object object) Overrides java. Implements java. Doc from java. Returns | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Overrides java. Implements java. Doc from java. Returns
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |