L
- The left valueR
- The right valuepublic abstract class Either<L,R>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Either.Left<L,R>
A left projected
Either . |
static class |
Either.NotLeftException
An error that is thrown if an attempt is made to project an Either to
Either.Left when the object is actually an instance of Either.Right . |
static class |
Either.NotRightException
An error that is thrown if an attempt is made to project an Either to
Either.Right when the object is actually an instance of Either.Left . |
static class |
Either.Right<L,R>
A right projected
Either . |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
equals(java.lang.Object other) |
R |
get()
Get the right projected value of the either.
|
static <T> T |
getOrElse(Either<?,? extends T> either,
T t)
Get the right projected value of the either or a provided default value.
|
abstract int |
hashCode() |
abstract boolean |
isLeft()
Check whether this is a Left projection.
|
abstract boolean |
isRight()
Check whether this is a Right projection.
|
static <L,R,T extends L> |
left(T value)
Returns a left projected either.
|
static <L,R> Either.Left<L,R> |
leftProjection(Either<L,R> either)
Returns the Left projection for the provided Either or throws an exception if the Either is
actually an instance of
Either.Right . |
static <L,R,T extends R> |
right(T value)
Returns a right projected either.
|
static <L,R> Either.Right<L,R> |
rightProjection(Either<L,R> either)
Returns the Right projection for the provided Either or throws an exception if the Either is
actually an instance of
Either.Left . |
public static <L,R> Either.Left<L,R> leftProjection(Either<L,R> either) throws Either.NotLeftException
Either.Right
.L
- the left type of the either.R
- the right type of the either.either
- the either, assumed to be an instance of left, that willEither.NotLeftException
- if the value is a Either.Right
.public static <L,R> Either.Right<L,R> rightProjection(Either<L,R> either) throws Either.NotRightException
Either.Left
.L
- the left type of the either.R
- the right type of the either.either
- the either, assumed to be an instance of left, that willEither.NotRightException
- if the value is a Either.Left
.public abstract boolean isLeft()
public abstract boolean isRight()
public R get()
Either.NotRightException
- if this is a left projectionpublic static <T> T getOrElse(Either<?,? extends T> either, T t)
T
- the default typeeither
- the either from which the method extracts the result if it is a Either.Right
.t
- the default valuepublic abstract int hashCode()
hashCode
in class java.lang.Object
public abstract boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public static <L,R,T extends L> Either<L,R> left(T value)
L
- the type of the left parameter of the resultR
- the type of the right parameter of the resultT
- a refinement type that allows us to wrap subtypes of Lvalue
- the value to wrappublic static <L,R,T extends R> Either<L,R> right(T value)
L
- the type of the left parameter of the resultR
- the type of the right parameter of the resultT
- a refinement type that allows us to wrap subtypes of Rvalue
- the value to wrap