Record Class Tuple2<T,U>

java.lang.Object
java.lang.Record
org.klojang.util.Tuple2<T,U>
Type Parameters:
T - The type of the first component
U - The type of the second component
Record Components:
first - The first component of the 2-tuple
second - The second component of the 2-tuple

public record Tuple2<T,U>(T first, U second) extends Record
Generic 2-tuple of arbitrarily typed, non-null objects.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tuple2(T first, U second)
    Instantiates a new Tuple2.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the first record component.
    final int
    Returns a hash code value for this object.
    static <T, U> Tuple2<T,U>
    of(T first, U second)
    Returns a Tuple2 consisting of the specified components.
    Returns the value of the second record component.
    Converts this instance to an immutable Map entry.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Tuple2

      public Tuple2(T first, U second)
      Instantiates a new Tuple2.
      Parameters:
      first - The first component of the 2-tuple
      second - The second component of the 2-tuple
  • Method Details

    • of

      public static <T, U> Tuple2<T,U> of(T first, U second)
      Returns a Tuple2 consisting of the specified components.
      Type Parameters:
      T - The type of the first component
      U - The type of the second component
      Parameters:
      first - The first component of the 2-tuple
      second - The second component of the 2-tuple
      Returns:
      A Tuple2 instance containing the specified values
    • toEntry

      public Map.Entry<T,U> toEntry()
      Converts this instance to an immutable Map entry.
      Returns:
      an immutable Map entry
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • first

      public T first()
      Returns the value of the first record component.
      Returns:
      the value of the first record component
    • second

      public U second()
      Returns the value of the second record component.
      Returns:
      the value of the second record component