Class SingletonMap
- java.lang.Object
-
- org.apache.commons.collections.map.SingletonMap
-
- All Implemented Interfaces:
Serializable,Cloneable,Map,BoundedMap,IterableMap,KeyValue,OrderedMap
@Deprecated(since="2021-04-30") public class SingletonMap extends Object implements OrderedMap, BoundedMap, KeyValue, Serializable, Cloneable
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.AMapimplementation 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
putorsetValuemethods 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, seemapIterator() - the
KeyValueinterface (just cast - no object creation)
- Since:
- Commons Collections 3.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SingletonMap()Deprecated.Constructor that creates a map ofnulltonull.SingletonMap(Object key, Object value)Deprecated.Constructor specifying the key and value.SingletonMap(Map map)Deprecated.Constructor copying elements from another map.SingletonMap(Map.Entry mapEntry)Deprecated.Constructor specifying the key and value as aMapEntry.SingletonMap(KeyValue keyValue)Deprecated.Constructor specifying the key and value as aKeyValue.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Deprecated.Unsupported operation.Objectclone()Deprecated.Clones the map without cloning the key or value.booleancontainsKey(Object key)Deprecated.Checks whether the map contains the specified key.booleancontainsValue(Object value)Deprecated.Checks whether the map contains the specified value.SetentrySet()Deprecated.Gets the entrySet view of the map.booleanequals(Object obj)Deprecated.Compares this map with another.ObjectfirstKey()Deprecated.Gets the first (and only) key in the map.Objectget(Object key)Deprecated.Gets the value mapped to the key specified.ObjectgetKey()Deprecated.Gets the key.ObjectgetValue()Deprecated.Gets the value.inthashCode()Deprecated.Gets the standard Map hashCode.booleanisEmpty()Deprecated.Checks whether the map is currently empty, which it never is.booleanisFull()Deprecated.Is the map currently full, always true.SetkeySet()Deprecated.Gets the unmodifiable keySet view of the map.ObjectlastKey()Deprecated.Gets the last (and only) key in the map.MapIteratormapIterator()Deprecated.Gets an iterator over the map.intmaxSize()Deprecated.Gets the maximum size of the map, always 1.ObjectnextKey(Object key)Deprecated.Gets the next key after the key specified, always null.OrderedMapIteratororderedMapIterator()Deprecated.Obtains anOrderedMapIteratorover the map.ObjectpreviousKey(Object key)Deprecated.Gets the previous key before the key specified, always null.Objectput(Object key, Object value)Deprecated.Puts a key-value mapping into this map where the key must match the existing key.voidputAll(Map map)Deprecated.Puts the values from the specified map into this map.Objectremove(Object key)Deprecated.Unsupported operation.ObjectsetValue(Object value)Deprecated.Sets the value.intsize()Deprecated.Gets the size of the map, always 1.StringtoString()Deprecated.Gets the map as a String.Collectionvalues()Deprecated.Gets the unmodifiable values view of the map.-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
SingletonMap
public SingletonMap()
Deprecated.Constructor that creates a map ofnulltonull.
-
SingletonMap
public SingletonMap(Object key, Object value)
Deprecated.Constructor specifying the key and value.- Parameters:
key- the key to usevalue- the value to use
-
SingletonMap
public SingletonMap(KeyValue keyValue)
Deprecated.Constructor specifying the key and value as aKeyValue.- Parameters:
keyValue- the key value pair to use
-
SingletonMap
public SingletonMap(Map.Entry mapEntry)
Deprecated.Constructor specifying the key and value as aMapEntry.- Parameters:
mapEntry- the mapEntry to use
-
SingletonMap
public SingletonMap(Map map)
Deprecated.Constructor copying elements from another map.- Parameters:
map- the map to copy, must be size 1- Throws:
NullPointerException- if the map is nullIllegalArgumentException- if the size is not 1
-
-
Method Detail
-
getKey
public Object getKey()
Deprecated.Gets the key.
-
getValue
public Object getValue()
Deprecated.Gets the value.
-
setValue
public Object setValue(Object value)
Deprecated.Sets the value.- Parameters:
value- the new value to set- Returns:
- the old value
-
isFull
public boolean isFull()
Deprecated.Is the map currently full, always true.- Specified by:
isFullin interfaceBoundedMap- Returns:
- true always
-
maxSize
public int maxSize()
Deprecated.Gets the maximum size of the map, always 1.- Specified by:
maxSizein interfaceBoundedMap- Returns:
- 1 always
-
size
public int size()
Deprecated.Gets the size of the map, always 1.
-
isEmpty
public boolean isEmpty()
Deprecated.Checks whether the map is currently empty, which it never is.
-
containsKey
public boolean containsKey(Object key)
Deprecated.Checks whether the map contains the specified key.- Specified by:
containsKeyin interfaceMap- Parameters:
key- the key to search for- Returns:
- true if the map contains the key
-
containsValue
public boolean containsValue(Object value)
Deprecated.Checks whether the map contains the specified value.- Specified by:
containsValuein interfaceMap- Parameters:
value- the value to search for- Returns:
- true if the map contains the key
-
put
public Object put(Object key, Object value)
Deprecated.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.
- Specified by:
putin interfaceMap- Parameters:
key- the key to set, must be the key of the mapvalue- the value to set- Returns:
- the value previously mapped to this key, null if none
- Throws:
IllegalArgumentException- if the key does not match
-
putAll
public void putAll(Map map)
Deprecated.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.
- Specified by:
putAllin interfaceMap- Parameters:
map- the map to add, must be size 0 or 1, and the key must match- Throws:
NullPointerException- if the map is nullIllegalArgumentException- if the key does not match
-
remove
public Object remove(Object key)
Deprecated.Unsupported operation.- Specified by:
removein interfaceMap- Parameters:
key- the mapping to remove- Returns:
- the value mapped to the removed key, null if key not in map
- Throws:
UnsupportedOperationException- always
-
entrySet
public Set entrySet()
Deprecated.Gets the entrySet view of the map. Changes made viasetValueaffect this map. To simply iterate through the entries, usemapIterator().
-
keySet
public Set keySet()
Deprecated.Gets the unmodifiable keySet view of the map. Changes made to the view affect this map. To simply iterate through the keys, usemapIterator().
-
values
public Collection values()
Deprecated.Gets the unmodifiable values view of the map. Changes made to the view affect this map. To simply iterate through the values, usemapIterator().
-
mapIterator
public MapIterator mapIterator()
Deprecated.Gets an iterator over the map. Changes made to the iterator usingsetValueaffect this map. Theremovemethod 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.
- Specified by:
mapIteratorin interfaceIterableMap- Returns:
- the map iterator
-
orderedMapIterator
public OrderedMapIterator orderedMapIterator()
Deprecated.Obtains anOrderedMapIteratorover the map.A ordered map iterator is an efficient way of iterating over maps in both directions.
- Specified by:
orderedMapIteratorin interfaceOrderedMap- Returns:
- an ordered map iterator
-
firstKey
public Object firstKey()
Deprecated.Gets the first (and only) key in the map.- Specified by:
firstKeyin interfaceOrderedMap- Returns:
- the key
-
lastKey
public Object lastKey()
Deprecated.Gets the last (and only) key in the map.- Specified by:
lastKeyin interfaceOrderedMap- Returns:
- the key
-
nextKey
public Object nextKey(Object key)
Deprecated.Gets the next key after the key specified, always null.- Specified by:
nextKeyin interfaceOrderedMap- Parameters:
key- the next key- Returns:
- null always
-
previousKey
public Object previousKey(Object key)
Deprecated.Gets the previous key before the key specified, always null.- Specified by:
previousKeyin interfaceOrderedMap- Parameters:
key- the next key- Returns:
- null always
-
clone
public Object clone()
Deprecated.Clones the map without cloning the key or value.- Returns:
- a shallow clone
-
equals
public boolean equals(Object obj)
Deprecated.Compares this map with another.
-
hashCode
public int hashCode()
Deprecated.Gets the standard Map hashCode.
-
-