Class DefaultKeyValue
- java.lang.Object
-
- org.apache.commons.collections.keyvalue.AbstractKeyValue
-
- org.apache.commons.collections.keyvalue.DefaultKeyValue
-
- All Implemented Interfaces:
KeyValue
public class DefaultKeyValue extends AbstractKeyValue
A mutableKeyValue
pair that does not implementMap.Entry
.Note that a
DefaultKeyValue
instance may not contain itself as a key or value.- Since:
- Commons Collections 3.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- James Strachan, Michael A. Smith, Neil O'Toole, Stephen Colebourne
-
-
Field Summary
-
Fields inherited from class org.apache.commons.collections.keyvalue.AbstractKeyValue
key, value
-
-
Constructor Summary
Constructors Constructor Description DefaultKeyValue()
Constructs a new pair with a null key and null value.DefaultKeyValue(Object key, Object value)
Constructs a new pair with the specified key and given value.DefaultKeyValue(Map.Entry entry)
Constructs a new pair from the specifiedMap.Entry
.DefaultKeyValue(KeyValue pair)
Constructs a new pair from the specifiedKeyValue
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Compares thisMap.Entry
with anotherMap.Entry
.int
hashCode()
Gets a hashCode compatible with the equals method.Object
setKey(Object key)
Sets the key.Object
setValue(Object value)
Sets the value.Map.Entry
toMapEntry()
Returns a newMap.Entry
object with key and value from this pair.-
Methods inherited from class org.apache.commons.collections.keyvalue.AbstractKeyValue
getKey, getValue, toString
-
-
-
-
Constructor Detail
-
DefaultKeyValue
public DefaultKeyValue()
Constructs a new pair with a null key and null value.
-
DefaultKeyValue
public DefaultKeyValue(Object key, Object 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 pair)
Constructs a new pair from the specifiedKeyValue
.- Parameters:
pair
- the pair to copy, must not be null- Throws:
NullPointerException
- if the entry is null
-
DefaultKeyValue
public DefaultKeyValue(Map.Entry entry)
Constructs a new pair from the specifiedMap.Entry
.- Parameters:
entry
- the entry to copy, must not be null- Throws:
NullPointerException
- if the entry is null
-
-
Method Detail
-
setKey
public Object setKey(Object key)
Sets the key.- Parameters:
key
- the new key- Returns:
- the old key
- Throws:
IllegalArgumentException
- if key is this object
-
setValue
public Object setValue(Object value)
Sets the value.- Parameters:
value
- the new value- Returns:
- the old value of the value
- Throws:
IllegalArgumentException
- if value is this object
-
toMapEntry
public Map.Entry toMapEntry()
Returns a newMap.Entry
object with key and value from this pair.- Returns:
- a MapEntry instance
-
equals
public boolean equals(Object obj)
Compares thisMap.Entry
with 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.
-
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.
-
-