Class OneOfN
java.lang.Object
de.xima.fc.common.data.algebraic.OneOfN
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
OneOfN.Either, OneOfN.Just, OneOfN.None, OneOfN.OneOf3, OneOfN.OneOf4, OneOfN.OneOf5
Base class for emulating algebraic sum types (also known as a discriminated union) of N elements.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classEmulates a sum type consisting of 2 cases.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value.static final classEmulates a sum type consisting of 1 case.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value.static final classEmulates a sum type consisting of 0 cases.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value.static final classEmulates a sum type consisting of 3 cases.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value.static final classEmulates a sum type consisting of 4 cases.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value.static final classEmulates a sum type consisting of 5 cases.static interfaceA matcher object that contains a handler for each case and can be used to reduce a sum type to a single value. -
Field Summary
Fields -
Method Summary
-
Field Details
-
choice
protected final int choice -
value
-
-
Method Details
-
equals
-
getChoice
public int getChoice()- Returns:
- The 0-based index representing the case for which a value is present.
-
getValue
Checks which case applies and returns the value for that case. You need to cast it yourself to the required type.- Returns:
- The value of this sum type.
-
hashCode
-
toString
-
getOrThrow
- Parameters:
choice- Index of the case to get.- Returns:
- The value of the given case, if present.
- Throws:
IllegalArgumentException- If the given case is not present.
-
is
protected final boolean is(int choice) - Parameters:
choice- Index of the case to check.- Returns:
- Whether a value is present for the given case.
-
select
-