java.lang.Object
java.lang.Record
nl.jqno.equalsverifier.internal.reflection.Tuple<T>
Type Parameters:
T - The assumed type of the values.
Record Components:
red - The red value.
blue - The blue value.
redCopy - A shallow copy of the red value.

public record Tuple<T>(T red, T blue, T redCopy) extends Record
Container for three values of the same type: a "red" one, a "blue" one, and a shallow copy of the "red" one.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final T
    The field for the blue record component.
    private final T
    The field for the red record component.
    private final T
    The field for the redCopy record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tuple(T red, T blue, T redCopy)
    Creates an instance of a Tuple record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the blue record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    <U> Tuple<U>
    map(Function<T,U> fn)
    Returns a new Tuple with the given function applied to each element.
    red()
    Returns the value of the red record component.
    Returns the value of the redCopy record component.
    Returns a new Tuple with only the blue value switched to the given value and the other values left intact if the red value equals the blue value; otherwise, returns the original tuple.
    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
  • Field Details

    • red

      private final T red
      The field for the red record component.
    • blue

      private final T blue
      The field for the blue record component.
    • redCopy

      private final T redCopy
      The field for the redCopy record component.
  • Constructor Details

    • Tuple

      public Tuple(T red, T blue, T redCopy)
      Creates an instance of a Tuple record class.
      Parameters:
      red - the value for the red record component
      blue - the value for the blue record component
      redCopy - the value for the redCopy record component
  • Method Details

    • map

      public <U> Tuple<U> map(Function<T,U> fn)
      Returns a new Tuple with the given function applied to each element.
      Parameters:
      fn - The function to apply to all values.
      Returns:
      A new Tuple with the given function applied to each element.
    • swapBlueIfEqualToRed

      public Tuple<T> swapBlueIfEqualToRed(Supplier<T> newBlue)
      Returns a new Tuple with only the blue value switched to the given value and the other values left intact if the red value equals the blue value; otherwise, returns the original tuple. This is useful for single-element enums, where only one value can be provided: in those cases, perhaps an alternative can be provided (e.g. an empty list) using this method.
      Parameters:
      newBlue - A new value for blue.
      Returns:
      A new tuple with the blue value switched if red an blue are equal, or the original tuple otherwise.
    • 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.
    • red

      public T red()
      Returns the value of the red record component.
      Returns:
      the value of the red record component
    • blue

      public T blue()
      Returns the value of the blue record component.
      Returns:
      the value of the blue record component
    • redCopy

      public T redCopy()
      Returns the value of the redCopy record component.
      Returns:
      the value of the redCopy record component