Record Class Pair<L,R>

java.lang.Object
java.lang.Record
org.tquadrat.foundation.lang.Pair<L,R>
Type Parameters:
L - The type for the left value.
R - The type for the right value.
Record Components:
left - The left value of the pair.
right - The right value of the pair.

@ClassVersion(sourceVersion="$Id: Pair.java 1119 2024-03-16 09:03:57Z tquadrat $") @API(status=STABLE, since="0.1.0") public record Pair<L,R>(L left, R right) extends Record

The implementation of a tupel.

Both values are allowed to be null.

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: Pair.java 1119 2024-03-16 09:03:57Z tquadrat $
Since:
0.1.0
UML Diagram
UML Diagram for "org.tquadrat.foundation.lang.Pair"

UML Diagram for "org.tquadrat.foundation.lang.Pair"

UML Diagram for "org.tquadrat.foundation.lang.Pair"
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final L
    The field for the left record component.
    private final R
    The field for the right record component.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    final Map.Entry<L,R>
    Returns this instance of Pair as an instance of Map.Entry.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the left record component.
    final Pair<L,R>
    left(L newLeft)
    Creates a new instance of Pair with the right value from this one and the given new left value.
    Returns the value of the right record component.
    final Pair<L,R>
    right(R newRight)
    Creates a new instance of Pair with the left value from this one and the given new right value.
    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

    • left

      private final L left
      The field for the left record component.
  • Constructor Details

    • Pair

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

    • asEntry

      public final Map.Entry<L,R> asEntry()

      Returns this instance of Pair as an instance of Map.Entry. The left value is the key, the right value is the value.

      The method Map.Entry.setValue(Object) is not implemented and will throw an exception when called.

      Returns:
      A reference to this instance as an Entry.
    • left

      public final Pair<L,R> left(L newLeft)
      Creates a new instance of Pair with the right value from this one and the given new left value.
      Parameters:
      newLeft - The new left value; can be null.
      Returns:
      A new instance of Pair.
    • right

      public final Pair<L,R> right(R newRight)
      Creates a new instance of Pair with the left value from this one and the given new right value.
      Parameters:
      newRight - The new right value; can be null.
      Returns:
      A new instance of Pair.
    • 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.
    • 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