Package jline.util

Class Pair<T,U>

java.lang.Object
jline.util.Pair<T,U>
Type Parameters:
T - the type of the left element
U - the type of the right element
All Implemented Interfaces:
Serializable, Comparable<Pair<T,U>>

public class Pair<T,U> extends Object implements Comparable<Pair<T,U>>, Serializable
A generic pair container that holds two objects of potentially different types.

This utility class provides a simple way to group two related values together. It implements Comparable for ordering pairs and Serializable for persistence. The comparison is based on the left element if it's comparable, otherwise on the right element.

Common use cases:

  • Returning multiple values from methods
  • Storing coordinate pairs or ranges
  • Key-value associations where Map is not suitable
  • Temporary grouping of related objects

Since:
1.0
See Also:
  • Constructor Details

    • Pair

      public Pair(T left, U right)
      Constructs a new pair with the specified left and right elements.
      Parameters:
      left - the left element of the pair
      right - the right element of the pair
    • Pair

      public Pair(Pair<T,U> other)
      Copy constructor that creates a new pair with the same elements as another pair.
      Parameters:
      other - the pair to copy from
  • Method Details

    • compareTo

      public int compareTo(Pair<T,U> other)
      Specified by:
      compareTo in interface Comparable<T>
    • getLeft

      public T getLeft()
    • setLeft

      public void setLeft(T left)
    • getRight

      public U getRight()
    • setRight

      public void setRight(U right)
    • getFirst

      public T getFirst()
      Kotlin-style alias for getLeft().
    • getSecond

      public U getSecond()
      Kotlin-style alias for getRight().