Package org.protelis.lang.datatype
Class Either<L,R>
- java.lang.Object
-
- org.protelis.lang.datatype.Either<L,R>
-
- Type Parameters:
L
- left typeR
- right type
- All Implemented Interfaces:
java.io.Serializable
public final class Either<L,R> extends java.lang.Object implements java.io.Serializable
A data structure that can yield either a value of type L or a value of type R.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
L
getLeft()
R
getRight()
int
hashCode()
boolean
isLeft()
boolean
isRight()
static <L,R>
Either<L,R>left(L value)
Factory method for a leftEither
.static <L,R>
Either<L,R>right(R value)
Factory method for a rightEither
.java.lang.String
toString()
-
-
-
Method Detail
-
isLeft
public boolean isLeft()
- Returns:
- true if it is a left
Either
-
isRight
public boolean isRight()
- Returns:
- true if it is a right
Either
-
getLeft
public L getLeft()
- Returns:
- the left value, or an
IllegalStateException
- Throws:
java.lang.IllegalStateException
- if this is a right either
-
getRight
public R getRight()
- Returns:
- the right value, or an
IllegalStateException
- Throws:
java.lang.IllegalStateException
- if this is a left either
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-