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.SerializableA 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 booleanequals(java.lang.Object other)LgetLeft()RgetRight()inthashCode()booleanisLeft()booleanisRight()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.StringtoString()
-
-
-
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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-