Package jline.util

Class Pair

  • All Implemented Interfaces:
    java.io.Serializable , java.lang.Comparable

    
    public class Pair<T, U>
     implements Comparable<T>, 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

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public T left
      public U right
    • Constructor Summary

      Constructors 
      Constructor Description
      Pair(T left, U right) Constructs a new pair with the specified left and right elements.
      Pair(Pair<T, U> other) Copy constructor that creates a new pair with the same elements as another pair.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      T getLeft()
      void setLeft(T left)
      U getRight()
      void setRight(U right)
      int compareTo(Pair<T, U> other)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Pair

        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

        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