Class GValue<V>
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.process.traversal.step.GValue<V>
-
- All Implemented Interfaces:
Serializable
public class GValue<V> extends Object implements Serializable
AGValue
is a variable or literal value that is used in aTraversal
. It is composed of a key-value pair where the key is the name given to the variable and the value is the object that the variable resolved to. If the name is not given, the value was provided literally in the traversal. The value of the variable can be any object. TheGValue
also includes theGType
that describes the type it contains.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> GValue<T>[]
ensureGValues(Object[] args)
The elements in object array argument are examined to see if they areGValue
objects.boolean
equals(Object o)
V
get()
Gets the value.static <T> T
getFrom(Object o)
If the object is aGValue
then get its value, otherwise return the object as-is.String
getName()
Gets the name of the variable if it was defined as such and returns null if the value was a literal.GType
getType()
Gets the type of the value.int
hashCode()
static boolean
instanceOf(Object o, GType type)
Checks the type of the object against the providedGType
.static boolean
instanceOfCollection(Object o)
static boolean
instanceOfNumber(Object o)
Returnstrue
if the object is a number or aGValue
that contains a number.boolean
isNull()
Determines if the value held is of anull
value.boolean
isVariable()
Determines if the value held by this object was defined as a variable or a literal value.static Number
numberOf(Object either)
Takes an argument that is either aGValue
or an object and returns itsNumber
form, otherwise throws an exception.static <V> GValue<V>
of(String name, V value)
Create a newVar
with the specified name and value.static GValue<BigDecimal>
ofBigDecimal(String name, BigDecimal value)
Create a newGValue
for a BigDecimal value with a specified name.static GValue<BigInteger>
ofBigInteger(String name, BigInteger value)
Create a newGValue
for a BigInteger value with a specified name.static GValue<Boolean>
ofBoolean(String name, Boolean value)
Create a newGValue
for a boolean value with a specified name.static GValue<Double>
ofDouble(String name, Double value)
Create a newGValue
for a double value with a specified name.static GValue<Integer>
ofInteger(String name, Integer value)
Create a newGValue
for an integer value with a specified name.static <T> GValue<List<T>>
ofList(String name, List<T> value)
Create a newGValue
for a list value with a specified name.static GValue<Long>
ofLong(String name, Long value)
Create a newGValue
for a long value with a specified name.static GValue<Map>
ofMap(String name, Map value)
Create a newGValue
for a map value with a specified name.static GValue<Set>
ofSet(String name, Set value)
Create a newGValue
for a set value with a specified name.static GValue<String>
ofString(String name, String value)
Create a newGValue
for a string value with a specified name.static GValue<Vertex>
ofVertex(String name, Vertex value)
Create a newGValue
for a vertex value with a specified name.static Object[]
resolveToValues(GValue<?>[] gvalues)
ConvertsGValue
objects argument array to their values to prevent them from leaking to the Graph API.String
toString()
static boolean
valueInstanceOf(Object o, GType type)
static boolean
valueInstanceOfCollection(Object o)
Tests if the object is aGValue
and if so, checks if the type of the value is a collection.static boolean
valueInstanceOfNumeric(Object o)
Tests if the object is aGValue
and if so, checks if the type of the value is a numeric.static Object
valueOf(Object either)
Takes an argument that is either aGValue
or an object and if the former, returns the child object and if the latter returns the object itself.
-
-
-
Method Detail
-
isVariable
public boolean isVariable()
Determines if the value held by this object was defined as a variable or a literal value. Literal values simply have no name.
-
getName
public String getName()
Gets the name of the variable if it was defined as such and returns null if the value was a literal.
-
getType
public GType getType()
Gets the type of the value. The explicit type could be determined withinstanceof
on the value, but this might be helpful for cases where the value was constructed with anull
value which might just return asObject
.
-
isNull
public boolean isNull()
Determines if the value held is of anull
value.
-
get
public V get()
Gets the value.
-
of
public static <V> GValue<V> of(String name, V value)
Create a newVar
with the specified name and value. If the argument provide is already aGValue
then an IllegalArgumentException is thrown.- Parameters:
name
- the name of the variablevalue
- the value of the variable- Throws:
IllegalArgumentException
- if value is already aGValue
-
ofString
public static GValue<String> ofString(String name, String value)
Create a newGValue
for a string value with a specified name.
-
ofInteger
public static GValue<Integer> ofInteger(String name, Integer value)
Create a newGValue
for an integer value with a specified name.
-
ofBoolean
public static GValue<Boolean> ofBoolean(String name, Boolean value)
Create a newGValue
for a boolean value with a specified name.
-
ofDouble
public static GValue<Double> ofDouble(String name, Double value)
Create a newGValue
for a double value with a specified name.
-
ofBigInteger
public static GValue<BigInteger> ofBigInteger(String name, BigInteger value)
Create a newGValue
for a BigInteger value with a specified name.
-
ofBigDecimal
public static GValue<BigDecimal> ofBigDecimal(String name, BigDecimal value)
Create a newGValue
for a BigDecimal value with a specified name.
-
ofLong
public static GValue<Long> ofLong(String name, Long value)
Create a newGValue
for a long value with a specified name.
-
ofMap
public static GValue<Map> ofMap(String name, Map value)
Create a newGValue
for a map value with a specified name.
-
ofList
public static <T> GValue<List<T>> ofList(String name, List<T> value)
Create a newGValue
for a list value with a specified name.
-
ofSet
public static GValue<Set> ofSet(String name, Set value)
Create a newGValue
for a set value with a specified name.
-
ofVertex
public static GValue<Vertex> ofVertex(String name, Vertex value)
Create a newGValue
for a vertex value with a specified name.
-
getFrom
public static <T> T getFrom(Object o)
If the object is aGValue
then get its value, otherwise return the object as-is.
-
valueInstanceOfCollection
public static boolean valueInstanceOfCollection(Object o)
Tests if the object is aGValue
and if so, checks if the type of the value is a collection.
-
valueInstanceOfNumeric
public static boolean valueInstanceOfNumeric(Object o)
Tests if the object is aGValue
and if so, checks if the type of the value is a numeric.
-
instanceOfCollection
public static boolean instanceOfCollection(Object o)
-
instanceOfNumber
public static boolean instanceOfNumber(Object o)
Returnstrue
if the object is a number or aGValue
that contains a number.
-
valueOf
public static Object valueOf(Object either)
Takes an argument that is either aGValue
or an object and if the former, returns the child object and if the latter returns the object itself.
-
-