SPT Core API

com.sptci
Class KeyValue<K,V>

java.lang.Object
  extended by com.sptci.KeyValue<K,V>
Type Parameters:
K - The class name of the key for this object.
V - The class name of the value for this object.
All Implemented Interfaces:
Serializable, Cloneable, Comparable<KeyValue<K,V>>

public class KeyValue<K,V>
extends Object
implements Cloneable, Comparable<KeyValue<K,V>>, Serializable

A simple key-value class. This is useful in UI components when you wish to tag along a unique identifier (eg. database primary key, object ID etc.) with a display value. The toString() method returns only value thus ensuring that your display components function as normal, while giving access to the unique identifier for control logic.

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: KeyValue.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2006-01-22
See Also:
Serialized Form

Constructor Summary
KeyValue()
          Default constructor.
KeyValue(K key, V value)
          Create a new instance using the specified values.
 
Method Summary
 void addInformation(K key, V value)
          Add the specified key-value pair to information
 Object clone()
          Creates and returns a copy of this object.
 int compareTo(KeyValue<K,V> object)
          Compares this object with the specified object for order.
 boolean equals(Object object)
          Compare the specified object for equality with this object.
 Map getInformation()
          Returns information.
 K getKey()
          Returns key.
 V getValue()
          Returns value.
 int hashCode()
          Return a hash code for this object.
 void setInformation(Map<K,V> information)
          Set information.
 void setKey(K key)
          Set key.
 void setValue(V value)
          Set value.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyValue

public KeyValue()
Default constructor. Creates an empty uninitialised object.


KeyValue

public KeyValue(K key,
                V value)
Create a new instance using the specified values.

Parameters:
key - The key to use.
value - The value to use.
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Creates and returns a copy of this object. Implementation of the Cloneable interface. No special actions are performed. This method simply allows public access to the Object.clone method.

Overrides:
clone in class Object
Returns:
Object A clone of this instance.
Throws:
CloneNotSupportedException - If the super-class implementation throws an error.

compareTo

public int compareTo(KeyValue<K,V> object)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Note: The default implementation compares the value or key or hashCode() values in that order depending upon whether they implement Comparable or not.

Specified by:
compareTo in interface Comparable<KeyValue<K,V>>
Parameters:
object - The object that is to be compared with this object.
Returns:
int A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equals

public boolean equals(Object object)
Compare the specified object for equality with this object.

Overrides:
equals in class Object
Parameters:
object - The object that is to be checked for equality.
Returns:
Returns true if the specified object is of the same type and has the same key and value values.

hashCode

public int hashCode()
Return a hash code for this object.

Overrides:
hashCode in class Object
Returns:
The hash code for this object.

toString

public String toString()
Returns a string representation of the object. Returns the string representation of value.

Overrides:
toString in class Object
Returns:
The string representation of this object.

getKey

public K getKey()
Returns key.

Returns:
The value/reference of/to key.

setKey

public void setKey(K key)
Set key.

Parameters:
key - The value to set.

getValue

public V getValue()
Returns value.

Returns:
The value/reference of/to value.

setValue

public void setValue(V value)
Set value.

Parameters:
value - The value to set.

getInformation

public Map getInformation()
Returns information.

Returns:
Map The value/reference of/to information.

setInformation

public void setInformation(Map<K,V> information)
Set information.

Parameters:
information - The value to set.

addInformation

public void addInformation(K key,
                           V value)
Add the specified key-value pair to information

Parameters:
key - The key for the mapping
value - The value for the mapping.

SPT Core API