Package com.atlassian.bamboo.utils.safe
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 valueB
- the type of the second value
A generic class representing a pair of values.
- Since:
- 10.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.first()
Returns the value of thefirst
record component.final int
hashCode()
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.second()
Returns the value of thesecond
record component.swap()
Swaps the first and second values of the pair.final String
toString()
Returns a string representation of this record class.Creates a new pair with the specified first value and the current second value.withSecond
(B newSecond) Creates a new pair with the specified second value and the current first value.
-
Constructor Details
-
Pair
Creates an instance of aPair
record class.- Parameters:
first
- the value for thefirst
record componentsecond
- the value for thesecond
record component
-
-
Method Details
-
make
Creates a new pair with the specified values.- Type Parameters:
A
- the type of the first valueB
- the type of the second value- Parameters:
first
- the first value, must not be nullsecond
- the second value, must not be null- Returns:
- a new pair with the specified values
- Throws:
NullPointerException
- if either value is null
-
withFirst
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
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
Swaps the first and second values of the pair.- Returns:
- a new pair with the first and second values swapped
-
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. -
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. -
equals
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 withObjects::equals(Object,Object)
. -
first
Returns the value of thefirst
record component.- Returns:
- the value of the
first
record component
-
second
Returns the value of thesecond
record component.- Returns:
- the value of the
second
record component
-