Record Class Pair<A,B>

java.lang.Object
java.lang.Record
com.atlassian.bamboo.utils.safe.Pair<A,B>
Type Parameters:
A - the type of the first value
B - the type of the second value

public record Pair<A,B>(A first, B second) extends Record
A generic class representing a pair of values.
Since:
10.2
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pair(A first, B second)
    Creates an instance of a Pair 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.
    static <A, B> @NotNull Pair<A,B>
    make(A first, B second)
    Creates a new pair with the specified values.
    Returns the value of the second record component.
    @NotNull Pair<B,A>
    Swaps the first and second values of the pair.
    final String
    Returns a string representation of this record class.
    @NotNull Pair<A,B>
    withFirst(A newFirst)
    Creates a new pair with the specified first value and the current second value.
    @NotNull Pair<A,B>
    withSecond(B newSecond)
    Creates a new pair with the specified second value and the current first value.

    Methods inherited from class java.lang.Object

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

    • Pair

      public Pair(@NotNull A first, @NotNull B second)
      Creates an instance of a Pair record class.
      Parameters:
      first - the value for the first record component
      second - the value for the second record component
  • Method Details

    • make

      @NotNull public static <A, B> @NotNull Pair<A,B> make(@NotNull A first, @NotNull B second)
      Creates a new pair with the specified values.
      Type Parameters:
      A - the type of the first value
      B - the type of the second value
      Parameters:
      first - the first value, must not be null
      second - the second value, must not be null
      Returns:
      a new pair with the specified values
      Throws:
      NullPointerException - if either value is null
    • withFirst

      @NotNull public @NotNull Pair<A,B> withFirst(@NotNull A newFirst)
      Creates a new pair with the specified first value and the current second value.
      Parameters:
      newFirst - the new first value, must not be null
      Returns:
      a new pair with the specified first value and the current second value
      Throws:
      NullPointerException - if the new first value is null
    • withSecond

      @NotNull public @NotNull Pair<A,B> withSecond(@NotNull B newSecond)
      Creates a new pair with the specified second value and the current first value.
      Parameters:
      newSecond - the new second value, must not be null
      Returns:
      a new pair with the specified second value and the current first value
      Throws:
      NullPointerException - if the new second value is null
    • swap

      @NotNull public @NotNull Pair<B,A> swap()
      Swaps the first and second values of the pair.
      Returns:
      a new pair with the first and second values swapped
    • 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

      @NotNull public A first()
      Returns the value of the first record component.
      Returns:
      the value of the first record component
    • second

      @NotNull public B second()
      Returns the value of the second record component.
      Returns:
      the value of the second record component