Class Union2<A,​B>

java.lang.Object
co.elastic.clients.util.Union2<A,​B>
Type Parameters:
A - type of the first variant
B - 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 variant A of this union.
    B b()
    Get the variant B of this union.
    static <A,​ B> Union2<A,​B> ofA​(A value)
    Creates a variant A.
    static <A,​ B> Union2<A,​B> ofB​(B value)
    Creates a variant B.
    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

      public static <A,​ B> Union2<A,​B> ofA​(A value)
      Creates a variant A.
    • ofB

      public static <A,​ B> Union2<A,​B> ofB​(B value)
      Creates a variant B.
    • tag

      public Union2.Tag tag()
      Get the variant's tag of this union.
      Returns:
      the variant's tag
    • a

      public A a()
      Get the variant A of this union.
      Returns:
      the variant's value
      Throws:
      java.lang.IllegalStateException - if the union is not holding a variant A
    • b

      public B b()
      Get the variant B of this union.
      Returns:
      the variant's value
      Throws:
      java.lang.IllegalStateException - if the union is not holding a variant B
    • 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)