jaggregate
Class Pair<K,V>

java.lang.Object
  extended by jaggregate.Pair<K,V>
Type Parameters:
K - the type of the pair's key
V - the type of the pair's value
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
KeyValuePair

public class Pair<K,V>
extends Object
implements Serializable

A simple 2-tuple, typically used to represent the key-value pairs of an AbstractDictionary.

Version:
$Id: Pair.java,v 1.2 2008/03/26 18:00:34 pholser Exp $
Author:
Paul Holser
See Also:
Serialized Form

Constructor Summary
Pair(K key, V value)
          Creates a pair.
 
Method Summary
 boolean equals(Object that)
          
 int hashCode()
          
 K key()
          Gives the pair's key.
static
<T,U> Pair<T,U>
pair(T key, U value)
          Creates a new pair with the given key and value.
 String toString()
          
 V value()
          Gives the pair's value.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pair

public Pair(K key,
            V value)
Creates a pair.

Parameters:
key - the new pair's key
value - the new pair's value
Method Detail

pair

public static <T,U> Pair<T,U> pair(T key,
                                   U value)
Creates a new pair with the given key and value. Unlike the constructor, this generic factory method allows type inference to work its magic and can save the caller from having to specify the actual types of the pair's elements twice. For example:

   Pair<Integer, Integer> square = new Pair<Integer, Integer>( 3, 9 );
 
versus
   Pair<Integer, Integer> square = pairOf( 3, 9 );
 

Type Parameters:
T - the type of the key in the resultant pair
U - the type of the value in the resultant pair
Parameters:
key - a key
value - a value
Returns:
a pair containing key and value

key

public K key()
Gives the pair's key.

Returns:
the key

value

public V value()
Gives the pair's value.

Returns:
the value

equals

public boolean equals(Object that)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu