Class Pair<L,R> 
- Type Parameters:
- L- the left element type
- R- the right element type
- All Implemented Interfaces:
- Serializable,- Comparable<Pair<L,,- R>> - Map.Entry<L,- R> 
- Direct Known Subclasses:
- Diff,- ImmutablePair,- MutablePair
This class is an abstract implementation defining the basic API.
 It refers to the elements as 'left' and 'right'. It also implements the
 Map.Entry interface where the key is 'left' and the value is '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:
- 3.0
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription<E extends Throwable>
 voidaccept(FailableBiConsumer<L, R, E> consumer) Accepts this key and value as arguments to the given consumer.<V,E extends Throwable> 
 Vapply(FailableBiFunction<L, R, V, E> function) Applies this key and value as arguments to the given function.intCompares the pair based on the left element followed by the right element.static <L,R> Pair<L, R>[] Returns the empty array singleton that can be assigned without compiler warning.booleanCompares this pair to another based on the two elements.final LgetKey()Gets the key from this pair.abstract LgetLeft()Gets the left element from this pair.abstract RgetRight()Gets the right element from this pair.getValue()Gets the value from this pair.inthashCode()Returns a suitable hash code.static <L,R> Pair<L, R> Creates an immutable pair from a map entry.static <L,R> Pair<L, R> of(L left, R right) Creates an immutable pair of two objects inferring the generic types.static <L,R> Pair<L, R> ofNonNull(L left, R right) Creates an immutable pair of two non-null objects inferring the generic types.toString()Returns a String representation of this pair using the format($left,$right).Formats the receiver using the given format.
- 
Field Details- 
EMPTY_ARRAYAn empty array.Consider using emptyArray()to avoid generics warnings.- Since:
- 3.10.
 
 
- 
- 
Constructor Details- 
Pairpublic Pair()Constructs a new instance.
 
- 
- 
Method Details- 
emptyArrayReturns the empty array singleton that can be assigned without compiler warning.- Type Parameters:
- L- the left element type
- R- the right element type
- Returns:
- the empty array singleton that can be assigned without compiler warning.
- Since:
- 3.10.
 
- 
ofCreates an immutable pair of 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
 
- 
ofCreates an immutable pair from a map entry.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:
- pair- the map entry.
- Returns:
- a pair formed from the map entry
- Since:
- 3.10
 
- 
ofNonNullCreates an immutable pair of two non-null 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 not be null
- right- the right element, may not be null
- Returns:
- a pair formed from the two parameters, not null
- Throws:
- NullPointerException- if any input is null
- Since:
- 3.13.0
 
- 
acceptAccepts this key and value as arguments to the given consumer.- Type Parameters:
- E- The kind of thrown exception or error.
- Parameters:
- consumer- the consumer to call.
- Throws:
- E- Thrown when the consumer fails.
- Since:
- 3.13.0
 
- 
applyApplies this key and value as arguments to the given function.- Type Parameters:
- V- The function return type.
- E- The kind of thrown exception or error.
- Parameters:
- function- the consumer to call.
- Returns:
- the function's return value.
- Throws:
- E- Thrown when the consumer fails.
- Since:
- 3.13.0
 
- 
compareToCompares the pair based on the left element followed by the right element. The types must beComparable.- Specified by:
- compareToin interface- Comparable<L>
- Parameters:
- other- the other pair, not null
- Returns:
- negative if this is less, zero if equal, positive if greater
 
- 
equalsCompares this pair to another based on the two elements.
- 
getKeyGets the key from this pair.This method implements the Map.Entryinterface returning the left element as the key.
- 
getLeftGets the left element from this pair.When treated as a key-value pair, this is the key. - Returns:
- the left element, may be null
 
- 
getRightGets the right element from this pair.When treated as a key-value pair, this is the value. - Returns:
- the right element, may be null
 
- 
getValueGets the value from this pair.This method implements the Map.Entryinterface returning the right element as the value.
- 
hashCodeReturns a suitable hash code. The hash code follows the definition inMap.Entry.
- 
toStringReturns a String representation of this pair using the format($left,$right).
- 
toStringFormats the receiver using the given format.This uses Formattableto perform the formatting. Two variables may be used to embed the left and right elements. Use%1$sfor the left element (key) and%2$sfor the right element (value). The default format used bytoString()is(%1$s,%2$s).- Parameters:
- format- the format string, optionally containing- %1$sand- %2$s, not null
- Returns:
- the formatted string, not null
 
 
-