public class

Variant

extends Object
java.lang.Object
   ↳ com.carto.core.Variant

Class Overview

JSON value. Can contain JSON-style structured data, including objects and arrays.

Summary

Public Constructors
Variant()
Constructs a null Variant object.
Variant(boolean boolVal)
Constructs Variant object from a boolean.
Variant(long longVal)
Constructs Variant object from an integer.
Variant(double doubleVal)
Constructs Variant object from a double.
Variant(String string)
Constructs Variant object from a string.
Variant(VariantVector array)
Constructs Variant object from a list of values.
Variant(StringVariantMap object)
Constructs Variant object from a map of values.
Public Methods
boolean containsObjectKey(String key)
Returns true if object elements contains the specified key.
synchronized void delete()
boolean equals(Object obj)
Checks if this object is equal to the specified object.
static Variant fromString(String str)
Creates a Variant object from a JSON string representation.
Variant getArrayElement(int idx)
Returns the element of array at specified position.
int getArraySize()
Returns the number of elements in the array.
boolean getBool()
Returns the boolean value of this variant.
double getDouble()
Returns the floating point value of this variant.
long getLong()
Returns the integer value of this variant.
Variant getObjectElement(String key)
Returns the element of object with the specified key.
StringVector getObjectKeys()
Returns all the keys in the object.
String getString()
Returns the string value of this variant.
VariantType getType()
Returns the type of this variant.
int hashCode()
Returns the hash value of this object.
String toString()
Converts the variant to JSON string.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Variant ()

Constructs a null Variant object.

public Variant (boolean boolVal)

Constructs Variant object from a boolean.

Parameters
boolVal The boolean value.

public Variant (long longVal)

Constructs Variant object from an integer.

Parameters
longVal The integer value.

public Variant (double doubleVal)

Constructs Variant object from a double.

Parameters
doubleVal The double value.

public Variant (String string)

Constructs Variant object from a string.

Parameters
string The string value.

public Variant (VariantVector array)

Constructs Variant object from a list of values.

Parameters
array The array of JSON values.

public Variant (StringVariantMap object)

Constructs Variant object from a map of values.

Parameters
object The map of JSON values.

Public Methods

public boolean containsObjectKey (String key)

Returns true if object elements contains the specified key.

Parameters
key The key of the object element to check.
Returns
  • True if the specified key exists in the object. If the element is not an object or the key does not exist, false is returned.

public synchronized void delete ()

public boolean equals (Object obj)

Checks if this object is equal to the specified object.

Parameters
obj The reference object.
Returns
  • True when objects are equal, false otherwise.

public static Variant fromString (String str)

Creates a Variant object from a JSON string representation.

Parameters
str The JSON string to use for the variant.
Returns
  • The corresponding Variant object.
Throws
Exception If the string parsing fails.

public Variant getArrayElement (int idx)

Returns the element of array at specified position.

Parameters
idx The index of the array element to return (starting from 0).
Returns
  • The array element at specified position or null type if the element does not exist or the variant is not an array.

public int getArraySize ()

Returns the number of elements in the array.

Returns
  • The number of elements in the array if the variant is of array type. Otherwise 0 is returned.

public boolean getBool ()

Returns the boolean value of this variant.

Returns
  • The boolean value of the variant. If the variant is not boolean, false will be returned.

public double getDouble ()

Returns the floating point value of this variant.

Returns
  • The floating point value of the variant. If the variant is integer, it will be converted to floating point. Otherwise 0.0 is be returned.

public long getLong ()

Returns the integer value of this variant.

Returns
  • The integer value of the variant. If the variant is not integer, 0 will be returned.

public Variant getObjectElement (String key)

Returns the element of object with the specified key.

Parameters
key The key of the object element to return.
Returns
  • The object element with the specified key or null type if the element does not exist or the variant is not an object.

public StringVector getObjectKeys ()

Returns all the keys in the object.

Returns
  • The list containing all the keys of the object if the variant is of object type. Otherwise empty list is returned.

public String getString ()

Returns the string value of this variant.

Returns
  • The string value of the variant. If the variant is not string, empty string will be returned.

public VariantType getType ()

Returns the type of this variant.

Returns
  • The type of this variant.

public int hashCode ()

Returns the hash value of this object.

Returns
  • The hash value of this object.

public String toString ()

Converts the variant to JSON string.

Returns
  • The JSON string corresponding to the variant.