Class Pair<F,S>

java.lang.Object
org.forgerock.util.Pair<F,S>
Type Parameters:
F - type of the first pair element
S - 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 Details

  • Method Details

    • of

      public static <F, S> Pair<F,S> of(F first, S second)
      Creates a new Pair.
      Type Parameters:
      F - type of the first pair element
      S - type of the second pair element
      Parameters:
      first - the first element of the constructed pair
      second - 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 element
      S - 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 element
      S - 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
    • asMap

      public Map<F,S> asMap()
      Get the pair as a map of key to value.
      Returns:
      The map.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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

      public String toString()
      Overrides:
      toString in class Object