Package com.fa993.types.supertype
Class Either.OfTwo<A,B>
- java.lang.Object
-
- com.fa993.types.supertype.Either.OfTwo<A,B>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OfTwo(A first, B second, Either.Selector selector)
Constructs anOfTwo
object with the specified values and selector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A,B>
Either.OfTwo<A,B>first(A first)
Creates anOfTwo
instance with the first value selected.A
getFirst()
Gets the first value if selected.B
getSecond()
Gets the second value if selected.Either.Selector
getSelector()
Gets the current selector.static <A,B>
Either.OfTwo<A,B>second(B second)
Creates anOfTwo
instance with the second value selected.
-
-
-
Constructor Detail
-
OfTwo
protected OfTwo(A first, B second, Either.Selector selector)
Constructs anOfTwo
object with the specified values and selector.- Parameters:
first
- the value of the first optionsecond
- the value of the second optionselector
- the selector indicating the current choice
-
-
Method Detail
-
first
public static <A,B> Either.OfTwo<A,B> first(A first)
Creates anOfTwo
instance with the first value selected.- Type Parameters:
A
- the type of the first valueB
- the type of the second value- Parameters:
first
- the value of the first option- Returns:
- an
OfTwo
instance with the first value selected
-
second
public static <A,B> Either.OfTwo<A,B> second(B second)
Creates anOfTwo
instance with the second value selected.- Type Parameters:
A
- the type of the first valueB
- the type of the second value- Parameters:
second
- the value of the second option- Returns:
- an
OfTwo
instance with the second value selected
-
getFirst
public A getFirst()
Gets the first value if selected.- Returns:
- the first value
- Throws:
IllegalStateException
- if the current selection is notFirst
-
getSecond
public B getSecond()
Gets the second value if selected.- Returns:
- the second value
- Throws:
IllegalStateException
- if the current selection is notSecond
-
getSelector
public Either.Selector getSelector()
Gets the current selector.- Returns:
- the
Selector
indicating the current selection
-
-