public class Variant extends Object implements Serializable, Comparable<Variant>
Modifier and Type | Field and Description |
---|---|
static Variant |
FALSE
A default BOOL#false instance
|
static Variant |
NULL
A default NULL instance
|
static Variant |
TRUE
A default BOOL#true instance
|
Modifier | Constructor and Description |
---|---|
protected |
Variant() |
protected |
Variant(boolean value) |
protected |
Variant(double value) |
protected |
Variant(int value) |
protected |
Variant(long value) |
protected |
Variant(Object object) |
protected |
Variant(String value) |
protected |
Variant(Variant other) |
Modifier and Type | Method and Description |
---|---|
Serializable |
as(VariantType variantType)
Convert the variant to a java object of the type specified by the
variantType parameter
|
Serializable |
as(VariantType variantType,
Serializable defaultValue)
Convert the variant to a java object of the type specified by the
variantType parameter
|
boolean |
asBoolean()
Get the value as boolean value If the value is
null then
false is returned. |
Boolean |
asBoolean(Boolean defaultValue)
Return the value as boolean
|
double |
asDouble() |
Double |
asDouble(Double defaultValue) |
int |
asInteger() |
Integer |
asInteger(Integer defaultValue) |
long |
asLong() |
Long |
asLong(Long defaultValue) |
String |
asString()
Get the string representation of the variant value.
|
String |
asString(String defaultValue)
Get the string representation of the variant value or a default value if
the variant is of type
VariantType.NULL . |
int |
compareTo(Variant o) |
boolean |
equals(Object obj) |
VariantType |
getType() |
Serializable |
getValue()
Get the internal variant value
|
int |
hashCode() |
boolean |
isBoolean() |
boolean |
isDouble() |
boolean |
isInteger() |
boolean |
isLong() |
boolean |
isNull() |
boolean |
isNumber() |
boolean |
isString() |
String |
toLabel() |
String |
toLabel(String defaultLabel) |
String |
toString()
Get the string representation of the variant (not the variant value).
|
static Variant |
valueOf(boolean value) |
static Variant |
valueOf(double value) |
static Variant |
valueOf(int value) |
static Variant |
valueOf(long value) |
static Variant |
valueOf(Object value) |
public static final Variant NULL
public static final Variant TRUE
public static final Variant FALSE
protected Variant()
protected Variant(Object object)
protected Variant(boolean value)
protected Variant(double value)
protected Variant(int value)
protected Variant(long value)
protected Variant(String value)
protected Variant(Variant other)
public static Variant valueOf(long value)
public static Variant valueOf(int value)
public static Variant valueOf(double value)
public static Variant valueOf(boolean value)
public boolean isNull()
public String asString() throws NullValueException
NullValueException
- thrown if the variant if of type VariantType.NULL
public String asString(String defaultValue)
VariantType.NULL
.public Double asDouble(Double defaultValue)
defaultValue
- the default valuepublic double asDouble() throws NullValueException, NotConvertableException
public Integer asInteger(Integer defaultValue)
defaultValue
- the default valuepublic int asInteger() throws NullValueException, NotConvertableException
public Long asLong(Long defaultValue)
defaultValue
- the default valuepublic long asLong() throws NullValueException, NotConvertableException
public boolean asBoolean()
null
then
false
is returned. If the value is a boolean it will simply
return the value itself. If the value is a numeric
value (double, long, integer) is will return false
if the
value zero and true
otherwise. If the value is a string then
false
is returned if the string is
empty. If the string can be converted to a number (long or double) it
will be compared to that number. Otherwise it will be compared case
insensitive against the string
true.
public Boolean asBoolean(Boolean defaultValue)
defaultValue
- the default valuepublic Serializable as(VariantType variantType, Serializable defaultValue)
The default value must be of the type of the variant type parameter, otherwise a class cast exception will be thrown. The default value may also be null.
variantType
- the variant type to convert to (may be null
)defaultValue
- the default value in case the conversion fails or the variant
is NULLas(VariantType)
public Serializable as(VariantType variantType) throws NullValueException, NotConvertableException
The method converts the current variant to a plain java
Serializable
of the requested type. For the list of types than
can be expected see the java type field of VariantType
.
There are some special cases for this method:
VariantType.UNKNOWN
is requested the java
object currently set will be returned without any conversionVariantType.NULL
is requested always null
will be returned
variantType
- the target typeNullValueException
- in case the variant was of type null and should be converted
to some other typeNotConvertableException
- in case the variant cannot be converted to the target valuepublic boolean isBoolean()
public boolean isString()
public boolean isDouble()
public boolean isInteger()
public boolean isLong()
public boolean isNumber()
public String toLabel()
public String toString()
The format is
VariantType#VariantValue
.
If you want to get the string representation of the variant value itself
use asString()
instead.
public VariantType getType()
public Serializable getValue()
public int compareTo(Variant o)
compareTo
in interface Comparable<Variant>
Copyright © 2016 Eclipse NeoSCADA Project. All rights reserved.