Record Class ImmutablePair<K,V>

java.lang.Object
java.lang.Record
fr.alasdiablo.diolib.util.ImmutablePair<K,V>
Type Parameters:
K - Type of the first value
V - Type of the second value

public record ImmutablePair<K,V>(K key, V value) extends Record
Define a tuple of two values
  • Constructor Summary

    Constructors
    Constructor
    Description
    ImmutablePair(K key, V value)
    Creates an instance of a ImmutablePair record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if two pairs are equals
    int
    Create a hash of the current pair
    key()
    Returns the value of the key record component.
    static <K, V> @NotNull ImmutablePair<K,V>
    of(K key, V value)
    Static factory use to create a pair
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

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

    • ImmutablePair

      public ImmutablePair(K key, V value)
      Creates an instance of a ImmutablePair record class.
      Parameters:
      key - the value for the key record component
      value - the value for the value record component
  • Method Details

    • of

      @Contract("_, _ -> new") @NotNull public static <K, V> @NotNull ImmutablePair<K,V> of(K key, V value)
      Static factory use to create a pair
      Type Parameters:
      K - Type of the first value
      V - Type of the second value
      Parameters:
      key - first value
      value - seconde value
      Returns:
      Create a pair containing two values
    • equals

      public boolean equals(Object o)
      Check if two pairs are equals
      Specified by:
      equals in class Record
      Parameters:
      o - Pair to compare with the current one
      Returns:
      true if it is the same, false in another case
    • hashCode

      public int hashCode()
      Create a hash of the current pair
      Specified by:
      hashCode in class Record
      Returns:
      A hash build from the two values
    • 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
    • key

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

      public V value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component