Package co.elastic.clients.util
Class Union2<A,B>
java.lang.Object
co.elastic.clients.util.Union2<A,B>
- Type Parameters:
A
- type of the first variantB
- type of the second variant
public class Union2<A,B>
extends java.lang.Object
A tagged union (also known as variant, sum type or coproduct) with two members.
The union's value is one (and only one) of the possible variants. The variant in use is defined by the
tag()
's value.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Union2.JsonpParser<A,B>
static class
Union2.Tag
The variant tag. -
Method Summary
Modifier and Type Method Description A
a()
Get the variantA
of this union.B
b()
Get the variantB
of this union.static <A, B> Union2<A,B>
ofA(A value)
Creates a variantA
.static <A, B> Union2<A,B>
ofB(B value)
Creates a variantB
.void
serialize(jakarta.json.stream.JsonGenerator builder, JsonpMapper params, TriConsumer<A,jakarta.json.stream.JsonGenerator,JsonpMapper> a, TriConsumer<B,jakarta.json.stream.JsonGenerator,JsonpMapper> b)
Union2.Tag
tag()
Get the variant's tag of this union.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
ofA
Creates a variantA
. -
ofB
Creates a variantB
. -
tag
Get the variant's tag of this union.- Returns:
- the variant's tag
-
a
Get the variantA
of this union.- Returns:
- the variant's value
- Throws:
java.lang.IllegalStateException
- if the union is not holding a variantA
-
b
Get the variantB
of this union.- Returns:
- the variant's value
- Throws:
java.lang.IllegalStateException
- if the union is not holding a variantB
-
serialize
public void serialize(jakarta.json.stream.JsonGenerator builder, JsonpMapper params, TriConsumer<A,jakarta.json.stream.JsonGenerator,JsonpMapper> a, TriConsumer<B,jakarta.json.stream.JsonGenerator,JsonpMapper> b)
-