Class ComparablePair<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>>
- java.lang.Object
-
- dk.cloudcreate.essentials.shared.functional.tuple.comparable.ComparablePair<T1,T2>
-
- Type Parameters:
T1- the first element typeT2- the second element type
- All Implemented Interfaces:
ComparableTuple<ComparablePair<T1,T2>>,Serializable,Comparable<ComparablePair<T1,T2>>
public class ComparablePair<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>> extends Object implements ComparableTuple<ComparablePair<T1,T2>>
Represents aComparableTuplewith two elements.
Note:ComparablePairsupportsequals(Object)comparison using subclasses, e.g.:public class LeftAndRightSide extends ComparablePair<String, String> { public LeftAndRightSide(String leftSide, String rightSide) { super(leftSide, rightSide); } }- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ComparablePair(T1 t1, T2 t2)Construct a newComparableTuplewith 2 elements
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T1_1()The first element in this tupleT2_2()The second element in this tupleintarity()Number of arguments/elements in the TupleintcompareTo(ComparablePair<T1,T2> o)booleanequals(Object o)inthashCode()<R1 extends Comparable<? super R1>,R2 extends Comparable<? super R2>>
ComparablePair<R1,R2>map(BiFunction<? super T1,? super T2,ComparablePair<R1,R2>> mappingFunction)Maps the elements of thisComparablePairusing the mapping function<R1 extends Comparable<? super R1>,R2 extends Comparable<? super R2>>
ComparablePair<R1,R2>map(Function<? super T1,? super R1> mappingFunction1, Function<? super T2,? super R2> mappingFunction2)Maps the elements of thisComparablePairusing two distinct mapping functions<R1 extends Comparable<? super R1>>
ComparablePair<R1,T2>map1(Function<? super T1,? super R1> mappingFunction1)Map the first element of thisComparablePairusing the mapping function<R2 extends Comparable<? super R2>>
ComparablePair<T1,R2>map2(Function<? super T2,? super R2> mappingFunction2)Map the second element of thisComparablePairusing the mapping functionComparablePair<T2,T1>swap()Swap the elements of thisComparablePairMap.Entry<T1,T2>toEntry()List<?>toList()Convert the Tuple to a listStringtoString()
-
-
-
Field Detail
-
_1
public final T1 extends Comparable<? super T1> _1
The first element in this tuple
-
_2
public final T2 extends Comparable<? super T2> _2
The second element in this tuple
-
-
Constructor Detail
-
ComparablePair
public ComparablePair(T1 t1, T2 t2)
Construct a newComparableTuplewith 2 elements- Parameters:
t1- the first elementt2- the second element
-
-
Method Detail
-
arity
public int arity()
Description copied from interface:ComparableTupleNumber of arguments/elements in the Tuple- Specified by:
arityin interfaceComparableTuple<T1 extends Comparable<? super T1>>- Returns:
- Number of arguments/elements in the Tuple
-
toList
public List<?> toList()
Description copied from interface:ComparableTupleConvert the Tuple to a list- Specified by:
toListin interfaceComparableTuple<T1 extends Comparable<? super T1>>- Returns:
- list of all Tuple elements
-
_1
public T1 _1()
The first element in this tuple- Returns:
- The first element in this tuple
-
_2
public T2 _2()
The second element in this tuple- Returns:
- The second element in this tuple
-
swap
public ComparablePair<T2,T1> swap()
Swap the elements of thisComparablePair- Returns:
- A new
ComparablePairwhere the first element is the second element of thisComparablePairAND where the second element is the first element of thisComparablePair
-
toEntry
public Map.Entry<T1,T2> toEntry()
- Returns:
- a
Map.Entrywhere the key is the first element of thisComparablePairand the value is the second element of thisComparablePair
-
compareTo
public int compareTo(ComparablePair<T1,T2> o)
- Specified by:
compareToin interfaceComparable<T1 extends Comparable<? super T1>>
-
map
public <R1 extends Comparable<? super R1>,R2 extends Comparable<? super R2>> ComparablePair<R1,R2> map(BiFunction<? super T1,? super T2,ComparablePair<R1,R2>> mappingFunction)
Maps the elements of thisComparablePairusing the mapping function- Type Parameters:
R1- result type for first element of theComparablePairafter applying the mapping functionR2- result type for second element of theComparablePairafter applying the mapping function- Parameters:
mappingFunction- the mapping function- Returns:
- a new
ComparablePairwith the result of applying the mapping function to thisComparablePair
-
map
public <R1 extends Comparable<? super R1>,R2 extends Comparable<? super R2>> ComparablePair<R1,R2> map(Function<? super T1,? super R1> mappingFunction1, Function<? super T2,? super R2> mappingFunction2)
Maps the elements of thisComparablePairusing two distinct mapping functions- Type Parameters:
R1- result type for first element of theComparablePairafter applying the mapping functionR2- result type for second element of theComparablePairafter applying the mapping function- Parameters:
mappingFunction1- the mapping function for element number 1mappingFunction2- the mapping function for element number 2- Returns:
- a new
ComparablePairwith the result of applying the mapping function to thisComparablePair
-
map1
public <R1 extends Comparable<? super R1>> ComparablePair<R1,T2> map1(Function<? super T1,? super R1> mappingFunction1)
Map the first element of thisComparablePairusing the mapping function- Type Parameters:
R1- result type for first element of theComparablePairafter applying the mapping function- Parameters:
mappingFunction1- the mapping function for element number 1- Returns:
- a new
ComparablePairwith the result of applying the mapping function to the first element of thisComparablePair
-
map2
public <R2 extends Comparable<? super R2>> ComparablePair<T1,R2> map2(Function<? super T2,? super R2> mappingFunction2)
Map the second element of thisComparablePairusing the mapping function- Type Parameters:
R2- result type for second element of theComparablePairafter applying the mapping function- Parameters:
mappingFunction2- the mapping function for element number 2- Returns:
- a new
ComparablePairwith the result of applying the mapping function to the second element of thisComparablePair
-
-