public class Variant extends Object implements UaNamespaceTranslateable<Variant>, Cloneable
Structure. e.g. new Variant( new
NotificationData() );
Encoders write a structure as an ExtensionObject.UaNamespaceTranslateable.Context| Modifier and Type | Field and Description |
|---|---|
static Variant[] |
EMPTY_ARRAY |
static Variant |
NULL |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
asClass(Class<T> clazz,
T defaultValue)
Convert the variant value to any class.
|
<T extends Enum<T> & Enumeration> |
asEnum(Class<T> clazz)
Converts the value to the given Enumeration objects.
|
Object |
asEnum(EnumerationSpecification enumerationSpecification)
For a Variant that contains anydimensional data of OPC UA Int32 i.e.
|
static Object[] |
asObjectArray(Variant... variants)
Transforms the given Variant array to an Object array having the variants values as elements.
|
Object |
asOptionSet(OptionSetSpecification optionSetSpecification)
For a Variant that contains anydimensional data of OPC UA Numeric "OptionSet" types, transform
the data to the
OptionSetSpecification.getJavaClass(). |
static Variant[] |
asVariantArray(Object... objects)
Transforms given objects to a Variant array.
|
boolean |
booleanValue()
Returns the value of the specified Variant as a
boolean. |
byte |
byteValue()
Returns the value of the specified Variant as a
byte. |
Variant |
clone() |
protected String |
compositeClassToString()
compositeClassToString.
|
static Variant |
defaultValue(Class<?> compositeClass)
Get a new Variant instance initialized to a default value of javaClass.
|
static Variant |
defaultValue(Class<?> compositeClass,
int valueRank)
Get a new Variant instance initialized to a default value of javaClass.
|
static Variant |
defaultValue(Class<?> compositeClass,
UaArrayDimensions arrayDimensions)
Get a new Variant instance initialized to a default value of javaClass.
|
static Variant |
defaultValue(Class<?> compositeClass,
UnsignedInteger[] arrayDimensions)
Get a new Variant instance initialized to a default value of javaClass.
|
static Variant |
defaultValue(EncoderContext encoderContext,
UaNodeId dataTypeId)
Get a new Variant instance initialized to a default value of a DataType.
|
static Variant |
defaultValue(EncoderContext encoderContext,
UaNodeId dataTypeId,
int valueRank) |
static Variant |
defaultValue(EncoderContext encoderContext,
UaNodeId dataTypeId,
UaArrayDimensions arrayDimensions)
Get a new Variant instance initialized to a default value of a DataType.
|
static Variant |
defaultValue(EncoderContext encoderContext,
UaNodeId dataTypeId,
UnsignedInteger[] arrayDimensions)
Get a new Variant instance initialized to a default value of a DataType.
|
double |
doubleValue()
Returns the value of the specified Variant as a
double. |
boolean |
equals(Object obj) |
float |
floatValue()
Returns the value of the specified Variant as a
float. |
int[] |
getArrayDimensions()
Returns the current dimensions of
getValue() or an empty array, if it is not an array. |
Object |
getArrayElement(int... indices)
Get the array element corresponding to the indices.
|
Class<?> |
getCompositeClass()
Returns the class type of the variant value.
|
int |
getDimension()
Returns the number of array dimensions of
getValue() as defined by
MultiDimensionArrayUtils.getDimension(Object). |
Object |
getValue()
Returns the value the
Variant was constructed with. |
int |
hashCode() |
int |
intValue()
Returns the value of the specified Variant as an
int. |
boolean |
isArray()
Returns true, if
getValue() is not null and it's getClass().isArray() is true. |
boolean |
isComparable()
Returns true, if
getValue() is an instance of Comparable. |
boolean |
isEmpty()
Returns true, if
getValue() is null. |
boolean |
isNumber()
Returns true, if
getValue() is an instance of Number of Boolean (which
can be used as Integer) and can therefore be converted toNumber(). |
long |
longValue()
Returns the value of the specified Variant as a
long. |
short |
shortValue()
Returns the value of the specified Variant as a
short. |
Number |
toNumber()
Returns the value of the specified Variant as a
Number. |
String |
toString() |
String |
toString(boolean includeCompositeClass)
Convert the value to string, optionally including the compositeClass.
|
String |
toStringWithType()
Convert the value to string, including the compositeClass.
|
boolean |
valueEquals(Variant value2)
Compares the value of a variant with another variant.
|
Variant |
withTranslatedNamespaces(UaNamespaceTranslateable.Context context)
Returns a deep copy of itself where all where every namespace index and uri plus server index
and uri (see
ExpandedNodeId, UaExpandedNodeId) has been swapped based on the
given UaNamespaceTranslateable.Context. |
public static final Variant NULL
public static final Variant[] EMPTY_ARRAY
public Variant(Object value)
value - scalar, array or multi-dimension arraypublic static Object[] asObjectArray(Variant... variants)
public static Variant[] asVariantArray(Object... objects)
IllegalArgumentException if any of the given types cannot be put to Variant.public static Variant defaultValue(Class<?> compositeClass)
compositeClass - the class to use to initialize the Variant. Expects that the class is a
native JavaClass corresponding to the OPC UA built-in types.public static Variant defaultValue(Class<?> compositeClass, int valueRank)
compositeClass - the class to use to initialize the Variant. Expects that the class is a
native JavaClass corresponding to the OPC UA built-in types.valueRank - the dimension required for the array. If
ValueRanks#acceptsScalar(valueRank) a scalar value is always returned.public static Variant defaultValue(Class<?> compositeClass, UaArrayDimensions arrayDimensions)
compositeClass - the class to use to initialize the Variant. Expects that the class is a
native JavaClass corresponding to the OPC UA built-in types.arrayDimensions - the size of the array in each dimension.public static Variant defaultValue(Class<?> compositeClass, UnsignedInteger[] arrayDimensions)
compositeClass - the class to use to initialize the Variant. Expects that the class is a
native JavaClass corresponding to the OPC UA built-in types.arrayDimensions - the size of the array in each dimension.public static Variant defaultValue(EncoderContext encoderContext, UaNodeId dataTypeId)
encoderContext - the encoder context that can provide the correct DataTypeSpecification
for the DataType. Typically, you can get this from the UaApplication instance.dataTypeId - the NodeId of the OPC UA DataType that you wish to use for (each element of)
the default value.public static Variant defaultValue(EncoderContext encoderContext, UaNodeId dataTypeId, int valueRank)
public static Variant defaultValue(EncoderContext encoderContext, UaNodeId dataTypeId, UaArrayDimensions arrayDimensions)
encoderContext - the encoder context that can provide the correct DataTypeSpecification
for the DataType. Typically, you can get this from the UaApplication instance.dataTypeId - the NodeId of the OPC UA DataType that you wish to use for (each element of)
the default value.arrayDimensions - the size of the array in each dimension.public static Variant defaultValue(EncoderContext encoderContext, UaNodeId dataTypeId, UnsignedInteger[] arrayDimensions)
encoderContext - the encoder context that can provide the correct DataTypeSpecification
for the DataType. Typically, you can get this from the UaApplication instance.dataTypeId - the NodeId of the OPC UA DataType that you wish to use for (each element of)
the default value.arrayDimensions - the size of the array in each dimension.public <T> T asClass(Class<T> clazz, T defaultValue)
public <T extends Enum<T> & Enumeration> Object asEnum(Class<T> clazz)
clazz - enumeration classClassCastException - if internal value is not Integer (or somedimensional array of them)public Object asEnum(EnumerationSpecification enumerationSpecification)
EnumerationSpecification. Integer values that do not map to the given
EnumerationSpecification's range are set to null. Returns null, if contained null
value. Return value has same dimensions as getValue() has. For array data for
EnumerationSpecifications without any constants returns raw Enumeration-typed arrays
(of proper dimensions).ClassCastException - if this variant doesn't contain java.lang.Integer values (scalar or
of any dimension).public Object asOptionSet(OptionSetSpecification optionSetSpecification)
OptionSetSpecification.getJavaClass(). Returns null if given null. If
given OptionSetStructureSpecification, doesn't do any conversion (as this only makes
sense for UInteger-based OptionSets).ClassCastException - if this variant doesn't contain correct UInteger-based value for the
given OptionSetSpecification.getBaseTypeId().public boolean booleanValue()
boolean.ClassCastException - if the value cannot be cast to booleanpublic byte byteValue()
byte. This may involve rounding or
truncation.byte.ClassCastException - if the value cannot be cast to Numberpublic double doubleValue()
double. This may involve rounding.double.ClassCastException - if the value cannot be cast to Numberpublic float floatValue()
float. This may involve rounding.float.ClassCastException - if the value cannot be cast to Numberpublic int[] getArrayDimensions()
getValue() or an empty array, if it is not an array.public Object getArrayElement(int... indices)
public Class<?> getCompositeClass()
public int getDimension()
getValue() as defined by
MultiDimensionArrayUtils.getDimension(Object).public int intValue()
int. This may involve rounding or
truncation.int.ClassCastException - if the value cannot be cast to Numberpublic boolean isArray()
getValue() is not null and it's getClass().isArray() is true.public boolean isComparable()
getValue() is an instance of Comparable.public boolean isEmpty()
getValue() is null.public boolean isNumber()
getValue() is an instance of Number of Boolean (which
can be used as Integer) and can therefore be converted toNumber().public long longValue()
long. This may involve rounding or
truncation.long.ClassCastException - if the value cannot be cast to Numberpublic short shortValue()
short. This may involve rounding
or truncation.short.ClassCastException - if the value cannot be cast to Numberpublic Number toNumber()
Number.ClassCastException - if the value cannot be cast to Numberpublic String toString(boolean includeCompositeClass)
includeCompositeClass - whether to also add the name of the compositeClasspublic String toStringWithType()
String object.public boolean valueEquals(Variant value2)
equals(Object) is called. If both variants isNumber(), compares the
floatValue() of each.value2 - the value to compare topublic Variant withTranslatedNamespaces(UaNamespaceTranslateable.Context context)
UaNamespaceTranslateableExpandedNodeId, UaExpandedNodeId) has been swapped based on the
given UaNamespaceTranslateable.Context. Returning the same object is allowed if the type is immutable and the
result is equal to this. Note that for Structure types if the
UaDataTypeSpecification translation is active the returned type can be of different
java class.withTranslatedNamespaces in interface UaNamespaceTranslateable<Variant>Copyright © 2026. All rights reserved.