T1 - first possible typeT2 - second possible typepublic abstract class UnionBase<T1,T2>
extends java.lang.Object
This is mainly used to be able to compare both Union
and NullableUnion.
It can also be used as a type where both can appear.
To ensure the invariables of unions, objects of this class cannot be constructed outside of this package.
| Constructor and Description |
|---|
UnionBase()
Make this class unconstructable outside of this package.
|
| Modifier and Type | Method and Description |
|---|---|
abstract <V> V |
condense(java.util.function.Function<? super T1,? extends V> mapper1,
java.util.function.Function<? super T2,? extends V> mapper2)
Condense this union into a singular value.
|
abstract void |
dispose(java.util.function.Consumer<? super T1> handler1,
java.util.function.Consumer<? super T2> handler2)
Call the appropriate handler depending on this unions' value.
|
abstract <E extends java.lang.Exception> |
disposeFragile1(FragileProcedure1<E,? super T1> handler)
Call the given handler if this union contains a value of type
T1. |
abstract <E extends java.lang.Exception> |
disposeFragile2(FragileProcedure1<E,? super T2> handler)
Call the given handler if this union contains a value of type
T2. |
abstract UnionBase<T1,T2> |
disposeOnly1(java.util.function.Consumer<? super T1> handler)
Call the given handler if this union contains a value of type
T1. |
abstract UnionBase<T1,T2> |
disposeOnly2(java.util.function.Consumer<? super T2> handler)
Call the given handler if this union contains a value of type
T2. |
abstract T1 |
get1()
Get the value if it is of type
T1. |
abstract T2 |
get2()
Get the value if it is of type
T2. |
abstract java.lang.Object |
getValue()
Get the value contained in this union.
|
abstract boolean |
has1()
Does this union contain a value of type
T1? |
abstract boolean |
has2()
Does this union contain a value of type
T2? |
(package private) static boolean |
isEqual1(UnionBase<?,?> definitely1,
java.lang.Object maybe1)
Check whether two unions using their first type define the same value.
|
(package private) static boolean |
isEqual2(UnionBase<?,?> definitely2,
java.lang.Object maybe2)
Check whether two unions using their second type define the same value.
|
abstract <V1,V2> UnionBase<V1,V2> |
map(java.util.function.Function<? super T1,? extends V1> mapper1,
java.util.function.Function<? super T2,? extends V2> mapper2)
Convert this union into another union.
|
abstract UnionBase<T2,T1> |
swap()
Convert this union into one where both values (and types) are exchanged.
|
abstract boolean |
test(java.util.function.Predicate<? super T1> test1,
java.util.function.Predicate<? super T2> test2)
Perform a test on this union.
|
UnionBase()
public abstract boolean has1()
T1?true: if this union contains a value of type T1false: if this union contains a value of type T2get1()public abstract boolean has2()
T2?true: if this union contains a value of type T2false: if this union contains a value of type T1get2()public abstract T1 get1() throws java.lang.IllegalStateException
T1.
Throw an exception otherwise.T1java.lang.IllegalStateException - if this union does contain a value of type T2has1()public abstract T2 get2() throws java.lang.IllegalStateException
T2.
Throw an exception otherwise.T2java.lang.IllegalStateException - if this union does contain a value of type T1has1()public abstract java.lang.Object getValue()
T1 or T2public abstract void dispose(@NotNull java.util.function.Consumer<? super T1> handler1, @NotNull java.util.function.Consumer<? super T2> handler2)
handler1 - called if this union contains a value of type T1handler2 - called if this union contains a value of type T2@NotNull public abstract UnionBase<T1,T2> disposeOnly1(@NotNull java.util.function.Consumer<? super T1> handler)
T1.handler - called with the value of this union if the contained type is T1, not called otherwise@NotNull public abstract UnionBase<T1,T2> disposeOnly2(@NotNull java.util.function.Consumer<? super T2> handler)
T2.handler - called with the value of this union if the contained type is T2, not called otherwise@NotNull public abstract <E extends java.lang.Exception> UnionBase<T1,T2> disposeFragile1(@NotNull FragileProcedure1<E,? super T1> handler) throws E extends java.lang.Exception
T1.
Allows for a handler which might throw a checked exception.E - exception the handler might throwhandler - called with the value of this union if the contained type is T1, not called otherwiseE - if handler throws itE extends java.lang.Exception@NotNull public abstract <E extends java.lang.Exception> UnionBase<T1,T2> disposeFragile2(@NotNull FragileProcedure1<E,? super T2> handler) throws E extends java.lang.Exception
T2.
Allows for a handler which might throw a checked exception.E - exception the handler might throwhandler - called with the value of this union if the contained type is T2, not called otherwiseE - if handler throws itE extends java.lang.Exception@NotNull public abstract <V1,V2> UnionBase<V1,V2> map(@NotNull java.util.function.Function<? super T1,? extends V1> mapper1, @NotNull java.util.function.Function<? super T2,? extends V2> mapper2)
V1 - mapped first value typeV2 - mapped second value typemapper1 - mapper applied if this union carries a value of the first typemapper2 - mapper applied if this union carries a value of the second typeswap()@NotNull public abstract UnionBase<T2,T1> swap()
map(Function, Function)public abstract <V> V condense(@NotNull java.util.function.Function<? super T1,? extends V> mapper1, @NotNull java.util.function.Function<? super T2,? extends V> mapper2)
V - mapped value typemapper1 - mapper applied if this union carries a value of the first typemapper2 - mapper applied if this union carries a value of the second typepublic abstract boolean test(@NotNull java.util.function.Predicate<? super T1> test1, @NotNull java.util.function.Predicate<? super T2> test2)
test1 - test applied if this union carries a value of the first typetest2 - test applied if this union carries a value of the second typestatic boolean isEqual1(@NotNull UnionBase<?,?> definitely1, @Nullable java.lang.Object maybe1)
definitely1 - a union which definitely contains a value of type V1maybe1 - a possible union which may contain a first value of type V1true: maybe1 is using its first type, and the object contained
is the same as the one from definitely1static boolean isEqual2(@NotNull UnionBase<?,?> definitely2, @Nullable java.lang.Object maybe2)
definitely2 - a union which definitely contains a value of type V2maybe2 - a possible union which may contain a second value of type V2true: maybe2 is using its second type, and the object contained
is the same as the one from definitely2