org.apache.tinkerpop.gremlin.tinkergraph.structure

## Class TinkerGraph

- java.lang.Object
- - org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph

- All Implemented Interfaces:
    AutoCloseable, Graph, Host

      public final class TinkerGraph
      extends Object
      implements Graph

  An in-memory (with optional persistence on calls to `close()`), reference implementation of the property graph interfaces provided by TinkerPop.
  Author:
    Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TinkerGraph.DefaultIdManager` A default set of `TinkerGraph.IdManager` implementations for common identifier types.
    `static interface` | `TinkerGraph.IdManager<T>` TinkerGraph will use an implementation of this interface to generate identifiers when a user does not supply them and to handle identifier conversions when querying to provide better flexibility with respect to handling different data types that mean the same thing.
    `class` | `TinkerGraph.TinkerGraphEdgeFeatures`
    `class` | `TinkerGraph.TinkerGraphFeatures`
    `class` | `TinkerGraph.TinkerGraphGraphFeatures`
    `class` | `TinkerGraph.TinkerGraphVertexFeatures`
    `class` | `TinkerGraph.TinkerGraphVertexPropertyFeatures`

    - ### Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Graph

      `Graph.Exceptions, Graph.Features, Graph.Hidden, Graph.OptIn, Graph.OptIns, Graph.OptOut, Graph.OptOuts, Graph.Variables`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AtomicLong` | `currentId`
    `protected VertexProperty.Cardinality` | `defaultVertexPropertyCardinality`
    `protected TinkerGraph.IdManager<?>` | `edgeIdManager`
    `protected org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIndex<TinkerEdge>` | `edgeIndex`
    `protected Map<Object,Edge>` | `edges`
    `protected TinkerGraphComputerView` | `graphComputerView`
    `static String` | `GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY`
    `static String` | `GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER`
    `static String` | `GREMLIN_TINKERGRAPH_GRAPH_FORMAT`
    `static String` | `GREMLIN_TINKERGRAPH_GRAPH_LOCATION`
    `static String` | `GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER`
    `static String` | `GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER`
    `protected TinkerGraphVariables` | `variables`
    `protected TinkerGraph.IdManager<?>` | `vertexIdManager`
    `protected org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIndex<TinkerVertex>` | `vertexIndex`
    `protected TinkerGraph.IdManager<?>` | `vertexPropertyIdManager`
    `protected Map<Object,Vertex>` | `vertices`

    - ### Fields inherited from interface org.apache.tinkerpop.gremlin.structure.Graph

      `GRAPH`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Vertex` | `addVertex(Object... keyValues)` Add a `Vertex` to the graph given an optional series of key/value pairs.
    `void` | `clear()`
    `void` | `close()` This method only has an effect if the `GREMLIN_TINKERGRAPH_GRAPH_LOCATION` is set, in which case the data in the graph is persisted to that location.
    `GraphComputer` | `compute()` Generate a `GraphComputer` using the default engine of the underlying graph system.
    `<C extends GraphComputer> C` | `compute(Class<C> graphComputerClass)` Declare the `GraphComputer` to use for OLAP operations on the graph.
    `Configuration` | `configuration()` Get the `org.apache.commons.configuration.Configuration` associated with the construction of this graph.
    `<E extends Element> void` | `createIndex(String key, Class<E> elementClass)` Create an index for said element class (`Vertex` or `Edge`) and said property key.
    `<E extends Element> void` | `dropIndex(String key, Class<E> elementClass)` Drop the index for the specified element class (`Vertex` or `Edge`) and key.
    `Iterator<Edge>` | `edges(Object... edgeIds)` Get the `Edge` objects in this graph with the provided edge ids or `Edge` objects.
    `Graph.Features` | `features()` Return TinkerGraph feature set.
    `<E extends Element> Set<String>` | `getIndexedKeys(Class<E> elementClass)` Return all the keys currently being index for said element class (`Vertex` or `Edge`).
    `<I extends Io> I` | `io(Io.Builder<I> builder)` Construct a particular `Io` implementation for reading and writing the `Graph` and other data.
    `static TinkerGraph` | `open()` Open a new `TinkerGraph` instance.
    `static TinkerGraph` | `open(Configuration configuration)` Open a new `TinkerGraph` instance.
    `String` | `toString()`
    `Transaction` | `tx()` Configure and control the transactions for those graphs that support this feature.
    `Graph.Variables` | `variables()` A collection of global `Graph.Variables` associated with the graph.
    `Iterator<Vertex>` | `vertices(Object... vertexIds)` Get the `Vertex` objects in this graph with the provided vertex ids or `Vertex` objects themselves.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.tinkerpop.gremlin.structure.Graph

      `addVertex, traversal, traversal`

    - ### Methods inherited from interface org.apache.tinkerpop.gremlin.structure.util.Host

      `getHostingVertex`

- - ### Field Detail

    - #### GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER

          public static final String GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER

      See Also:
        Constant Field Values

    - #### GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER

          public static final String GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER

      See Also:
        Constant Field Values

    - #### GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER

          public static final String GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER

      See Also:
        Constant Field Values

    - #### GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY

          public static final String GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY

      See Also:
        Constant Field Values

    - #### GREMLIN_TINKERGRAPH_GRAPH_LOCATION

          public static final String GREMLIN_TINKERGRAPH_GRAPH_LOCATION

      See Also:
        Constant Field Values

    - #### GREMLIN_TINKERGRAPH_GRAPH_FORMAT

          public static final String GREMLIN_TINKERGRAPH_GRAPH_FORMAT

      See Also:
        Constant Field Values

    - #### currentId

          protected AtomicLong currentId

    - #### vertices

          protected Map<Object,Vertex> vertices

    - #### edges

          protected Map<Object,Edge> edges

    - #### variables

          protected TinkerGraphVariables variables

    - #### graphComputerView

          protected TinkerGraphComputerView graphComputerView

    - #### vertexIndex

          protected org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIndex<TinkerVertex> vertexIndex

    - #### edgeIndex

          protected org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIndex<TinkerEdge> edgeIndex

    - #### vertexIdManager

          protected final TinkerGraph.IdManager<?> vertexIdManager

    - #### edgeIdManager

          protected final TinkerGraph.IdManager<?> edgeIdManager

    - #### vertexPropertyIdManager

          protected final TinkerGraph.IdManager<?> vertexPropertyIdManager

    - #### defaultVertexPropertyCardinality

          protected final VertexProperty.Cardinality defaultVertexPropertyCardinality

  - ### Method Detail

    - #### open

          public static TinkerGraph open()

      Open a new `TinkerGraph` instance.

      Reference Implementation Help: If a `Graph` implementation does not require a `Configuration` (or perhaps has a default configuration) it can choose to implement a zero argument `open()` method. This is an optional constructor method for TinkerGraph. It is not enforced by the Gremlin Test Suite.

    - #### open

          public static TinkerGraph open(Configuration configuration)

      Open a new `TinkerGraph` instance.

      Reference Implementation Help: This method is the one use by the `GraphFactory` to instantiate `Graph` instances. This method must be overridden for the Structure Test Suite to pass. Implementers have latitude in terms of how exceptions are handled within this method. Such exceptions will be considered implementation specific by the test suite as all test generate graph instances by way of `GraphFactory`. As such, the exceptions get generalized behind that facade and since `GraphFactory` is the preferred method to opening graphs it will be consistent at that level.
      Parameters:
        `configuration` - the configuration for the instance
      Returns:
        a newly opened `Graph`

    - #### addVertex

          public Vertex addVertex(Object... keyValues)

      Description copied from interface: `Graph`
      Add a `Vertex` to the graph given an optional series of key/value pairs. These key/values must be provided in an even number where the odd numbered arguments are `String` property keys and the even numbered arguments are the related property values.
      Specified by:
        `addVertex` in interface `Graph`
      Parameters:
        `keyValues` - The key/value pairs to turn into vertex properties
      Returns:
        The newly created vertex

    - #### compute

          public <C extends GraphComputer> C compute(Class<C> graphComputerClass)

      Description copied from interface: `Graph`
      Declare the `GraphComputer` to use for OLAP operations on the graph. If the graph does not support graph computer then an `UnsupportedOperationException` is thrown.
      Specified by:
        `compute` in interface `Graph`
      Parameters:
        `graphComputerClass` - The graph computer class to use.
      Returns:
        A graph computer for processing this graph

    - #### compute

          public GraphComputer compute()

      Description copied from interface: `Graph`
      Generate a `GraphComputer` using the default engine of the underlying graph system. This is a shorthand method for the more involved method that uses `Graph.compute(Class)`.
      Specified by:
        `compute` in interface `Graph`
      Returns:
        A default graph computer

    - #### variables

          public Graph.Variables variables()

      Description copied from interface: `Graph`
      A collection of global `Graph.Variables` associated with the graph. Variables are used for storing metadata about the graph.
      Specified by:
        `variables` in interface `Graph`
      Returns:
        The variables associated with this graph

    - #### io

          public <I extends Io> I io(Io.Builder<I> builder)

      Description copied from interface: `Graph`
      Construct a particular `Io` implementation for reading and writing the `Graph` and other data. End-users will "select" the `Io` implementation that they want to use by supplying the `Io.Builder` that constructs it. In this way, `Graph` vendors can supply their `IoRegistry` to that builder thus allowing for custom serializers to be auto-configured into the `Io` instance. Registering custom serializers is particularly useful for those graphs that have complex types for `Element` identifiers. For those graphs that do not need to register any custom serializers, the default implementation should suffice. If the default is overridden, take care to register the current graph via the `Io.Builder.graph(Graph)` method.
      Specified by:
        `io` in interface `Graph`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### clear

          public void clear()

    - #### close

          public void close()

      This method only has an effect if the `GREMLIN_TINKERGRAPH_GRAPH_LOCATION` is set, in which case the data in the graph is persisted to that location. This method may be called multiple times and does not release resources.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Graph`

    - #### tx

          public Transaction tx()

      Description copied from interface: `Graph`
      Configure and control the transactions for those graphs that support this feature. Note that this method does not indicate the creation of a "transaction" object. A `Transaction` in the TinkerPop context is a transaction "factory" or "controller" that helps manage transactions owned by the underlying graph database.
      Specified by:
        `tx` in interface `Graph`

    - #### configuration

          public Configuration configuration()

      Description copied from interface: `Graph`
      Get the `org.apache.commons.configuration.Configuration` associated with the construction of this graph. Whatever configuration was passed to `GraphFactory#open(org.apache.commons.configuration.Configuration)` is what should be returned by this method.
      Specified by:
        `configuration` in interface `Graph`
      Returns:
        the configuration used during graph construction.

    - #### vertices

          public Iterator<Vertex> vertices(Object... vertexIds)

      Description copied from interface: `Graph`
      Get the `Vertex` objects in this graph with the provided vertex ids or `Vertex` objects themselves. If no ids are provided, get all vertices. Note that a vertex identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the `Graph.Features` around id support, multiple arguments might be applicable here.

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsNumericIds()` then it should support filters as with:
      - g.vertices(v)
      - g.vertices(v.id())
      - g.vertices(1)
      - g.vertices(1L)
      - g.vertices(1.0d)
      - g.vertices(1.0f)
      - g.vertices("1")

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsCustomIds()` ()} then it should support filters as with:
      - g.vertices(v)
      - g.vertices(v.id())
      - g.vertices(v.id().toString())

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsAnyIds()` ()} then it should support filters as with:
      - g.vertices(v)
      - g.vertices(v.id())

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsStringIds()` ()} then it should support filters as with:
      - g.vertices(v)
      - g.vertices(v.id().toString())
      - g.vertices("id")

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsStringIds()` ()} then it should support filters as with:
      - g.vertices(v)
      - g.vertices(v.id().toString())
      - g.vertices("id")
      Specified by:
        `vertices` in interface `Graph`
      Parameters:
        `vertexIds` - the ids of the vertices to get
      Returns:
        an `Iterator` of vertices that match the provided vertex ids

    - #### edges

          public Iterator<Edge> edges(Object... edgeIds)

      Description copied from interface: `Graph`
      Get the `Edge` objects in this graph with the provided edge ids or `Edge` objects. If no ids are provided, get all edges. Note that an edge identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the `Graph.Features` around id support, multiple arguments might be applicable here.

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsNumericIds()` then it should support filters as with:
      - g.edges(e)
      - g.edges(e.id())
      - g.edges(1)
      - g.edges(1L)
      - g.edges(1.0d)
      - g.edges(1.0f)
      - g.edges("1")

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsCustomIds()` ()} then it should support filters as with:
      - g.edges(e)
      - g.edges(e.id())
      - g.edges(e.id().toString())

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsAnyIds()` ()} then it should support filters as with:
      - g.edges(e)
      - g.edges(e.id())

      If the graph return `true` for `Graph.Features.ElementFeatures.supportsStringIds()` ()} then it should support filters as with:
      - g.edges(e)
      - g.edges(e.id().toString())
      - g.edges("id")
      Specified by:
        `edges` in interface `Graph`
      Parameters:
        `edgeIds` - the ids of the edges to get
      Returns:
        an `Iterator` of edges that match the provided edge ids

    - #### features

          public Graph.Features features()

      Return TinkerGraph feature set.

      Reference Implementation Help: Implementers only need to implement features for which there are negative or instance configured features. By default, all `Graph.Features` return true.
      Specified by:
        `features` in interface `Graph`

    - #### createIndex

          public <E extends Element> void createIndex(String key,
                                                      Class<E> elementClass)

      Create an index for said element class (`Vertex` or `Edge`) and said property key. Whenever an element has the specified key mutated, the index is updated. When the index is created, all existing elements are indexed to ensure that they are captured by the index.
      Type Parameters:
        `E` - The type of the element class
      Parameters:
        `key` - the property key to index
        `elementClass` - the element class to index

    - #### dropIndex

          public <E extends Element> void dropIndex(String key,
                                                    Class<E> elementClass)

      Drop the index for the specified element class (`Vertex` or `Edge`) and key.
      Type Parameters:
        `E` - The type of the element class
      Parameters:
        `key` - the property key to stop indexing
        `elementClass` - the element class of the index to drop

    - #### getIndexedKeys

          public <E extends Element> Set<String> getIndexedKeys(Class<E> elementClass)

      Return all the keys currently being index for said element class (`Vertex` or `Edge`).
      Type Parameters:
        `E` - The type of the element class
      Parameters:
        `elementClass` - the element class to get the indexed keys for
      Returns:
        the set of keys currently being indexed

Copyright © 2013–2018 Apache Software Foundation. All rights reserved.