org.hippoecm.hst.util
Class DefaultKeyValue<K,V>

java.lang.Object
  extended by org.hippoecm.hst.util.DefaultKeyValue<K,V>
All Implemented Interfaces:
KeyValue<K,V>

public class DefaultKeyValue<K,V>
extends Object
implements KeyValue<K,V>

An implementation of KeyValue to provide a simple key value pair. A Map Entry has considerable additional semantics over and above a simple key-value pair.

Version:
$Id: DefaultKeyValue.java 18160 2009-05-19 11:23:16Z wko $

Constructor Summary
DefaultKeyValue(KeyValue<K,V> pair)
          Constructs a new pair from the specified KeyValue.
DefaultKeyValue(KeyValue<K,V> pair, boolean compareByKeyOnly)
          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(K key, V value, boolean compareByKeyOnly)
          Constructs a new pair with the specified key and given value.
DefaultKeyValue(Map.Entry<K,V> entry)
          Constructs a new pair from the specified Map.Entry.
DefaultKeyValue(Map.Entry<K,V> entry, boolean compareByKeyOnly)
          Constructs a new pair from the specified Map.Entry.
 
Method Summary
 boolean equals(Object obj)
          Compares this KeyValue with another KeyValue.
 K getKey()
          Gets the key from the pair.
 V getValue()
          Gets the value from the pair.
 int hashCode()
          Gets a hashCode compatible with the equals method.
 K setKey(K key)
          Sets the key.
 V setValue(V value)
          Sets the value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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(K key,
                       V value,
                       boolean compareByKeyOnly)
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
compareByKeyOnly - flag if equals() depends on key only

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(KeyValue<K,V> pair,
                       boolean compareByKeyOnly)
Constructs a new pair from the specified KeyValue.

Parameters:
pair - the pair to copy, must not be null
compareByKeyOnly - flag if equals() depends on key only
Throws:
NullPointerException - if the entry is null

DefaultKeyValue

public DefaultKeyValue(Map.Entry<K,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

DefaultKeyValue

public DefaultKeyValue(Map.Entry<K,V> entry,
                       boolean compareByKeyOnly)
Constructs a new pair from the specified Map.Entry.

Parameters:
entry - the entry to copy, must not be null
compareByKeyOnly - flag if equals() depends on key only
Throws:
NullPointerException - if the entry is null
Method Detail

getKey

public K getKey()
Gets the key from the pair.

Specified by:
getKey in interface KeyValue<K,V>
Returns:
the key

getValue

public V getValue()
Gets the value from the pair.

Specified by:
getValue in interface KeyValue<K,V>
Returns:
the value

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

equals

public boolean equals(Object obj)
Compares this KeyValue with another KeyValue.

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.

Overrides:
hashCode in class Object
Returns:
a suitable hash code


Copyright © 2008-2012 Hippo. All Rights Reserved.