dk.brics.string.util
Class UnorderedPair<E extends Comparable<E>>

java.lang.Object
  extended by dk.brics.string.util.UnorderedPair<E>
All Implemented Interfaces:
Comparable<UnorderedPair<E>>

public final class UnorderedPair<E extends Comparable<E>>
extends Object
implements Comparable<UnorderedPair<E>>

An unordered immutable pair of elements. Unordered means the pair (a,b) equals the pair (b,a). An element of a pair cannot be null.

The class implements Comparable. Pairs are compared by their smallest elements, and if those are equal, they are compared by their maximum elements.

To work correctly, the underlying element type must implement Object.equals(java.lang.Object) and Comparable.compareTo(T) in a consistent fashion.


Constructor Summary
UnorderedPair(E a, E b)
          Creates an unordered pair of the specified elements.
 
Method Summary
 int compareTo(UnorderedPair<E> o)
           
 boolean equals(Object obj)
           
 E getFirst()
          Gets the smallest element of the pair (according to its Comparable implementation).
 E getSecond()
          Gets the largest element of the pair (according to its Comparable implementation).
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnorderedPair

public UnorderedPair(E a,
                     E b)
Creates an unordered pair of the specified elements. The order of the arguments is irrelevant, so the first argument is not guaranteed to be returned by getFirst(), for example.

Parameters:
a - one element of the pair. Must not be null.
b - one element of the pair. Must not be null. May be the same as a.
Method Detail

compareTo

public int compareTo(UnorderedPair<E> o)
Specified by:
compareTo in interface Comparable<UnorderedPair<E extends Comparable<E>>>

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getFirst

public E getFirst()
Gets the smallest element of the pair (according to its Comparable implementation).

Returns:
an element of the pair. null is never returned.

getSecond

public E getSecond()
Gets the largest element of the pair (according to its Comparable implementation).

Returns:
an element of the pair. null is never returned.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2009 Anders Møller, Aske Simon Christensen, Asger Feldthaus.