de.cau.cs.kieler.core.util
Class Pair<F,S>

java.lang.Object
  extended by de.cau.cs.kieler.core.util.Pair<F,S>
Type Parameters:
F - type of first contained object
S - type of second contained object

public class Pair<F,S>
extends Object

A simple pair implementation.

Rating yellow
(2011-03-14) reviewed by cmot, cds

Nested Class Summary
static class Pair.FirstComparator<F extends Comparable<F>,S>
          Comparator that uses the first element as base.
static class Pair.SecondComparator<F,S extends Comparable<S>>
          Comparator that uses the second element as base.
 
Constructor Summary
Pair()
          Constructs a pair with null elements.
Pair(F thefirst, S thesecond)
          Constructs a pair given both elements.
Pair(Map.Entry<F,S> entry)
          Constructs a pair from a map entry.
 
Method Summary
 boolean equals(Object obj)
          
static
<G,T> List<Pair<G,T>>
fromMap(Map<G,T> map)
          Constructs a list of pairs from the entries of a map.
 F getFirst()
          Returns the first element.
 S getSecond()
          Returns the second element.
 int hashCode()
          
 void setFirst(F thefirst)
          Sets the first element.
 void setSecond(S thesecond)
          Sets the second element.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pair

public Pair()
Constructs a pair with null elements.


Pair

public Pair(F thefirst,
            S thesecond)
Constructs a pair given both elements.

Parameters:
thefirst - the first element
thesecond - the second element

Pair

public Pair(Map.Entry<F,S> entry)
Constructs a pair from a map entry.

Parameters:
entry - an entry of a map
Method Detail

fromMap

public static <G,T> List<Pair<G,T>> fromMap(Map<G,T> map)
Constructs a list of pairs from the entries of a map.

Type Parameters:
G - type of the map keys
T - type of the map values
Parameters:
map - a map
Returns:
a list of map entries as pairs

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

setFirst

public void setFirst(F thefirst)
Sets the first element.

Parameters:
thefirst - the first element to set

getFirst

public F getFirst()
Returns the first element.

Returns:
the first element

setSecond

public void setSecond(S thesecond)
Sets the second element.

Parameters:
thesecond - the second element to set

getSecond

public S getSecond()
Returns the second element.

Returns:
the second element