Record Class AnyTuple2<T,U>

java.lang.Object
java.lang.Record
org.klojang.util.AnyTuple2<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
All Implemented Interfaces:
org.klojang.check.aux.Emptyable

public record AnyTuple2<T,U>(T first, U second) extends Record implements org.klojang.check.aux.Emptyable
Generic 2-tuple of arbitrarily typed objects, both of which are allowed to be null.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnyTuple2(T first, U second)
    Creates an instance of a AnyTuple2 record class.
  • 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.
    boolean
    Returns true if both components are recursively non-empty as per ObjectMethods.isDeepNotEmpty(Object).
    boolean
    Returns true if both components are null, otherwise false.
    static <T, U> AnyTuple2<T,U>
    of(T first, U second)
    Returns a AnyTuple2 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

    • AnyTuple2

      public AnyTuple2(T first, U second)
      Creates an instance of a AnyTuple2 record class.
      Parameters:
      first - the value for the first record component
      second - the value for the second record component
  • Method Details

    • of

      public static <T, U> AnyTuple2<T,U> of(T first, U second)
      Returns a AnyTuple2 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
    • isEmpty

      public boolean isEmpty()
      Returns true if both components are null, otherwise false.
      Specified by:
      isEmpty in interface org.klojang.check.aux.Emptyable
      Returns:
      true if both components are null
    • isDeepNotEmpty

      public boolean isDeepNotEmpty()
      Returns true if both components are recursively non-empty as per ObjectMethods.isDeepNotEmpty(Object).
      Specified by:
      isDeepNotEmpty in interface org.klojang.check.aux.Emptyable
      Returns:
      true if both components are recursively non-empty
    • 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