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 keysV- the type of values
- All Implemented Interfaces:
KeyValue<K,V>
public class DefaultKeyValue<K,V> extends AbstractKeyValue<K,V>
A mutableKeyValuepair that does not implementMap.Entry.Note that a
DefaultKeyValueinstance 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(java.util.Map.Entry<? extends K,? extends V> entry)Constructs a new pair from the specifiedMap.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 specifiedKeyValue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Compares thisMap.Entrywith anotherMap.Entry.inthashCode()Gets a hashCode compatible with the equals method.KsetKey(K key)Sets the key.VsetValue(V value)Sets the value.java.util.Map.Entry<K,V>toMapEntry()Returns a newMap.Entryobject with key and value from this pair.-
Methods inherited from class org.apache.commons.collections4.keyvalue.AbstractKeyValue
getKey, getValue, toString
-
-
-
-
Constructor Detail
-
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 nullvalue- the value for the entry, may be null
-
DefaultKeyValue
public DefaultKeyValue(KeyValue<? extends K,? extends V> pair)
Constructs a new pair from the specifiedKeyValue.- Parameters:
pair- the pair to copy, must not be null- Throws:
java.lang.NullPointerException- if the entry is null
-
-
Method Detail
-
setKey
public K setKey(K key)
Sets the key.- Parameters:
key- the new key- Returns:
- the old key
- Throws:
java.lang.IllegalArgumentException- if key is this object
-
setValue
public V setValue(V value)
Sets the value.- Parameters:
value- the new value- Returns:
- the old value of the value
- Throws:
java.lang.IllegalArgumentException- if value is this object
-
toMapEntry
public java.util.Map.Entry<K,V> toMapEntry()
Returns a newMap.Entryobject with key and value from this pair.- Returns:
- a MapEntry instance
-
equals
public boolean equals(java.lang.Object obj)
Compares thisMap.Entrywith anotherMap.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:
equalsin classjava.lang.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:
hashCodein classjava.lang.Object- Returns:
- a suitable hash code
-
-