Package org.forgerock.util
Class Pair<F,S>
- java.lang.Object
-
- org.forgerock.util.Pair<F,S>
-
- Type Parameters:
F
- type of the first pair elementS
- type of the second pair element
public final class Pair<F,S> extends Object
Ordered pair of arbitrary objects. Use of Pair is strictly restricted to internal (non-public) APIs:
- Pair cannot be used in public APIs - Consider using dedicated classes over Pair. Dedicated classes are more readable while Pair is meaningless.
- Pair should only be used to return two values from a method, just like a tuple. If you need more than two values, create a dedicated class.
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator
COMPARATOR
static Pair<?,?>
EMPTY
An empty Pair.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<F,S>
asMap()
Get the pair as a map of key to value.static <F,S>
Pair<F,S>empty()
Returns an empty Pair matching the required types.boolean
equals(Object obj)
F
getFirst()
Returns the first element of this pair.static <F extends Comparable<F>,S extends Comparable<S>>
Comparator<Pair<F,S>>getPairComparator()
Returns a comparator for Pairs of comparable objects.S
getSecond()
Returns the second element of this pair.int
hashCode()
static <F,S>
Pair<F,S>of(F first, S second)
Creates a newPair
.String
toString()
-
-
-
Field Detail
-
EMPTY
public static final Pair<?,?> EMPTY
An empty Pair.
-
COMPARATOR
public static final Comparator COMPARATOR
-
-
Method Detail
-
of
public static <F,S> Pair<F,S> of(F first, S second)
Creates a newPair
.- Type Parameters:
F
- type of the first pair elementS
- type of the second pair element- Parameters:
first
- the first element of the constructed pairsecond
- the second element of the constructed pair- Returns:
- A new Pair built with the provided elements
-
empty
public static <F,S> Pair<F,S> empty()
Returns an empty Pair matching the required types.- Type Parameters:
F
- type of the first pair elementS
- type of the second pair element- Returns:
- An empty Pair matching the required types
-
getPairComparator
public static <F extends Comparable<F>,S extends Comparable<S>> Comparator<Pair<F,S>> getPairComparator()
Returns a comparator for Pairs of comparable objects.- Type Parameters:
F
- type of the first pair elementS
- type of the second pair element- Returns:
- a comparator for Pairs of comparable objects.
-
getFirst
public F getFirst()
Returns the first element of this pair.- Returns:
- the first element of this pair
-
getSecond
public S getSecond()
Returns the second element of this pair.- Returns:
- the second element of this pair
-
-