org.apache.commons.collections.keyvalue
Class DefaultKeyValue<K,V>

java.lang.Object
  extended by org.apache.commons.collections.keyvalue.AbstractKeyValue<K,V>
      extended by org.apache.commons.collections.keyvalue.DefaultKeyValue<K,V>
All Implemented Interfaces:
KeyValue<K,V>

public class DefaultKeyValue<K,V>
extends AbstractKeyValue<K,V>

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
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:35:07 $
Author:
James Strachan, Michael A. Smith, Neil O'Toole, Matt Hall, John Watkinson, Stephen Colebourne

Field Summary
 
Fields inherited from class org.apache.commons.collections.keyvalue.AbstractKeyValue
key, value
 
Constructor Summary
DefaultKeyValue()
          Constructs a new pair with a null key and null value.
DefaultKeyValue(KeyValue<K,V> pair)
          Constructs a new pair from the specified KeyValue.
DefaultKeyValue(K key, V value)
          Constructs a new pair with the specified key and given value.
DefaultKeyValue(Map.Entry<K,V> entry)
          Constructs a new pair from the specified MapEntry.
 
Method Summary
 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.collections.keyvalue.AbstractKeyValue
getKey, getValue, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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 null
value - the value for the entry, may be null

DefaultKeyValue

public DefaultKeyValue(KeyValue<K,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<K,V> entry)
Constructs a new pair from the specified MapEntry.

Parameters:
entry - the entry to copy, must not be null
Throws:
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:
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:
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

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


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.