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 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 void |
handle(java.util.function.Consumer<? super T1> handler1,
java.util.function.Consumer<? super T2> handler2)
Call the appropriate handler depending on this unions' value.
|
abstract UnionBase<T1,T2> |
handle1(java.util.function.Consumer<? super T1> handler)
Call the given handler if this union contains a value of type
T1 . |
abstract UnionBase<T1,T2> |
handle2(java.util.function.Consumer<? super T2> handler)
Call the given handler if this union contains a value of type
T2 . |
abstract <E extends java.lang.Exception> |
handleFragile1(FragileProcedure1<E,? super T1> handler)
Call the given handler if this union contains a value of type
T1 . |
abstract <E extends java.lang.Exception> |
handleFragile2(FragileProcedure1<E,? super T2> handler)
Call the given handler if this union contains a value of type
T2 . |
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 T1
false
: if this union contains a value of type T2
get1()
public abstract boolean has2()
T2
?true
: if this union contains a value of type T2
false
: if this union contains a value of type T1
get2()
public abstract T1 get1() throws java.lang.IllegalStateException
T1
.
Throw an exception otherwise.T1
java.lang.IllegalStateException
- if this union does contain a value of type T2
has1()
public abstract T2 get2() throws java.lang.IllegalStateException
T2
.
Throw an exception otherwise.T2
java.lang.IllegalStateException
- if this union does contain a value of type T1
has1()
public abstract java.lang.Object getValue()
T1
or T2
public abstract void handle(@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 T1
handler2
- called if this union contains a value of type T2
@NotNull public abstract UnionBase<T1,T2> handle1(@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> handle2(@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> handleFragile1(@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> handleFragile2(@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
static boolean isEqual1(@NotNull UnionBase<?,?> definitely1, @Nullable java.lang.Object maybe1)
definitely1
- a union which definitely contains a value of type V1
maybe1
- a possible union which may contain a first value of type V1
true
: maybe1
is using its first type, and the object contained
is the same as the one from definitely1
static boolean isEqual2(@NotNull UnionBase<?,?> definitely2, @Nullable java.lang.Object maybe2)
definitely2
- a union which definitely contains a value of type V2
maybe2
- a possible union which may contain a first value of type V2
true
: maybe1
is using its second type, and the object contained
is the same as the one from definitely1