Class Pair<L,R>

java.lang.Object
net.dv8tion.jda.internal.utils.tuple.Pair<L,R>
Type Parameters:
L - the left element type
R - the right element type
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ImmutablePair, MutablePair

public abstract class Pair<L,R> extends Object implements Serializable
This class has been copied from Lang 3

A pair consisting of two elements.

This class is an abstract implementation defining the basic API. It refers to the elements as 'left' and 'right'.

Subclass implementations may be mutable or immutable. However, there is no restriction on the type of the stored objects that may be stored. If mutable objects are stored in the pair, then the pair itself effectively becomes mutable.

Since:
Lang 3.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compares this pair to another based on the two elements.
    abstract L
    Gets the left element from this pair.
    abstract R
    Gets the right element from this pair.
    int
    Returns a suitable hash code.
    static <L, R> Pair<L,R>
    of(L left, R right)
    Obtains an immutable pair of from two objects inferring the generic types.
    Returns a String representation of this pair using the format ($left,$right).

    Methods inherited from class java.lang.Object

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

    • Pair

      public Pair()
  • Method Details

    • of

      public static <L, R> Pair<L,R> of(L left, R right)

      Obtains an immutable pair of from two objects inferring the generic types.

      This factory allows the pair to be created using inference to obtain the generic types.

      Type Parameters:
      L - the left element type
      R - the right element type
      Parameters:
      left - the left element, may be null
      right - the right element, may be null
      Returns:
      a pair formed from the two parameters, not null
    • getLeft

      public abstract L getLeft()

      Gets the left element from this pair.

      When treated as a key-value pair, this is the key.

      Returns:
      the left element, may be null
    • getRight

      public abstract R getRight()

      Gets the right element from this pair.

      When treated as a key-value pair, this is the value.

      Returns:
      the right element, may be null
    • equals

      public boolean equals(Object obj)

      Compares this pair to another based on the two elements.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare to, null returns false
      Returns:
      true if the elements of the pair are equal
    • hashCode

      public int hashCode()

      Returns a suitable hash code. The hash code follows the definition in Map.Entry.

      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • toString

      public String toString()

      Returns a String representation of this pair using the format ($left,$right).

      Overrides:
      toString in class Object
      Returns:
      a string describing this object, not null