Class Pair<T1,T2>

java.lang.Object
com.saperion.common.lang.encapsulation.Pair<T1,T2>
Type Parameters:
T1 - type of first object
T2 - type of second object
All Implemented Interfaces:
Serializable

public class Pair<T1,T2> extends Object implements Serializable

A simple immutable encapsulation for 2 objects.

An instance of this Pair can be used in several threads concurrently.

Author:
agz
See Also:
  • Constructor Details

    • Pair

      public Pair(T1 first, T2 second)
      Creates a new Pair with the specified first and second objects.

      Both objects may be null.

      Parameters:
      first - first object
      second - second object
  • Method Details

    • getFirst

      public final T1 getFirst()
      Returns the first object.
      Returns:
      first object
    • getSecond

      public final T2 getSecond()
      Returns the second object.
      Returns:
      second object
    • 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
    • newInstance

      public static <T1, T2> Pair<T1,T2> newInstance(T1 first, T2 second)
      Convenience factory method for letting the compiler do the type inference.
      Parameters:
      first - The first object in the pair
      second - The second object in the pair
      Returns:
      A pair consisting of the given objects