Class Pair<T1,T2>
java.lang.Object
dk.cloudcreate.essentials.shared.functional.tuple.Pair<T1,T2>
- Type Parameters:
T1- the first element typeT2- the second element type
- All Implemented Interfaces:
Tuple<Pair<T1,,T2>> Serializable
Represents a
Note:
Tuple with two elements.Note:
Pair supports equals(Object) comparison using subclasses, e.g.:
public class LeftAndRightSide extends Pair<String, String> {
public LeftAndRightSide(String leftSide, String rightSide) {
super(leftSide, rightSide);
}
}
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription_1()The first element in this tuple_2()The second element in this tupleintarity()Number of arguments/elements in the TuplebooleaninthashCode()<R1,R2> Pair<R1, R2> map(BiFunction<? super T1, ? super T2, Pair<R1, R2>> mappingFunction) Maps the elements of thisPairusing the mapping function<R1,R2> Pair<R1, R2> map(Function<? super T1, ? super R1> mappingFunction1, Function<? super T2, ? super R2> mappingFunction2) Maps the elements of thisPairusing two distinct mapping functionsMap the first element of thisPairusing the mapping functionMap the second element of thisPairusing the mapping functionstatic <T1,T2> Pair<T1, T2> of(T1 t1, T2 t2) Create a newTuplewith 2 elementsswap()Swap the elements of thisPairtoEntry()List<?>toList()Convert the Tuple to a listtoString()
-
Field Details
-
_1
The first element in this tuple -
_2
The second element in this tuple
-
-
Constructor Details
-
Pair
Construct a newTuplewith 2 elements- Parameters:
t1- the first elementt2- the second element
-
-
Method Details
-
of
Create a newTuplewith 2 elements- Type Parameters:
T1- the first element typeT2- the second element type- Parameters:
t1- the first elementt2- the second element- Returns:
- the newly created
Pairtuple
-
arity
public int arity()Description copied from interface:TupleNumber of arguments/elements in the Tuple -
toList
Description copied from interface:TupleConvert the Tuple to a list -
_1
The first element in this tuple- Returns:
- The first element in this tuple
-
_2
The second element in this tuple- Returns:
- The second element in this tuple
-
swap
Swap the elements of thisPair -
toEntry
-
map
Maps the elements of thisPairusing the mapping function- Type Parameters:
R1- result type for first element of thePairafter applying the mapping functionR2- result type for second element of thePairafter applying the mapping function- Parameters:
mappingFunction- the mapping function- Returns:
- a new
Pairwith the result of applying the mapping function to thisPair
-
map
public <R1,R2> Pair<R1,R2> map(Function<? super T1, ? super R1> mappingFunction1, Function<? super T2, ? super R2> mappingFunction2) Maps the elements of thisPairusing two distinct mapping functions- Type Parameters:
R1- result type for first element of thePairafter applying the mapping functionR2- result type for second element of thePairafter applying the mapping function- Parameters:
mappingFunction1- the mapping function for element number 1mappingFunction2- the mapping function for element number 2- Returns:
- a new
Pairwith the result of applying the mapping function to thisPair
-
map1
Map the first element of thisPairusing the mapping function -
map2
Map the second element of thisPairusing the mapping function -
equals
-
hashCode
public int hashCode() -
toString
-