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 invariances 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 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 first type define the same value.
|
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.Exceptionstatic 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 first value of type V2true: maybe1 is using its second type, and the object contained
is the same as the one from definitely1