Package de.xima.fc.common.data.algebraic
Class OneOfN.OneOf4<T1,T2,T3,T4>
- java.lang.Object
 - 
- de.xima.fc.common.data.algebraic.OneOfN
 - 
- de.xima.fc.common.data.algebraic.OneOfN.OneOf4<T1,T2,T3,T4>
 
 
 
- 
- 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.
- All Implemented Interfaces:
 Serializable
- Enclosing class:
 - OneOfN
 
public static final class OneOfN.OneOf4<T1,T2,T3,T4> extends OneOfN
Emulates a sum type consisting of 4 cases.- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from class de.xima.fc.common.data.algebraic.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> 
 - 
 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T1first()static <T1,T2,T3,T4>
OneOfN.OneOf4<T1,T2,T3,T4>first(T1 first)T4fourth()static <T1,T2,T3,T4>
OneOfN.OneOf4<T1,T2,T3,T4>fourth(T4 fourth)booleanisFirst()booleanisFourth()booleanisSecond()booleanisThird()<R> Rmatch(Function<T1,R> first, Function<T2,R> second, Function<T3,R> third, Function<T4,R> fourth)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.OneOf4Matcher<R,T1,T2,T3,T4> 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.OneOfN.OneOf3<T2,T3,T4>mergeFirst(Function<T1,T2> combiner)Allows for a multi-stage reduce operation of the cases into a single value.OneOfN.OneOf3<T1,T2,T3>mergeLast(Function<T4,T3> combiner)Allows for a multi-stage reduce operation of the cases into a single value.T2second()static <T1,T2,T3,T4>
OneOfN.OneOf4<T1,T2,T3,T4>second(T2 second)Optional<T1>selectFirst()Optional<T4>selectFourth()Optional<T2>selectSecond()Optional<T3>selectThird()T3third()static <T1,T2,T3,T4>
OneOfN.OneOf4<T1,T2,T3,T4>third(T3 third)<R> RtryMatch(IThrowingFunction<T1,R> first, IThrowingFunction<T2,R> second, IThrowingFunction<T3,R> third, IThrowingFunction<T4,R> fourth)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 Detail
- 
first
public T1 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
public T4 fourth()
- Returns:
 - The value of the fourth case, if a value exists for that case.
 - Throws:
 IllegalArgumentException- If the requested case is not 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.
 
 
- 
match
public <R> R match(Function<T1,R> first, Function<T2,R> second, Function<T3,R> third, Function<T4,R> fourth)
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.- Returns:
 - The value returned by the mapping function for the matching case.
 
 
- 
match
public <R> R match(R defaultValue, OneOfN.OneOf4Matcher<R,T1,T2,T3,T4> 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
public OneOfN.OneOf3<T2,T3,T4> mergeFirst(Function<T1,T2> combiner)
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
public OneOfN.OneOf3<T1,T2,T3> mergeLast(Function<T4,T3> combiner)
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases by one by mapping the fourth to the third case via the given mapping function.- Parameters:
 combiner- Mapping function that transform the value of the fourth case into the third case.- Returns:
 - A sum type with one less case.
 
 
- 
second
public T2 second()
- Returns:
 - The value of the second case, if a value exists for that case.
 - Throws:
 IllegalArgumentException- If the requested case is not present.
 
- 
selectFirst
public Optional<T1> selectFirst()
- Returns:
 - The value of the first case, if a value exists for that case.
 
 
- 
selectFourth
public Optional<T4> selectFourth()
- Returns:
 - The value of the fourth case, if a value exists for that case.
 
 
- 
selectSecond
public Optional<T2> selectSecond()
- Returns:
 - The value of the second case, if a value exists for that case.
 
 
- 
selectThird
public Optional<T3> selectThird()
- Returns:
 - The value of the third case, if a value exists for that case.
 
 
- 
third
public T3 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<T1,R> first, IThrowingFunction<T2,R> second, IThrowingFunction<T3,R> third, IThrowingFunction<T4,R> fourth) 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.- 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.
 
- 
first
public static <T1,T2,T3,T4> OneOfN.OneOf4<T1,T2,T3,T4> first(T1 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.- Parameters:
 first- The value for the first case.- Returns:
 - A new sum type with the value for the first case.
 
 
- 
fourth
public static <T1,T2,T3,T4> OneOfN.OneOf4<T1,T2,T3,T4> fourth(T4 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.- Parameters:
 fourth- The value for the fourth case.- Returns:
 - A new sum type with the value for the fourth case.
 
 
- 
second
public static <T1,T2,T3,T4> OneOfN.OneOf4<T1,T2,T3,T4> second(T2 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.- Parameters:
 second- The value for the second case.- Returns:
 - A new sum type with the value for the second case.
 
 
- 
third
public static <T1,T2,T3,T4> OneOfN.OneOf4<T1,T2,T3,T4> third(T3 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.- Parameters:
 third- The value for the third case.- Returns:
 - A new sum type with the value for the third case.
 
 
 - 
 
 -