Class Tuple<A,B>
- java.lang.Object
-
- org.bytemechanics.commons.functional.Tuple<A,B>
-
- Type Parameters:
A
- first valueB
- second value
public class Tuple<A,B> extends Object
Immutable object to keep context of two values- Since:
- 1.3.0
- Author:
- afarre
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object _tuple)
A
getLeft()
Getter for left valueB
getRight()
Getter for right valueint
hashCode()
A
left()
return left value<C> Tuple<C,B>
left(C _newValue)
Create a clone tuple with the left value replaced with the given one<C> Tuple<C,B>
left(Function<A,C> _converter)
Create a clone tuple with the left value result of the current left value applying the given converterstatic <LEFT,RIGHT>
Tuple<LEFT,RIGHT>of(LEFT _left, RIGHT _right)
Create a new Tuple form scratch with the given valuesB
right()
return right value<C> Tuple<A,C>
right(C _newValue)
Create a clone tuple with the right value replaced with the given one<C> Tuple<A,C>
right(Function<B,C> _converter)
Create a clone tuple with the right value result of the current right value applying the given converterString
toString()
<C,D>
Tuple<C,D>with(C _left, D _right)
Create a clone tuple with the new given values<C,D>
Tuple<C,D>with(Function<A,C> _leftConverter, Function<B,D> _rightConverter)
Create a clone tuple with the left and right values converted with the given converters
-
-
-
Method Detail
-
getLeft
public A getLeft()
Getter for left value- Returns:
- left value
-
left
public A left()
return left value- Returns:
- left value
-
getRight
public B getRight()
Getter for right value- Returns:
- right value
-
right
public B right()
return right value- Returns:
- right value
-
left
public <C> Tuple<C,B> left(C _newValue)
Create a clone tuple with the left value replaced with the given one- Type Parameters:
C
- type of the new left value- Parameters:
_newValue
- new value to replace in the cloned tuple- Returns:
- clone of this tuple with the left value replaced by _newValue
-
left
public <C> Tuple<C,B> left(Function<A,C> _converter)
Create a clone tuple with the left value result of the current left value applying the given converter- Type Parameters:
C
- type of the new left value- Parameters:
_converter
- function to convert the left value- Returns:
- clone of this tuple with the left value replaced with the result of apply _converter to the current left value
- Since:
- 1.7.0
-
right
public <C> Tuple<A,C> right(C _newValue)
Create a clone tuple with the right value replaced with the given one- Type Parameters:
C
- type of the new right value- Parameters:
_newValue
- new value to replace in the cloned tuple- Returns:
- clone of this tuple with the right value replaced by _newValue
-
right
public <C> Tuple<A,C> right(Function<B,C> _converter)
Create a clone tuple with the right value result of the current right value applying the given converter- Type Parameters:
C
- type of the new right value- Parameters:
_converter
- function to convert the right value- Returns:
- clone of this tuple with the right value replaced with the result of apply _converter to the current right value
- Since:
- 1.7.0
-
with
public <C,D> Tuple<C,D> with(C _left, D _right)
Create a clone tuple with the new given values- Type Parameters:
C
- type of the new left valueD
- type of the new right value- Parameters:
_left
- new left value to replace in the cloned tuple_right
- new right value to replace in the cloned tuple- Returns:
- clone of this tuple with the right and the left values replaced
-
with
public <C,D> Tuple<C,D> with(Function<A,C> _leftConverter, Function<B,D> _rightConverter)
Create a clone tuple with the left and right values converted with the given converters- Type Parameters:
C
- type of the new left valueD
- type of the new right value- Parameters:
_leftConverter
- function to convert the right value_rightConverter
- function to convert the right value- Returns:
- clone of this tuple with the right and left value replaced with the result of apply _converters to the current values
- Since:
- 1.7.0
-
of
public static final <LEFT,RIGHT> Tuple<LEFT,RIGHT> of(LEFT _left, RIGHT _right)
Create a new Tuple form scratch with the given values- Type Parameters:
LEFT
- type of the new left valueRIGHT
- type of the new right value- Parameters:
_left
- left value_right
- right value- Returns:
- new Tuple form scratch with the given values
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classObject
- Returns:
- int hashcode representing this tuple
- See Also:
Object.hashCode()
-
equals
public boolean equals(Object _tuple)
- Overrides:
equals
in classObject
- Parameters:
_tuple
- tuple to compare with- Returns:
- true if this tuple is equals to the provided one
- See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
- Overrides:
toString
in classObject
- Returns:
- string representation of this tuple
- See Also:
Object.toString()
-
-