Record Class Tuple<L,R>

java.lang.Object
java.lang.Record
nl.colorize.util.stats.Tuple<L,R>
Type Parameters:
L - Type of the first (left) element.
R - Type of the second (right) element.

public record Tuple<L,R>(L left, R right) extends Record
Data structure that consists of two ordered values, sometimes also referred to as a pair. Tuples are immutable and may contain null values.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tuple(L left, R right)
    Creates an instance of a Tuple record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(Object element)
    Returns true if element is one of this tuple's elements.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns a new tuple with the inverse of this tuple's elements.
    Returns the value of the left record component.
    <L2, R2> Tuple<L2,R2>
    map(Function<L,L2> leftMapper, Function<R,R2> rightMapper)
     
    static <L, R> Tuple<L,R>
    of(L left, R right)
    Convenience factory method to create a tuple without having to specify the generic types.
    Returns the value of the right record component.
    Returns the string representation of this tuple.

    Methods inherited from class java.lang.Object

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

    • Tuple

      public Tuple(L left, R right)
      Creates an instance of a Tuple record class.
      Parameters:
      left - the value for the left record component
      right - the value for the right record component
  • Method Details

    • contains

      public boolean contains(Object element)
      Returns true if element is one of this tuple's elements.
    • inverse

      public Tuple<R,L> inverse()
      Returns a new tuple with the inverse of this tuple's elements. For example, the inverse of the tuple (A, B) will return the tuple (B, A).
    • map

      public <L2, R2> Tuple<L2,R2> map(Function<L,L2> leftMapper, Function<R,R2> rightMapper)
    • toString

      public String toString()
      Returns the string representation of this tuple. The returned string is in the format "(X, Y)", where X and Y are determined by the string representation of the elements of this tuple.
      Specified by:
      toString in class Record
    • of

      public static <L, R> Tuple<L,R> of(L left, R right)
      Convenience factory method to create a tuple without having to specify the generic types.
    • 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.
    • left

      public L left()
      Returns the value of the left record component.
      Returns:
      the value of the left record component
    • right

      public R right()
      Returns the value of the right record component.
      Returns:
      the value of the right record component