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 classUnion2.JsonpParser<A,B>static classUnion2.TagThe variant tag. -
Method Summary
Modifier and Type Method Description Aa()Get the variantAof this union.Bb()Get the variantBof 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.voidserialize(jakarta.json.stream.JsonGenerator builder, JsonpMapper params, TriConsumer<A,jakarta.json.stream.JsonGenerator,JsonpMapper> a, TriConsumer<B,jakarta.json.stream.JsonGenerator,JsonpMapper> b)Union2.Tagtag()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 variantAof this union.- Returns:
- the variant's value
- Throws:
java.lang.IllegalStateException- if the union is not holding a variantA
-
b
Get the variantBof 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)
-