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>

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:
5.0, 11/25/04
See Also:
Map#Entry

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
 Left left()
          left getter
 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
 

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

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

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 final Left left()
left getter

Returns:
Left

right

public final Right right()
right getter

Returns:
Right

swap

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

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