Package ffx.utilities

Record Class ObjectPair<T,S extends Comparable<S>>

java.lang.Object
java.lang.Record
ffx.utilities.ObjectPair<T,S>
Type Parameters:
T - The class of the non-comparable object.
S - The class of the indexing, comparable object.
Record Components:
val - The non-comparable object.
key - The indexing, comparable object.
All Implemented Interfaces:
Comparable<ObjectPair<T,S>>

public record ObjectPair<T,S extends Comparable<S>>(T val, S extends Comparable<S> key) extends Record implements Comparable<ObjectPair<T,S>>
ObjectPair record.

Implements a comparable pair, where a non-comparable T can be compared via a comparable S.

Since:
1.0
Author:
Jacob Litman
  • Constructor Details

    • ObjectPair

      public ObjectPair(T val, S key)
      Creates an instance of a ObjectPair record class.
      Parameters:
      val - the value for the val record component
      key - the value for the key record component
  • Method Details

    • sortAndReturn

      public static <U, V extends Comparable<V>> List<U> sortAndReturn(List<ObjectPair<U,V>> theList)
      sortAndReturn.
      Type Parameters:
      U - Some object.
      V - Some indexing, comparable object
      Parameters:
      theList - a List object.
      Returns:
      the sorted List of objects.
    • compareTo

      public int compareTo(ObjectPair<T,S> o)
      Specified by:
      compareTo in interface Comparable<T>
    • 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.
    • val

      public T val()
      Returns the value of the val record component.
      Returns:
      the value of the val record component
    • key

      public S key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component