gov.sandia.cognition.util
Class DefaultKeyValuePair<KeyType,ValueType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.DefaultKeyValuePair<KeyType,ValueType>
Type Parameters:
KeyType - The type of the key.
ValueType - The type of the value.
All Implemented Interfaces:
CloneableSerializable, KeyValuePair<KeyType,ValueType>, Pair<KeyType,ValueType>, Serializable, Cloneable

public class DefaultKeyValuePair<KeyType,ValueType>
extends AbstractCloneableSerializable
implements KeyValuePair<KeyType,ValueType>

A default implementation of the KeyValuePair interface.

Since:
3.1
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  KeyType key
          The key part in the pair, which is the first element.
protected  ValueType value
          The value part in the pair, which is the second element.
 
Constructor Summary
DefaultKeyValuePair()
          Creates a new, empty DefaultKeyValuePair.
DefaultKeyValuePair(KeyType key, ValueType value)
          Creates a new DefaultKeyValuePair from the given key and value.
DefaultKeyValuePair(KeyValuePair<? extends KeyType,? extends ValueType> other)
          Creates a new DefaultKeyValuePair as a shallow copy of the given key-value pair.
 
Method Summary
static
<KeyType,ValueType>
DefaultKeyValuePair<KeyType,ValueType>
create()
          Convenience method to create a new, empty DefaultKeyValuePair.
static
<KeyType,ValueType>
DefaultKeyValuePair<KeyType,ValueType>
create(KeyType key, ValueType value)
          Convenience method to create a new DefaultKeyValuePair from the given key and value.
 KeyType getFirst()
          Gets the first object.
 KeyType getKey()
          Gets the key part of the key-value pair.
 ValueType getSecond()
          Gets the second object.
 ValueType getValue()
          Gets the value part of the key-value pair.
 void setKey(KeyType key)
          Sets the key element of the pair.
 void setValue(ValueType value)
          Sets the value element of the pair.
 String toString()
           
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

key

protected KeyType key
The key part in the pair, which is the first element.


value

protected ValueType value
The value part in the pair, which is the second element.

Constructor Detail

DefaultKeyValuePair

public DefaultKeyValuePair()
Creates a new, empty DefaultKeyValuePair.


DefaultKeyValuePair

public DefaultKeyValuePair(KeyType key,
                           ValueType value)
Creates a new DefaultKeyValuePair from the given key and value.

Parameters:
key - The key.
value - The value.

DefaultKeyValuePair

public DefaultKeyValuePair(KeyValuePair<? extends KeyType,? extends ValueType> other)
Creates a new DefaultKeyValuePair as a shallow copy of the given key-value pair.

Parameters:
other - The key-value pair to copy.
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getFirst

public KeyType getFirst()
Description copied from interface: Pair
Gets the first object.

Specified by:
getFirst in interface Pair<KeyType,ValueType>
Returns:
The first object.

getSecond

public ValueType getSecond()
Description copied from interface: Pair
Gets the second object.

Specified by:
getSecond in interface Pair<KeyType,ValueType>
Returns:
The second object.

getKey

public KeyType getKey()
Description copied from interface: KeyValuePair
Gets the key part of the key-value pair.

Specified by:
getKey in interface KeyValuePair<KeyType,ValueType>
Returns:
The key.

setKey

public void setKey(KeyType key)
Sets the key element of the pair.

Parameters:
key - The key.

getValue

public ValueType getValue()
Description copied from interface: KeyValuePair
Gets the value part of the key-value pair.

Specified by:
getValue in interface KeyValuePair<KeyType,ValueType>
Returns:
The value.

setValue

public void setValue(ValueType value)
Sets the value element of the pair.

Parameters:
value - The value.

create

public static <KeyType,ValueType> DefaultKeyValuePair<KeyType,ValueType> create()
Convenience method to create a new, empty DefaultKeyValuePair.

Type Parameters:
KeyType - The type of the key.
ValueType - The type of the value.
Returns:
A new, empty key-value pair.

create

public static <KeyType,ValueType> DefaultKeyValuePair<KeyType,ValueType> create(KeyType key,
                                                                                ValueType value)
Convenience method to create a new DefaultKeyValuePair from the given key and value.

Type Parameters:
KeyType - The type of the key.
ValueType - The type of the value.
Parameters:
key - The key.
value - The value.
Returns:
A new, empty key-value pair.