Class CoTuple<A,B,C,D>

java.lang.Object
eu.bandm.tools.util.anon.CoTuple<A,B,C,D>
Type Parameters:
A - the type of the first variant.
B - the type of the second variant.
C - the type of the third variant.
D - the type of the fourth variant.

public class CoTuple<A,B,C,D> extends Object
A tagged union of two to four different cases.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final A
    Data store for variant 1
    (package private) final B
    Data store for variant 2
    (package private) final C
    Data store for variant 3
    (package private) final D
    Data store for variant 4
    (package private) final int
    The index of the variant realized by this instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkSelect(int s)
    Check whether this instance is of the given variant.
    boolean
    Get the value of variant 1.
    Get the value of variant 2.
    Get the value of variant 3.
    Get the value of variant 4.
    Return the data object wrapped in this instance.
    int
    Return the index of the variant realized by this instance.
    int
    static <A0, B0, C0, D0>
    CoTuple<A0,B0,C0,D0>
    new1(A0 p1)
    Create an instance of variant one.
    static <A0, B0, C0, D0>
    CoTuple<A0,B0,C0,D0>
    new2(B0 p2)
    Create an instance of variant two.
    static <A0, B0, C0, D0>
    CoTuple<A0,B0,C0,D0>
    new3(C0 p3)
    Create an instance of variant three.
    static <A0, B0, C0, D0>
    CoTuple<A0,B0,C0,D0>
    new4(D0 p4)
    Create an instance of variant four.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • select

      final int select
      The index of the variant realized by this instance.
    • p1

      @Opt final A p1
      Data store for variant 1
    • p2

      @Opt final B p2
      Data store for variant 2
    • p3

      @Opt final C p3
      Data store for variant 3
    • p4

      @Opt final D p4
      Data store for variant 4
  • Method Details

    • new1

      public static <A0, B0, C0, D0> CoTuple<A0,B0,C0,D0> new1(@Opt A0 p1)
      Create an instance of variant one.
      Type Parameters:
      A0 - the type of the first variant.
      B0 - the type of the second variant.
      C0 - the type of the third variant.
      D0 - the type of the fourth variant.
      Parameters:
      p1 - the value for this variant
      Returns:
      a CoTuple with selection and value set.
    • new2

      public static <A0, B0, C0, D0> CoTuple<A0,B0,C0,D0> new2(@Opt B0 p2)
      Create an instance of variant two.
      Type Parameters:
      A0 - the type of the first variant.
      B0 - the type of the second variant.
      C0 - the type of the third variant.
      D0 - the type of the fourth variant.
      Parameters:
      p2 - the value for this variant
      Returns:
      a CoTuple with selection and value set.
    • new3

      public static <A0, B0, C0, D0> CoTuple<A0,B0,C0,D0> new3(@Opt C0 p3)
      Create an instance of variant three.
      Type Parameters:
      A0 - the type of the first variant.
      B0 - the type of the second variant.
      C0 - the type of the third variant.
      D0 - the type of the fourth variant.
      Parameters:
      p3 - the value for this variant
      Returns:
      a CoTuple with selection and value set.
    • new4

      public static <A0, B0, C0, D0> CoTuple<A0,B0,C0,D0> new4(@Opt D0 p4)
      Create an instance of variant four.
      Type Parameters:
      A0 - the type of the first variant.
      B0 - the type of the second variant.
      C0 - the type of the third variant.
      D0 - the type of the fourth variant.
      Parameters:
      p4 - the value for this variant
      Returns:
      a CoTuple with selection and value set.
    • getSelect

      public int getSelect()
      Return the index of the variant realized by this instance.
      Returns:
      the index number of the contained variant. Is 1-based.
    • get1

      public A get1()
      Get the value of variant 1.
      Returns:
      get the value stored for the first variant.
      Throws:
      IllegalStateException - if this instance is not of that variant.
    • get2

      public B get2()
      Get the value of variant 2.
      Returns:
      get the value stored for the second variant.
      Throws:
      IllegalStateException - if this instance is not of that variant.
    • get3

      public C get3()
      Get the value of variant 3.
      Returns:
      get the value stored for the third variant.
      Throws:
      IllegalStateException - if this instance is not of that variant.
    • get4

      public D get4()
      Get the value of variant 4.
      Returns:
      get the value stored for the fourth variant.
      Throws:
      IllegalStateException - if this instance is not of that variant.
    • checkSelect

      protected void checkSelect(int s)
      Check whether this instance is of the given variant.
      Parameters:
      s - the variant number which is tested, 1 to 4.
      Throws:
      IllegalStateException - if this instance is not of that variant.
    • getObject

      public Object getObject()
      Return the data object wrapped in this instance.
      Returns:
      the value stored for the valid variant.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Opt @Opt Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object