Class CoTuple<A,B,C,D>

java.lang.Object
eu.bandm.tools.ops.CoTuple<A,B,C,D>

public class CoTuple<A,B,C,D> extends Object
Class realizing a "tagged union" of two(2) to four(4) 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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CoTuple(int select, A p1, B p2, C p3, D p4)
    Only constructor, called by factory methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkSelect(int s)
    Check whether this instance is of the given variant.
    protected boolean
    Aux function to compare to objects of unknown class.
    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 <A, B, C, D> CoTuple<A,B,C,D>
    new1(A p1)
    Create an instance of variant 1
    static <A, B, C, D> CoTuple<A,B,C,D>
    new2(B p2)
    Create an instance of variant 2
    static <A, B, C, D> CoTuple<A,B,C,D>
    new3(C p3)
    Create an instance of variant 3
    static <A, B, C, D> CoTuple<A,B,C,D>
    new4(D p4)
    Create an instance of variant 4
     

    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

      final A p1
      Data store for variant 1
    • p2

      final B p2
      Data store for variant 2
    • p3

      final C p3
      Data store for variant 3
    • p4

      final D p4
      Data store for variant 4
  • Constructor Details

    • CoTuple

      public CoTuple(int select, A p1, B p2, C p3, D p4)
      Only constructor, called by factory methods.
  • Method Details

    • new1

      public static <A, B, C, D> CoTuple<A,B,C,D> new1(A p1)
      Create an instance of variant 1
    • new2

      public static <A, B, C, D> CoTuple<A,B,C,D> new2(B p2)
      Create an instance of variant 2
    • new3

      public static <A, B, C, D> CoTuple<A,B,C,D> new3(C p3)
      Create an instance of variant 3
    • new4

      public static <A, B, C, D> CoTuple<A,B,C,D> new4(D p4)
      Create an instance of variant 4
    • getSelect

      public int getSelect()
      Return the index of the variant realized by this instance.
    • get1

      public A get1()
      Get the value of variant 1.
    • get2

      public B get2()
      Get the value of variant 2.
    • get3

      public C get3()
      Get the value of variant 3.
    • get4

      public D get4()
      Get the value of variant 4.
    • checkSelect

      protected void checkSelect(int s)
      Check whether this instance is of the given variant.
    • getObject

      public Object getObject()
      Return the data object wrapped in this instance.
    • toString

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

      protected boolean compEqual(Object o1, Object o2)
      Aux function to compare to objects of unknown class.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object