# Class SingleEntryMap<K,V>

java.lang.Object
org.apache.cayenne.util.SingleEntryMap<K,V>

All Implemented Interfaces:
  `Serializable, Map<K,V>, Map.Entry<K,V>`

public class SingleEntryMap<K,V> extends Object implements Map<K,V>, Map.Entry<K,V>, Serializable
Optimized mutable single-entry map.

This implementation is compatible with general `Map` contract, including `Map.equals(Object)`, `Map.hashCode()` and `AbstractMap.toString()` implementations.

This Map can store only one key that is defined at creation time and can't be changed. This map will throw `IllegalArgumentException` on any put operation with the wrong key and return `null` on get.

This map will be effectively empty after putting null value.

Since:
  4.2
See Also:
  - Serialized Form

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface Map

  `Map.Entry<K,V>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SingleEntryMap(K key)`
  Create empty map
  `SingleEntryMap(K key, V value)`
  Create map with single key-value entry

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  `V`
  `compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)`
  `V`
  `computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)`
  `V`
  `computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)`
  `boolean`
  `containsKey(Object key)`
  `boolean`
  `containsValue(Object value)`
  `Set<Map.Entry<K,V>>`
  `entrySet()`
  `boolean`
  `equals(Object o)`
  `void`
  `forEach(BiConsumer<? super K, ? super V> action)`
  `V`
  `get(Object key)`
  `K`
  `getKey()`
  `V`
  `getOrDefault(Object key, V defaultValue)`
  `V`
  `getValue()`
  `int`
  `hashCode()`
  `boolean`
  `isEmpty()`
  `Set<K>`
  `keySet()`
  `V`
  `merge(K key, V newValue, BiFunction<? super V, ? super V, ? extends V> remappingFunction)`
  `V`
  `put(K key, V value)`
  `void`
  `putAll(Map<? extends K, ? extends V> map)`
  `V`
  `putIfAbsent(K key, V value)`
  `V`
  `remove(Object key)`
  `boolean`
  `remove(Object key, Object value)`
  `V`
  `replace(K key, V value)`
  `boolean`
  `replace(K key, V oldValue, V newValue)`
  `V`
  `setValue(V value)`
  `int`
  `size()`
  `String`
  `toString()`
  `Collection<V>`
  `values()`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Map

  `replaceAll`

- ## Constructor Details

  - ### SingleEntryMap

    public SingleEntryMap(K key)
    Create empty map
    Parameters:
      `key` - that can be stored in this map, can't be null

  - ### SingleEntryMap

    public SingleEntryMap(K key, V value)
    Create map with single key-value entry
    Parameters:
      `key` - that can be stored in this map, can't be null
      `value` - to store, if null map will be empty.

- ## Method Details

  - ### entrySet

    public Set<Map.Entry<K,V>> entrySet()
    Specified by:
      `entrySet` in interface `Map<K,V>`

  - ### containsKey

    public boolean containsKey(Object key)
    Specified by:
      `containsKey` in interface `Map<K,V>`

  - ### size

    public int size()
    Specified by:
      `size` in interface `Map<K,V>`

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `Map<K,V>`

  - ### containsValue

    public boolean containsValue(Object value)
    Specified by:
      `containsValue` in interface `Map<K,V>`

  - ### get

    public V get(Object key)
    Specified by:
      `get` in interface `Map<K,V>`

  - ### put

    public V put(K key, V value)
    Specified by:
      `put` in interface `Map<K,V>`

  - ### remove

    public V remove(Object key)
    Specified by:
      `remove` in interface `Map<K,V>`

  - ### putAll

    public void putAll(Map<? extends K, ? extends V> map)
    Specified by:
      `putAll` in interface `Map<K,V>`

  - ### clear

    public void clear()
    Specified by:
      `clear` in interface `Map<K,V>`

  - ### keySet

    public Set<K> keySet()
    Specified by:
      `keySet` in interface `Map<K,V>`

  - ### values

    public Collection<V> values()
    Specified by:
      `values` in interface `Map<K,V>`

  - ### getKey

    public K getKey()
    Specified by:
      `getKey` in interface `Map.Entry<K,V>`

  - ### getValue

    public V getValue()
    Specified by:
      `getValue` in interface `Map.Entry<K,V>`

  - ### setValue

    public V setValue(V value)
    Specified by:
      `setValue` in interface `Map.Entry<K,V>`

  - ### equals

    public boolean equals(Object o)
    Specified by:
      `equals` in interface `Map<K,V>`
    Specified by:
      `equals` in interface `Map.Entry<K,V>`
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Specified by:
      `hashCode` in interface `Map<K,V>`
    Specified by:
      `hashCode` in interface `Map.Entry<K,V>`
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### forEach

    public void forEach(BiConsumer<? super K, ? super V> action)
    Specified by:
      `forEach` in interface `Map<K,V>`

  - ### getOrDefault

    public V getOrDefault(Object key, V defaultValue)
    Specified by:
      `getOrDefault` in interface `Map<K,V>`

  - ### putIfAbsent

    public V putIfAbsent(K key, V value)
    Specified by:
      `putIfAbsent` in interface `Map<K,V>`

  - ### computeIfAbsent

    public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)
    Specified by:
      `computeIfAbsent` in interface `Map<K,V>`

  - ### computeIfPresent

    public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)
    Specified by:
      `computeIfPresent` in interface `Map<K,V>`

  - ### compute

    public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)
    Specified by:
      `compute` in interface `Map<K,V>`

  - ### merge

    public V merge(K key, V newValue, BiFunction<? super V, ? super V, ? extends V> remappingFunction)
    Specified by:
      `merge` in interface `Map<K,V>`

  - ### replace

    public V replace(K key, V value)
    Specified by:
      `replace` in interface `Map<K,V>`

  - ### replace

    public boolean replace(K key, V oldValue, V newValue)
    Specified by:
      `replace` in interface `Map<K,V>`

  - ### remove

    public boolean remove(Object key, Object value)
    Specified by:
      `remove` in interface `Map<K,V>`