Class SingletonMap<K,V> 
- Type Parameters:
- K- the type of the keys in this map
- V- the type of the values in this map
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<K,,- V> - BoundedMap<K,,- V> - Get<K,,- V> - IterableGet<K,,- V> - IterableMap<K,,- V> - KeyValue<K,,- V> - OrderedMap<K,,- V> - Put<K,- V> 
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:
- normal Map methods and views
- the MapIterator, seemapIterator()
- the KeyValueinterface (just cast - no object creation)
- Since:
- 3.1
- See Also:
- 
Nested Class Summary
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor that creates a map ofnulltonull.SingletonMap(Map.Entry<? extends K, ? extends V> mapEntry) Constructor specifying the key and value as aMapEntry.SingletonMap(Map<? extends K, ? extends V> map) Constructor copying elements from another map.SingletonMap(K key, V value) Constructor specifying the key and value.SingletonMap(KeyValue<K, V> keyValue) Constructor specifying the key and value as aKeyValue.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Unsupported operation.clone()Clones the map without cloning the key or value.booleancontainsKey(Object key) Checks whether the map contains the specified key.booleancontainsValue(Object value) Checks whether the map contains the specified value.entrySet()Gets the entrySet view of the map.booleanCompares this map with another.firstKey()Gets the first (and only) key in the map.Gets the value mapped to the key specified.getKey()Gets the key.getValue()Gets the value.inthashCode()Gets the standard Map hashCode.booleanisEmpty()Checks whether the map is currently empty, which it never is.protected booleanisEqualKey(Object key) Compares the specified key to the stored key.protected booleanisEqualValue(Object value) Compares the specified value to the stored value.booleanisFull()Is the map currently full, always true.keySet()Gets the unmodifiable keySet view of the map.lastKey()Gets the last (and only) key in the map.Obtains anOrderedMapIteratorover the map.intmaxSize()Gets the maximum size of the map, always 1.Gets the next key after the key specified, always null.previousKey(K key) 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.voidPuts the values from the specified map into this map.Unsupported operation.Sets the value.intsize()Gets the size of the map, always 1.toString()Gets the map as a String.values()Gets the unmodifiable values view of the map.Methods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Constructor Details- 
SingletonMappublic SingletonMap()Constructor that creates a map ofnulltonull.
- 
SingletonMapConstructor specifying the key and value.- Parameters:
- key- the key to use
- value- the value to use
 
- 
SingletonMapConstructor specifying the key and value as aKeyValue.- Parameters:
- keyValue- the key value pair to use
 
- 
SingletonMapConstructor specifying the key and value as aMapEntry.- Parameters:
- mapEntry- the mapEntry to use
 
- 
SingletonMapConstructor copying elements from another map.- Parameters:
- map- the map to copy, must be size 1
- Throws:
- NullPointerException- if the map is null
- IllegalArgumentException- if the size is not 1
 
 
- 
- 
Method Details- 
clear
- 
clone
- 
containsKeyChecks whether the map contains the specified key.- Specified by:
- containsKeyin interface- Get<K,- V> 
- Specified by:
- containsKeyin interface- Map<K,- V> 
- Parameters:
- key- the key to search for
- Returns:
- true if the map contains the key
- See Also:
 
- 
containsValueChecks whether the map contains the specified value.- Specified by:
- containsValuein interface- Get<K,- V> 
- Specified by:
- containsValuein interface- Map<K,- V> 
- Parameters:
- value- the value to search for
- Returns:
- true if the map contains the key
- See Also:
 
- 
entrySetGets the entrySet view of the map. Changes made viasetValueaffect this map. To simply iterate through the entries, usemapIterator().
- 
equals
- 
firstKey
- 
get
- 
getKey
- 
getValue
- 
hashCode
- 
isEmpty
- 
isEqualKeyCompares the specified key to the stored key.- Parameters:
- key- the key to compare
- Returns:
- true if equal
 
- 
isEqualValueCompares the specified value to the stored value.- Parameters:
- value- the value to compare
- Returns:
- true if equal
 
- 
isFullIs the map currently full, always true.- Specified by:
- isFullin interface- BoundedMap<K,- V> 
- Returns:
- true always
 
- 
keySet
- 
lastKey
- 
mapIteratorObtains anOrderedMapIteratorover the map.An ordered map iterator is an efficient way of iterating over maps in both directions. - Specified by:
- mapIteratorin interface- IterableGet<K,- V> 
- Specified by:
- mapIteratorin interface- OrderedMap<K,- V> 
- Returns:
- a map iterator
 
- 
maxSizeGets the maximum size of the map, always 1.- Specified by:
- maxSizein interface- BoundedMap<K,- V> 
- Returns:
- 1 always
 
- 
nextKey
- 
previousKeyGets the previous key before the key specified, always null.- Specified by:
- previousKeyin interface- OrderedMap<K,- V> 
- Parameters:
- key- the next key
- Returns:
- null always
 
- 
putPuts 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. 
- 
putAllPuts 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. - Specified by:
- putAllin interface- Map<K,- V> 
- Specified by:
- putAllin interface- Put<K,- V> 
- Parameters:
- map- the map to add, must be size 0 or 1, and the key must match
- Throws:
- NullPointerException- if the map is null
- IllegalArgumentException- if the key does not match
- See Also:
 
- 
removeUnsupported operation.
- 
setValue
- 
size
- 
toString
- 
values
 
-