Skip to content

Gremlin Methods

okram edited this page Mar 22, 2011 · 41 revisions

IMPORTANT: The full Java API can be seamlessly accessed by Gremlin. Thus, both the Blueprints and Pipes APIs can be accessed from within Gremlin. For behaviors that are commonly used in Gremlin, Gremlin adds MetaClass methods/operators to make it easier and faster to work with the Blueprints and Pipes APIs. These MetaClass methods/operators are provided in the table below.

Developer Note: If you come up a with a generally useful method and would like to include it into the main Gremlin distribution, please make an issue or provide the appropriate pull request.

method/operator equivalence description
Graph.v(Object) Graph.getVertex(Object) get a vertex by its id
Graph.e(Object) Graph.getEdge(Object) get an edge by its id
Graph.idx(String) Graph.getIndex(String, Class, Type) get an index by its name
Graph.addVertex() Graph.addVertex(null) add a vertex
Graph.addVertex(Object, Map) no simple representation add a vertex with property map
Graph.addVertex(Map) no simple representation add a vertex with property map
Graph.addEdge(Object, Vertex, Vertex, String, Map) no simple representation add an edge with property map
Graph.addEdge(Vertex, Vertex, String, Map) no simple representation add an edge with property map
Index[Map.Entry] Index.get(String, Object) get an element by its key/value
Element.key Element.getProperty(key) get the value of a property by key
Element.key = value Element.setProperty(key,value) set the value of a property
Element[key] Element.getProperty(key) get the value of a property by key
Element[key] = value Element.setProperty(key,value) set the value of a property
Element.keys() Element.getPropertyKeys() get the property keys of the element
Element.values() no simple representation get the property values of the element
Element.map() no simple representation get the property map of the element
Pipe>>1 Iterator.next() get the next object in the pipe
Pipe>>Integer no simple representation get the next n objects in pipe and return as a list
Pipe>>-1 no simple representation next() all the objects out of the pipe
Pipe>>Collection no simple representation add all the pipe objects to the collection
Pipe.count() PipeHelper.counter(Pipe) count objects in the pipe
Pipe.mean() no simple representation the average of the objects in the pipe

Note: All Pipe methods/operators also work for Iterator and Iterable.