Class GValue<V>

  • All Implemented Interfaces:
    Serializable

    public class GValue<V>
    extends Object
    implements Serializable
    A GValue is a variable or literal value that is used in a Traversal. 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. The GValue also includes the GType that describes the type it contains.
    See Also:
    Serialized Form
    • 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 with instanceof on the value, but this might be helpful for cases where the value was constructed with a null value which might just return as Object.
      • isNull

        public boolean isNull()
        Determines if the value held is of a null value.
      • get

        public V get()
        Gets the value.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • of

        public static <V> GValue<V> of​(String name,
                                       V value)
        Create a new Var with the specified name and value. If the argument provide is already a GValue then an IllegalArgumentException is thrown.
        Parameters:
        name - the name of the variable
        value - the value of the variable
        Throws:
        IllegalArgumentException - if value is already a GValue
      • ofString

        public static GValue<String> ofString​(String name,
                                              String value)
        Create a new GValue for a string value with a specified name.
      • ofInteger

        public static GValue<Integer> ofInteger​(String name,
                                                Integer value)
        Create a new GValue for an integer value with a specified name.
      • ofBoolean

        public static GValue<Boolean> ofBoolean​(String name,
                                                Boolean value)
        Create a new GValue for a boolean value with a specified name.
      • ofDouble

        public static GValue<Double> ofDouble​(String name,
                                              Double value)
        Create a new GValue for a double value with a specified name.
      • ofBigInteger

        public static GValue<BigInteger> ofBigInteger​(String name,
                                                      BigInteger value)
        Create a new GValue for a BigInteger value with a specified name.
      • ofBigDecimal

        public static GValue<BigDecimal> ofBigDecimal​(String name,
                                                      BigDecimal value)
        Create a new GValue for a BigDecimal value with a specified name.
      • ofLong

        public static GValue<Long> ofLong​(String name,
                                          Long value)
        Create a new GValue for a long value with a specified name.
      • ofMap

        public static GValue<Map> ofMap​(String name,
                                        Map value)
        Create a new GValue for a map value with a specified name.
      • ofList

        public static <T> GValue<List<T>> ofList​(String name,
                                                 List<T> value)
        Create a new GValue for a list value with a specified name.
      • ofSet

        public static GValue<Set> ofSet​(String name,
                                        Set value)
        Create a new GValue for a set value with a specified name.
      • ofVertex

        public static GValue<Vertex> ofVertex​(String name,
                                              Vertex value)
        Create a new GValue for a vertex value with a specified name.
      • getFrom

        public static <T> T getFrom​(Object o)
        If the object is a GValue then get its value, otherwise return the object as-is.
      • valueInstanceOf

        public static boolean valueInstanceOf​(Object o,
                                              GType type)
        Tests if the object is a GValue and if so, checks the type of the value against the provided GType.
      • valueInstanceOfCollection

        public static boolean valueInstanceOfCollection​(Object o)
        Tests if the object is a GValue 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 a GValue and if so, checks if the type of the value is a numeric.
      • instanceOf

        public static boolean instanceOf​(Object o,
                                         GType type)
        Checks the type of the object against the provided GType. If the object is a GValue then it can directly check the type, otherwise it will test the given object's class itself using the mapping on the GType.
      • instanceOfCollection

        public static boolean instanceOfCollection​(Object o)
        Returns true if the object is a collection or a GValue that contains a Collection.
      • instanceOfNumber

        public static boolean instanceOfNumber​(Object o)
        Returns true if the object is a number or a GValue that contains a number.
      • ensureGValues

        public static <T> GValue<T>[] ensureGValues​(Object[] args)
        The elements in object array argument are examined to see if they are GValue objects. If they are, they are preserved as is. If they are not then they are wrapped in a GValue object.
      • resolveToValues

        public static Object[] resolveToValues​(GValue<?>[] gvalues)
        Converts GValue objects argument array to their values to prevent them from leaking to the Graph API. Providers extending from this step should use this method to get actual values to prevent any GValue objects from leaking to the Graph API.
      • valueOf

        public static Object valueOf​(Object either)
        Takes an argument that is either a GValue or an object and if the former, returns the child object and if the latter returns the object itself.
      • numberOf

        public static Number numberOf​(Object either)
        Takes an argument that is either a GValue or an object and returns its Number form, otherwise throws an exception.