Package com.grammatech.gtirb.variant
Class Variant3<A,B,C>
- java.lang.Object
-
- com.grammatech.gtirb.variant.Variant3<A,B,C>
-
public abstract class Variant3<A,B,C> extends java.lang.Object
A 3-valued variant. The variant can store a single object that is of one of the generic parameter types provided. Note that this class is abstract. Intended use is to extend this class with a simple wrapper that uses named getters/setters.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Variant3(Token.T0 tok, A o)
Initialize the variant with an object of the first type.protected
Variant3(Token.T1 tok, B o)
Initialize the variant with an object of the second type.protected
Variant3(Token.T2 tok, C o)
Initialize the variant with an object of the third type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
Implementation of deep equality.java.util.Optional<A>
get0()
Get the object in the first field of the variant.java.util.Optional<B>
get1()
Get the object in the second field of the variant.java.util.Optional<C>
get2()
Get the object in the third field of the variant.int
getIndex()
Get the field index that is populated in this variant.void
set0(A o)
Set the first field of the variant.void
set1(B o)
Set the second field of the variant.void
set2(C o)
Set the third field of the variant.
-
-
-
Constructor Detail
-
Variant3
protected Variant3(Token.T0 tok, A o)
Initialize the variant with an object of the first type.- Parameters:
tok
- This is a marker parameter indicating which field of the variant is to be populated by the constructor.o
- The object to populate the variant with.
-
Variant3
protected Variant3(Token.T1 tok, B o)
Initialize the variant with an object of the second type.- Parameters:
tok
- This is a marker parameter indicating which field of the variant is to be populated by the constructor.o
- The object to populate the variant with.
-
-
Method Detail
-
getIndex
public int getIndex()
Get the field index that is populated in this variant.- Returns:
- The index (0-based) of the field of the variant.
-
get0
public java.util.Optional<A> get0()
Get the object in the first field of the variant.- Returns:
- If the field in the variant is populated, the return value is the populated object wrapped in Optional. Otherwise returns Optional.empty().
-
get1
public java.util.Optional<B> get1()
Get the object in the second field of the variant.- Returns:
- If the field in the variant is populated, the return value is the populated object wrapped in Optional. Otherwise returns Optional.empty().
-
get2
public java.util.Optional<C> get2()
Get the object in the third field of the variant.- Returns:
- If the field in the variant is populated, the return value is the populated object wrapped in Optional. Otherwise returns Optional.empty().
-
set0
public void set0(A o)
Set the first field of the variant. If any other field is populated, that field is dropped.- Parameters:
o
- The object to populate the field with.
-
set1
public void set1(B o)
Set the second field of the variant. If any other field is populated, that field is dropped.- Parameters:
o
- The object to populate the field with.
-
set2
public void set2(C o)
Set the third field of the variant. If any other field is populated, that field is dropped.- Parameters:
o
- The object to populate the field with.
-
equals
public boolean equals(java.lang.Object other)
Implementation of deep equality.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- The other object to compare equality against- Returns:
- True of other is equal to this object.
-
-