⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.keyvalue

Class DefaultKeyValue

java.lang.Object
|
+--org.apache.commons.collections.keyvalue.AbstractKeyValue
   |
   +--org.apache.commons.collections.keyvalue.DefaultKeyValue


public class DefaultKeyValue
extends AbstractKeyValue

A mutable KeyValue pair that does not implement MapEntry.

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

Since:
Commons Collections 3.0
Authors:
James Strachan
Michael A. Smith
Neil O'Toole
Stephen Colebourne

Constructor Summary

DefaultKeyValue()

Constructs a new pair with a null key and null value.

DefaultKeyValue(final Object key, final Object value)

Constructs a new pair with the specified key and given value.

DefaultKeyValue(final KeyValue pair)

Constructs a new pair from the specified KeyValue.

DefaultKeyValue(final Map.Entry entry)

Constructs a new pair from the specified MapEntry.

Method Summary

boolean

equals(final Object obj)

Compares this Map Entry with another Map Entry.

int

hashCode()

Gets a hashCode compatible with the equals method.

Object

setKey(final Object key)

Sets the key.

Object

setValue(final Object value)

Sets the value.

Map.Entry

toMapEntry()

Returns a new Map.Entry object with key and value from this pair.

Constructor Details

DefaultKeyValue

public DefaultKeyValue()

Constructs a new pair with a null key and null value.


DefaultKeyValue

public DefaultKeyValue(final KeyValue pair)

Constructs a new pair from the specified KeyValue.

Parameters:
pair - the pair to copy, must not be null
Throws:
- if the entry is null

DefaultKeyValue

public DefaultKeyValue(final Map.Entry entry)

Constructs a new pair from the specified MapEntry.

Parameters:
entry - the entry to copy, must not be null
Throws:
- if the entry is null

DefaultKeyValue

public DefaultKeyValue(final Object key, final Object 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

Method Details

equals

public boolean equals(final 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.

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 java.util.Map.Entry.hashCode(), however subclasses may override this.

Returns:
a suitable hash code

setKey

public Object setKey(final Object key)

Sets the key.

Parameters:
key - the new key
Returns:
the old key
Throws:
- if key is this object

setValue

public Object setValue(final Object value)

Sets the value.

Parameters:
value - the new value
Returns:
the old value of the value
Throws:
- if value is this object

toMapEntry

public Entry toMapEntry()

Returns a new Map.Entry object with key and value from this pair.

Returns:
a MapEntry instance