Package org.apache.commons.collections4.keyvalue

# Class DefaultKeyValue<K,V>

java.lang.Object
org.apache.commons.collections4.keyvalue.AbstractKeyValue<K,V>
org.apache.commons.collections4.keyvalue.DefaultKeyValue<K,V>

Type Parameters:
  `K` - The type of keys
  `V` - The type of values

All Implemented Interfaces:
  `KeyValue<K,V>`

public class DefaultKeyValue<K,V> extends AbstractKeyValue<K,V>
A mutable `KeyValue` pair that does not implement `Map.Entry`.

Note that a `DefaultKeyValue` instance may not contain itself as a key or value.

Since:
  3.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultKeyValue()`
  Constructs a new pair with a null key and null value.
  `DefaultKeyValue(Map.Entry<? extends K,? extends V> entry)`
  Constructs a new pair from the specified `Map.Entry`.
  `DefaultKeyValue(K key, V value)`
  Constructs a new pair with the specified key and given value.
  `DefaultKeyValue(KeyValue<? extends K,? extends V> pair)`
  Constructs a new pair from the specified `KeyValue`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Compares this `Map.Entry` with another `Map.Entry`.
  `int`
  `hashCode()`
  Gets a hashCode compatible with the equals method.
  `K`
  `setKey(K key)`
  Sets the key.
  `V`
  `setValue(V value)`
  Sets the value.
  `Map.Entry<K,V>`
  `toMapEntry()`
  Returns a new `Map.Entry` object with key and value from this pair.

  ### Methods inherited from class org.apache.commons.collections4.keyvalue.AbstractKeyValue

  `getKey, getValue, toString`

  ### Methods inherited from class java.lang.Object

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

- ## Constructor Details

  - ### DefaultKeyValue

    public DefaultKeyValue()
    Constructs a new pair with a null key and null value.

  - ### DefaultKeyValue

    public DefaultKeyValue(K key, V value)
    Constructs a new pair with the specified key and given value.
    Parameters:
      `key` - The key for the entry, may be null
      `value` - The value for the entry, may be null

  - ### DefaultKeyValue

    public DefaultKeyValue(KeyValue<? extends K,? extends V> pair)
    Constructs a new pair from the specified `KeyValue`.
    Parameters:
      `pair` - The pair to copy, must not be null
    Throws:
      `NullPointerException` - if the entry is null

  - ### DefaultKeyValue

    public DefaultKeyValue(Map.Entry<? extends K,? extends V> entry)
    Constructs a new pair from the specified `Map.Entry`.
    Parameters:
      `entry` - The entry to copy, must not be null
    Throws:
      `NullPointerException` - if the entry is null

- ## Method Details

  - ### equals

    public boolean equals(Object obj)
    Compares this `Map.Entry` with another `Map.Entry`.

    Returns true if the compared object is also a `DefaultKeyValue`, and its key and value are equal to this object's key and value.

    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - The object to compare to
    Returns:
      true if equal key and value

  - ### hashCode

    public int hashCode()
    Gets a hashCode compatible with the equals method.

    Implemented per API documentation of `Map.Entry.hashCode()`, however subclasses may override this.

    Overrides:
      `hashCode` in class `Object`
    Returns:
      A suitable hash code

  - ### setKey

    public K setKey(K key)
    Sets the key.
    Overrides:
      `setKey` in class `AbstractKeyValue<K,V>`
    Parameters:
      `key` - The new key
    Returns:
      The old key
    Throws:
      `IllegalArgumentException` - if key is this object

  - ### setValue

    public V setValue(V value)
    Sets the value.
    Overrides:
      `setValue` in class `AbstractKeyValue<K,V>`
    Parameters:
      `value` - The new value
    Returns:
      The old value of the value
    Throws:
      `IllegalArgumentException` - if value is this object

  - ### toMapEntry

    public Map.Entry<K,V> toMapEntry()
    Returns a new `Map.Entry` object with key and value from this pair.
    Returns:
      A MapEntry instance