Package software.amazon.awssdk.utils
Class Either<L,R>
- java.lang.Object
-
- software.amazon.awssdk.utils.Either<L,R>
-
- Type Parameters:
L
- Left typeR
- Right type
public final class Either<L,R> extends Object
Represents a value that can be one of two types.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(Consumer<? super L> lFunc, Consumer<? super R> rFunc)
Apply the consumers to the left or the right value depending on which is present.boolean
equals(Object o)
static <L,R>
Optional<Either<L,R>>fromNullable(L left, R right)
Create a newOptional<Either>
from two possibly null values.int
hashCode()
Optional<L>
left()
static <L,R>
Either<L,R>left(L value)
Create a new Either with the left type.<T> T
map(Function<? super L,? extends T> lFunc, Function<? super R,? extends T> rFunc)
Maps the Either to a type and returns the resolved value (which may be from the left or the right value).<T> Either<T,R>
mapLeft(Function<? super L,? extends T> lFunc)
Map the left most value and return a new Either reflecting the new types.<T> Either<L,T>
mapRight(Function<? super R,? extends T> rFunc)
Map the right most value and return a new Either reflecting the new types.Optional<R>
right()
static <L,R>
Either<L,R>right(R value)
Create a new Either with the right type.
-
-
-
Method Detail
-
map
public <T> T map(Function<? super L,? extends T> lFunc, Function<? super R,? extends T> rFunc)
Maps the Either to a type and returns the resolved value (which may be from the left or the right value).- Type Parameters:
T
- Type that both the left and right should be mapped to.- Parameters:
lFunc
- Function that maps the left value if present.rFunc
- Function that maps the right value if present.- Returns:
- Mapped value from either lFunc or rFunc depending on which value is present.
-
mapLeft
public <T> Either<T,R> mapLeft(Function<? super L,? extends T> lFunc)
Map the left most value and return a new Either reflecting the new types.- Type Parameters:
T
- New type of left value.- Parameters:
lFunc
- Function that maps the left value if present.- Returns:
- New Either bound to the new left type and the same right type.
-
mapRight
public <T> Either<L,T> mapRight(Function<? super R,? extends T> rFunc)
Map the right most value and return a new Either reflecting the new types.- Type Parameters:
T
- New type of right value.- Parameters:
rFunc
- Function that maps the right value if present.- Returns:
- New Either bound to the same left type and the new right type.
-
apply
public void apply(Consumer<? super L> lFunc, Consumer<? super R> rFunc)
Apply the consumers to the left or the right value depending on which is present.- Parameters:
lFunc
- Consumer of left value, invoked if left value is present.rFunc
- Consumer of right value, invoked if right value is present.
-
left
public static <L,R> Either<L,R> left(L value)
Create a new Either with the left type.- Type Parameters:
L
- Left typeR
- Right type- Parameters:
value
- Left value
-
right
public static <L,R> Either<L,R> right(R value)
Create a new Either with the right type.- Type Parameters:
L
- Left typeR
- Right type- Parameters:
value
- Right value
-
fromNullable
public static <L,R> Optional<Either<L,R>> fromNullable(L left, R right)
Create a newOptional<Either>
from two possibly null values. If both values are null,Optional.empty()
is returned. Only one of the left or right values is allowed to be non-null, otherwise anIllegalArgumentException
is thrown.- Type Parameters:
L
- Left typeR
- Right type- Parameters:
left
- The left value (possibly null)right
- The right value (possibly null)- Returns:
- an Optional Either representing one of the two values or empty if both are null
-
-