Class OneOfN.OneOf5<T1,T2,T3,T4,T5>
java.lang.Object
de.xima.fc.common.data.algebraic.OneOfN
de.xima.fc.common.data.algebraic.OneOfN.OneOf5<T1,T2,T3,T4,T5>
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.
- All Implemented Interfaces:
Serializable
- Enclosing class:
OneOfN
Emulates a sum type consisting of 5 cases.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class OneOfN
OneOfN.Either<T1,T2>, OneOfN.EitherMatcher<R, T1, T2>, OneOfN.Just<T1>, OneOfN.JustMatcher<R, T1>, OneOfN.None, OneOfN.NoneMatcher<R>, OneOfN.OneOf3<T1, T2, T3>, OneOfN.OneOf3Matcher<R, T1, T2, T3>, OneOfN.OneOf4<T1, T2, T3, T4>, OneOfN.OneOf4Matcher<R, T1, T2, T3, T4>, OneOfN.OneOf5<T1, T2, T3, T4, T5>, OneOfN.OneOf5Matcher<R, T1, T2, T3, T4, T5> -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionfifth()static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> fifth(T5 fifth) first()static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> first(T1 first) static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> firstNonNull(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) Returns the first non-null value of the five given values as a OneOf5 type.fourth()static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> fourth(T4 fourth) booleanisFifth()booleanisFirst()booleanisFourth()booleanisSecond()booleanisThird()<R1,R2, R3, R4, R5>
OneOfN.OneOf5<R1, R2, R3, R4, R5> map(Function<? super T1, ? extends R1> first, Function<? super T2, ? extends R2> second, Function<? super T3, ? extends R3> third, Function<? super T4, ? extends R4> fourth, Function<? super T5, ? extends R5> fifth) Maps this sum type to another sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(OneOfN.OneOf5Matcher<? extends R, ? super T1, ? super T2, ? super T3, ? super T4, ? super T5> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(Function<? super T1, ? extends R> first, Function<? super T2, ? extends R> second, Function<? super T3, ? extends R> third, Function<? super T4, ? extends R> fourth, Function<? super T5, ? extends R> fifth) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(R defaultValue, OneOfN.OneOf5Matcher<? extends R, ? super T1, ? super T2, ? super T3, ? super T4, ? super T5> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.mergeFirst(Function<? super T1, ? extends T2> combiner) Allows for a multi-stage reduce operation of the cases into a single value.Allows for a multi-stage reduce operation of the cases into a single value.second()static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> second(T2 second) third()static <T1,T2, T3, T4, T5>
OneOfN.OneOf5<T1, T2, T3, T4, T5> third(T3 third) <R> RtryMatch(IThrowingFunction<? super T1, ? extends R> first, IThrowingFunction<? super T2, ? extends R> second, IThrowingFunction<? super T3, ? extends R> third, IThrowingFunction<? super T4, ? extends R> fourth, IThrowingFunction<? super T5, ? extends R> fifth) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.
-
Method Details
-
fifth
- Returns:
- The value of the fifth case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
first
- Returns:
- The value of the first case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
fourth
- Returns:
- The value of the fourth case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
isFifth
public boolean isFifth()- Returns:
- Whether a value for the fifth case is present.
-
isFirst
public boolean isFirst()- Returns:
- Whether a value for the first case is present.
-
isFourth
public boolean isFourth()- Returns:
- Whether a value for the fourth case is present.
-
isSecond
public boolean isSecond()- Returns:
- Whether a value for the second case is present.
-
isThird
public boolean isThird()- Returns:
- Whether a value for the third case is present.
-
map
public <R1,R2, OneOfN.OneOf5<R1,R3, R4, R5> R2, mapR3, R4, R5> (Function<? super T1, ? extends R1> first, Function<? super T2, ? extends R2> second, Function<? super T3, ? extends R3> third, Function<? super T4, ? extends R4> fourth, Function<? super T5, ? extends R5> fifth) Maps this sum type to another sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R1- Type of the result returned by the mapping function for the left case.R2- Type of the result returned by the mapping function for the middle case.R3- Type of the result returned by the mapping function for theR4- Type of the result returned by the mapping function for the fourth case.R5- Type of the result returned by the mapping function for the fifth case.- Parameters:
first- Mapping function for the first case.second- Mapping function for the second case.third- Mapping function for the third case.fourth- Mapping function for the fourth case.fifth- Mapping function for the fifth case.- Returns:
- The sum type with the value returned by the mapping function for the matching case.
-
match
public <R> R match(Function<? super T1, ? extends R> first, Function<? super T2, ? extends R> second, Function<? super T3, ? extends R> third, Function<? super T4, ? extends R> fourth, Function<? super T5, ? extends R> fifth) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
first- Mapping function for the first case.second- Mapping function for the second case.third- Mapping function for the third case.fourth- Mapping function for the fourth case.fifth- Mapping function for the fifth case.- Returns:
- The value returned by the mapping function for the matching case.
-
match
public <R> R match(OneOfN.OneOf5Matcher<? extends R, ? super T1, ? super T2, ? super T3, ? super T4, ? super T5> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
matcher- Matcher object for each case.- Returns:
- The value returned by the mapping function for the matching case.
-
match
public <R> R match(R defaultValue, OneOfN.OneOf5Matcher<? extends R, ? super T1, ? super T2, ? super T3, ? super T4, ? super T5> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
defaultValue- Value returned when the given matcher has no matching case.matcher- Matcher object for each case.- Returns:
- The value returned by the mapping function for the matching case.
-
mergeFirst
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases by one by mapping the first to the second case via the given mapping function.- Parameters:
combiner- Mapping function that transform the value of the first case into the second case.- Returns:
- A sum type with one less case.
-
mergeLast
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases by one by mapping the fifth to the fourth case via the given mapping function.- Parameters:
combiner- Mapping function that transform the value of the fifth case into the fourth case.- Returns:
- A sum type with one less case.
-
second
- Returns:
- The value of the second case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
selectFifth
-
selectFirst
-
selectFourth
-
selectSecond
-
selectThird
-
third
- Returns:
- The value of the third case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
tryMatch
public <R> R tryMatch(IThrowingFunction<? super T1, ? extends R> first, IThrowingFunction<? super T2, ? extends R> second, IThrowingFunction<? super T3, ? extends R> third, IThrowingFunction<? super T4, ? extends R> fourth, IThrowingFunction<? super T5, ? extends R> fifth) throws Exception Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
first- Mapping function for the first case.second- Mapping function for the second case.third- Mapping function for the third case.fourth- Mapping function for the fourth case.fifth- Mapping function for the fifth case.- Returns:
- The value returned by the mapping function for the matching case.
- Throws:
Exception- If the mapping function for the matching case throws an exception.
-
fifth
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
fifth- The value for the fifth case.- Returns:
- A new sum type with the value for the fifth case.
-
first
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
first- The value for the first case.- Returns:
- A new sum type with the value for the first case.
-
firstNonNull
public static <T1,T2, OneOfN.OneOf5<T1,T3, T4, T5> T2, firstNonNullT3, T4, T5> (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) Returns the first non-null value of the five given values as a OneOf5 type.- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
t1- The first valuet2- The second valuet3- The third valuet4- The fourth valuet5- The fifth value- Returns:
- The first non-null value, or null if all are null.
-
fourth
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
fourth- The value for the fourth case.- Returns:
- A new sum type with the value for the fourth case.
-
second
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
second- The value for the second case.- Returns:
- A new sum type with the value for the second case.
-
third
- Type Parameters:
T1- Type of the value for the first case.T2- Type of the value for the second case.T3- Type of the value for the third case.T4- Type of the value for the fourth case.T5- Type of the value for the fifth case.- Parameters:
third- The value for the third case.- Returns:
- A new sum type with the value for the third case.
-