A - the first element typeB - the second element typepublic final class Pair<A,B> extends Object implements org.joda.beans.ImmutableBean, Tuple, Comparable<Pair<A,B>>, Serializable
This implementation refers to the elements as 'first' and 'second'. The elements cannot be null.
Although the implementation is immutable, there is no restriction on the objects that may be stored. If mutable objects are stored in the pair, then the pair itself effectively becomes mutable.
Some primitive specializations of this class are provided, such as DoublesPair.
This class is immutable and thread-safe if the stored objects are immutable.
| Modifier and Type | Class and Description |
|---|---|
static class |
Pair.Meta<A,B>
The meta-bean for
Pair. |
| Modifier and Type | Method and Description |
|---|---|
<C,D> Pair<A,B> |
combinedWith(Pair<C,D> other,
BiFunction<? super A,? super C,? extends A> combinerFirst,
BiFunction<? super B,? super D,? extends B> combinerSecond)
Combines this instance with another.
|
static <A,B> BinaryOperator<Pair<A,B>> |
combining(BiFunction<? super A,? super A,? extends A> combinerFirst,
BiFunction<? super B,? super B,? extends B> combinerSecond)
Returns a combiner of pair instances.
|
int |
compareTo(Pair<A,B> other)
Compares the pair based on the first element followed by the second element.
|
ImmutableList<Object> |
elements()
Gets the elements from this pair as a list.
|
boolean |
equals(Object obj) |
A |
getFirst()
Gets the first element in this pair.
|
B |
getSecond()
Gets the second element in this pair.
|
int |
hashCode() |
static Pair.Meta |
meta()
The meta-bean for
Pair. |
Pair.Meta<A,B> |
metaBean() |
static <R,S> Pair.Meta<R,S> |
metaPair(Class<R> cls1,
Class<S> cls2)
The meta-bean for
Pair. |
static <A,B> Pair<A,B> |
of(A first,
B second)
Obtains a pair inferring the types.
|
int |
size()
Gets the number of elements held by this pair.
|
String |
toString()
Gets the pair using a standard string format.
|
public static <A,B> Pair<A,B> of(A first, B second)
A - the first element typeB - the second element typefirst - the first elementsecond - the second elementpublic static <A,B> BinaryOperator<Pair<A,B>> combining(BiFunction<? super A,? super A,? extends A> combinerFirst, BiFunction<? super B,? super B,? extends B> combinerSecond)
This is useful if you have a stream of Pair<A, B> and would like to reduce.
e.g
pairList.stream()
.reduce(Pair.combining(A::combinedWith, B::combinedWith))
A - the type of the first valuesB - the type of the second valuescombinerFirst - the combiner of first valuescombinerSecond - the combiner of second valuespublic <C,D> Pair<A,B> combinedWith(Pair<C,D> other, BiFunction<? super A,? super C,? extends A> combinerFirst, BiFunction<? super B,? super D,? extends B> combinerSecond)
C - the type of the first value in the other instanceD - the type of the second value in the other instanceother - the other paircombinerFirst - the combiner of first valuescombinerSecond - the combiner of second valuespublic int size()
public ImmutableList<Object> elements()
The list returns each element in the pair in order.
public int compareTo(Pair<A,B> other)
The element types must be Comparable.
compareTo in interface Comparable<Pair<A,B>>other - the other pairClassCastException - if either object is not comparablepublic String toString()
The standard format is '[$first, $second]'. Spaces around the values are trimmed.
public static Pair.Meta meta()
Pair.public static <R,S> Pair.Meta<R,S> metaPair(Class<R> cls1, Class<S> cls2)
Pair.R - the first generic typeS - the second generic typecls1 - the first generic typecls2 - the second generic typepublic A getFirst()
public B getSecond()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.