Package eu.bandm.tools.util.anon
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.
A tagged union of two to four different cases.
-
Field Summary
FieldsModifier and TypeFieldDescription(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 TypeMethodDescriptionprotected void
checkSelect
(int s) Check whether this instance is of the given variant.boolean
get1()
Get the value of variant 1.get2()
Get the value of variant 2.get3()
Get the value of variant 3.get4()
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
hashCode()
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.toString()
-
Field Details
-
select
final int selectThe index of the variant realized by this instance. -
p1
Data store for variant 1 -
p2
Data store for variant 2 -
p3
Data store for variant 3 -
p4
Data store for variant 4
-
-
Method Details
-
new1
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
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
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
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
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
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
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
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
Return the data object wrapped in this instance.- Returns:
- the value stored for the valid variant.
-
toString
-
equals
-
hashCode
public int hashCode()
-