com.myjavatools.lib.foundation
Class Pair<Left,Right>

java.lang.Object
  extended by com.myjavatools.lib.foundation.Pair<Left,Right>
All Implemented Interfaces:
java.util.Map.Entry<Left,Right>
Direct Known Subclasses:
LazyPair

public class Pair<Left,Right>
extends java.lang.Object
implements java.util.Map.Entry<Left,Right>

Pair<Left, Right> is a class that represents pairs of objects. It is similar to Map.Entry. Pair is immutable.

Since:
5.0
Version:
6.0 04/25/06
See Also:
Map#Entry

Field Summary
protected  Left left
           
protected  Right right
           
 
Constructor Summary
Pair(Left left, Right right)
          Constructor, creates a new pair from two objects.
 
Method Summary
 boolean equals(java.lang.Object x)
          equals method
 Left getKey()
          key getter (to implement Map.Entry)
 Right getValue()
          value getter (to implement Map.Entry)
 int hashCode()
          some hashcode for Pair made from left and right hash codes
protected static int hashCode(java.util.Map.Entry pair)
           
 Left left()
          left getter
protected static boolean pairEqual(java.util.Map.Entry pair1, java.util.Map.Entry pair2)
           
 Right right()
          right getter
 Right setValue(Right value)
          value setter - unsupported (immutable class)
 Pair<Right,Left> swap()
          swaps left and right
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

left

protected Left left

right

protected Right right
Constructor Detail

Pair

public Pair(Left left,
            Right right)
Constructor, creates a new pair from two objects.

Parameters:
left - Left
right - Right
Method Detail

setValue

public Right setValue(Right value)
value setter - unsupported (immutable class)

Specified by:
setValue in interface java.util.Map.Entry<Left,Right>
Parameters:
value - Right ignored
Returns:
Right none actually
Throws:
java.lang.UnsupportedOperationException - - always

getValue

public Right getValue()
value getter (to implement Map.Entry)

Specified by:
getValue in interface java.util.Map.Entry<Left,Right>
Returns:
Right the map entry value

getKey

public Left getKey()
key getter (to implement Map.Entry)

Specified by:
getKey in interface java.util.Map.Entry<Left,Right>
Returns:
Left the map entry key

pairEqual

protected static boolean pairEqual(java.util.Map.Entry pair1,
                                   java.util.Map.Entry pair2)

equals

public boolean equals(java.lang.Object x)
equals method

Specified by:
equals in interface java.util.Map.Entry<Left,Right>
Overrides:
equals in class java.lang.Object
Parameters:
x - Object to compare to
Returns:
boolean true if x is not null and equals(this) equals(Map.Entry) returns true if the two entries have equal key and equal value are equal

hashCode

protected static int hashCode(java.util.Map.Entry pair)

hashCode

public int hashCode()
some hashcode for Pair made from left and right hash codes

Specified by:
hashCode in interface java.util.Map.Entry<Left,Right>
Overrides:
hashCode in class java.lang.Object
Returns:
int

left

public Left left()
left getter

Returns:
Left

right

public Right right()
right getter

Returns:
Right

swap

public Pair<Right,Left> swap()
swaps left and right

Returns:
new Pair<Right,Left> (right, left)