Interface GraphNode

  • All Known Subinterfaces:
    ReactiveGraphNode

    public interface GraphNode
    A node in a tree-like structure representing a Graph or a Graph component.

    It can be:

    • a scalar value of a primitive type (boolean, string, int, long, double);
    • a graph element (vertex, edge, path or property);
    • a list of nodes;
    • a set of nodes;
    • a map of nodes.
    This interface provides test methods to find out what a node represents, and conversion methods to cast it to a particular Java type. Two generic methods as(Class) and as(GenericType) can produce any arbitrary Java type, provided that the underlying serialization runtime has been correctly configured to support the requested conversion.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <ResultT> ResultT as​(GenericType<ResultT> type)
      Deserializes and returns this node as an instance of the given type.
      <ResultT> ResultT as​(Class<ResultT> clazz)
      Deserializes and returns this node as an instance of clazz.
      boolean asBoolean()
      Returns this node as a boolean.
      double asDouble()
      Returns this node as a long integer.
      org.apache.tinkerpop.gremlin.structure.Edge asEdge()
      Returns this node as a Tinkerpop Edge.
      int asInt()
      Returns this node as an integer.
      <T> List<T> asList()
      Deserializes and returns this node as a List.
      long asLong()
      Returns this node as a long integer.
      <K,​V>
      Map<K,​V>
      asMap()
      Deserializes and returns this node as a Map.
      org.apache.tinkerpop.gremlin.process.traversal.Path asPath()
      Returns this node as a Tinkerpop Path.
      <T> org.apache.tinkerpop.gremlin.structure.Property<T> asProperty()
      Returns this node as a Tinkerpop Property.
      <T> Set<T> asSet()
      Deserializes and returns this node as a Set.
      String asString()
      A valid string representation of this node.
      org.apache.tinkerpop.gremlin.structure.Vertex asVertex()
      Returns this node as a Tinkerpop Vertex.
      <T> org.apache.tinkerpop.gremlin.structure.VertexProperty<T> asVertexProperty()
      Returns this node as a Tinkerpop VertexProperty.
      GraphNode getByIndex​(int index)
      Returns the element at the given index as a node.
      GraphNode getByKey​(Object key)
      Returns the value for the given key as a node.
      boolean isEdge()
      Returns true if this node is a Edge, and false otherwise.
      boolean isList()
      Returns true if this node is a List, and false otherwise.
      boolean isMap()
      Returns true if this node is a Map, and false otherwise.
      boolean isNull()
      Whether this node represents a null value.
      boolean isPath()
      Returns true if this node is a Path, and false otherwise.
      boolean isProperty()
      Returns true if this node is a Property, and false otherwise.
      boolean isSet()
      Returns true if this node is a Set, and false otherwise.
      boolean isValue()
      Returns true if this node is a simple scalar value, (i.e., string, boolean or number), and false otherwise.
      boolean isVertex()
      Returns true if this node is a Vertex, and false otherwise.
      boolean isVertexProperty()
      Returns true if this node is a VertexProperty, and false otherwise.
      Iterable<?> keys()
      The keys of this map node, or an empty iterator if it is not a map.
      int size()
      The size of the current node, if it is a list or map, or 0 otherwise.
    • Method Detail

      • isNull

        boolean isNull()
        Whether this node represents a null value.
      • isMap

        boolean isMap()
        Returns true if this node is a Map, and false otherwise.

        If this method returns true, you can convert this node with asMap(), or use keys() and getByKey(Object) to access the individual fields (note that entries are not ordered, so getByIndex(int) does not work).

      • keys

        Iterable<?> keys()
        The keys of this map node, or an empty iterator if it is not a map.
      • getByKey

        GraphNode getByKey​(Object key)
        Returns the value for the given key as a node.

        If this node is not a map, or does not contain the specified key, null is returned.

        If the property value has been explicitly set to null, implementors may return a special "null node" instead of null.

      • asMap

        <K,​V> Map<K,​V> asMap()
        Deserializes and returns this node as a Map.
      • isList

        boolean isList()
        Returns true if this node is a List, and false otherwise.

        If this method returns true, you can convert this node with asList(), or use size() and getByIndex(int) to access the individual fields.

      • size

        int size()
        The size of the current node, if it is a list or map, or 0 otherwise.
      • getByIndex

        GraphNode getByIndex​(int index)
        Returns the element at the given index as a node.

        If this node is not a list, or index is out of bounds (i.e. less than zero or >= size(), null is returned; no exception will be thrown.

        If the requested element has been explicitly set to null, implementors may return a special "null node" instead of null.

      • asList

        <T> List<T> asList()
        Deserializes and returns this node as a List.
      • isValue

        boolean isValue()
        Returns true if this node is a simple scalar value, (i.e., string, boolean or number), and false otherwise.

        If this method returns true, you can convert this node with asString(), asBoolean(), asInt(), asLong() or asDouble().

      • asInt

        int asInt()
        Returns this node as an integer.

        If the underlying object is not convertible to integer, implementors may choose to either throw ClassCastException or return [null | empty | some default value], whichever is deemed more appropriate.

      • asBoolean

        boolean asBoolean()
        Returns this node as a boolean.

        If the underlying object is not convertible to boolean, implementors may choose to either throw ClassCastException or return [null | empty | some default value], whichever is deemed more appropriate.

      • asLong

        long asLong()
        Returns this node as a long integer.

        If the underlying object is not convertible to long, implementors may choose to either throw ClassCastException or return [null | empty | some default value], whichever is deemed more appropriate.

      • asDouble

        double asDouble()
        Returns this node as a long integer.

        If the underlying object is not convertible to double, implementors may choose to either throw ClassCastException or return [null | empty | some default value], whichever is deemed more appropriate.

      • asString

        String asString()
        A valid string representation of this node.

        If the underlying object is not convertible to a string, implementors may choose to either throw ClassCastException or return an empty string, whichever is deemed more appropriate.

      • as

        <ResultT> ResultT as​(Class<ResultT> clazz)
        Deserializes and returns this node as an instance of clazz.

        Before attempting such a conversion, there must be an appropriate converter configured on the underlying serialization runtime.

      • as

        <ResultT> ResultT as​(GenericType<ResultT> type)
        Deserializes and returns this node as an instance of the given type.

        Before attempting such a conversion, there must be an appropriate converter configured on the underlying serialization runtime.

      • isVertex

        boolean isVertex()
        Returns true if this node is a Vertex, and false otherwise.

        If this method returns true, then asVertex() can be safely called.

      • asVertex

        org.apache.tinkerpop.gremlin.structure.Vertex asVertex()
        Returns this node as a Tinkerpop Vertex.
      • isEdge

        boolean isEdge()
        Returns true if this node is a Edge, and false otherwise.

        If this method returns true, then asEdge() can be safely called.

      • asEdge

        org.apache.tinkerpop.gremlin.structure.Edge asEdge()
        Returns this node as a Tinkerpop Edge.
      • isPath

        boolean isPath()
        Returns true if this node is a Path, and false otherwise.

        If this method returns true, then asPath() can be safely called.

      • asPath

        org.apache.tinkerpop.gremlin.process.traversal.Path asPath()
        Returns this node as a Tinkerpop Path.
      • isProperty

        boolean isProperty()
        Returns true if this node is a Property, and false otherwise.

        If this method returns true, then asProperty() can be safely called.

      • asProperty

        <T> org.apache.tinkerpop.gremlin.structure.Property<T> asProperty()
        Returns this node as a Tinkerpop Property.
      • isVertexProperty

        boolean isVertexProperty()
        Returns true if this node is a VertexProperty, and false otherwise.

        If this method returns true, then asVertexProperty() ()} can be safely called.

      • asVertexProperty

        <T> org.apache.tinkerpop.gremlin.structure.VertexProperty<T> asVertexProperty()
        Returns this node as a Tinkerpop VertexProperty.
      • isSet

        boolean isSet()
        Returns true if this node is a Set, and false otherwise.

        If this method returns true, you can convert this node with asSet(), or use size().

      • asSet

        <T> Set<T> asSet()
        Deserializes and returns this node as a Set.