Interface Traversal<S,E>
-
- All Superinterfaces:
AutoCloseable
,Cloneable
,Iterator<E>
,Serializable
- All Known Subinterfaces:
CredentialTraversal<S,E>
,CredentialTraversalDsl<S,E>
,GraphTraversal<S,E>
,GraphTraversal.Admin<S,E>
,RemoteTraversal<S,E>
,Traversal.Admin<S,E>
- All Known Implementing Classes:
AbstractLambdaTraversal
,AbstractRemoteTraversal
,ColumnTraversal
,ConstantTraversal
,DefaultCredentialTraversal
,DefaultGraphTraversal
,DefaultTraversal
,DriverRemoteTraversal
,EmbeddedRemoteTraversal
,EmptyTraversal
,HaltedTraversersCountTraversal
,IdentityTraversal
,LoopTraversal
,PredicateTraversal
,ScriptTraversal
,TokenTraversal
,TrueTraversal
,ValueTraversal
public interface Traversal<S,E> extends Iterator<E>, Serializable, Cloneable, AutoCloseable
ATraversal
represents a directed walk over aGraph
. This is the base interface for all traversal's, where each extending interface is seen as a domain specific language. For example,GraphTraversal
is a domain specific language for traversing a graph using "graph concepts" (e.g. vertices, edges). Another example may represent the graph using "social concepts" (e.g. people, cities, artifacts). ATraversal
is evaluated in one of two ways: iterator-based OLTP orGraphComputer
-based OLAP. OLTP traversals leverage an iterator and are executed within a single JVM (with data access allowed to be remote). OLAP traversals leverageGraphComputer
and are executed between multiple JVMs (and/or cores).- Author:
- Marko A. Rodriguez (http://markorodriguez.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Traversal.Admin<S,E>
static class
Traversal.Exceptions
A collection ofException
types associated with Traversal execution.static class
Traversal.Symbols
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default Traversal.Admin<S,E>
asAdmin()
Get access to administrative methods of the traversal via its accompanyingTraversal.Admin
.default void
close()
Releases resources opened in any steps that implementAutoCloseable
.default TraversalExplanation
explain()
Return aTraversalExplanation
that shows how this traversal will mutate with each appliedTraversalStrategy
.default <C extends Collection<E>>
Cfill(C collection)
Add all the results of the traversal to the provided collection.default <E2> void
forEachRemaining(Class<E2> endType, Consumer<E2> consumer)
A traversal can be rewritten such that its defined end type E may yield objects of a different type.default void
forEachRemaining(Consumer<? super E> action)
default <A,B>
Traversal<A,B>iterate()
Iterate all theTraverser
instances in the traversal.default List<E>
next(int amount)
Get the next n-number of results from the traversal.default Traversal<S,E>
none()
Filter all traversers in the traversal.default void
notifyClose()
default Traversal<S,TraversalMetrics>
profile()
Profile the traversal.default <T> CompletableFuture<T>
promise(Function<Traversal<S,E>,T> traversalFunction)
Starts a promise to execute a function on the currentTraversal
that will be completed in the future.default BulkSet<E>
toBulkSet()
Put all the results into aBulkSet
.default List<E>
toList()
Put all the results into anArrayList
.default Set<E>
toSet()
Put all the results into aHashSet
.default Stream<E>
toStream()
Return the traversal as aStream
.default Optional<E>
tryNext()
Return anOptional
of the next E object in the traversal.
-
-
-
Method Detail
-
asAdmin
default Traversal.Admin<S,E> asAdmin()
Get access to administrative methods of the traversal via its accompanyingTraversal.Admin
.- Returns:
- the admin of this traversal
-
tryNext
default Optional<E> tryNext()
Return anOptional
of the next E object in the traversal. If the traversal is empty, then anOptional.empty()
is returned.- Returns:
- an optional of the next object in the traversal
-
next
default List<E> next(int amount)
Get the next n-number of results from the traversal. If the traversal has less than n-results, then only that number of results are returned.- Parameters:
amount
- the number of results to get- Returns:
- the n-results in a
List
-
toList
default List<E> toList()
Put all the results into anArrayList
.- Returns:
- the results in a list
-
toBulkSet
default BulkSet<E> toBulkSet()
Put all the results into aBulkSet
. This can reduce both time and space when aggregating results by ensuring a weighted set.- Returns:
- the results in a bulk set
-
toStream
default Stream<E> toStream()
Return the traversal as aStream
.- Returns:
- the traversal as a stream.
-
promise
default <T> CompletableFuture<T> promise(Function<Traversal<S,E>,T> traversalFunction)
Starts a promise to execute a function on the currentTraversal
that will be completed in the future. Note that this method can only be used if theTraversal
is constructed usingAnonymousTraversalSource.withRemote(Configuration)
. Calling this method otherwise will yield anIllegalStateException
.
-
fill
default <C extends Collection<E>> C fill(C collection)
Add all the results of the traversal to the provided collection.- Parameters:
collection
- the collection to fill- Returns:
- the collection now filled
-
iterate
default <A,B> Traversal<A,B> iterate()
Iterate all theTraverser
instances in the traversal. What is returned is the empty traversal. It is assumed that what is desired from the computation is are the sideEffects yielded by the traversal.- Returns:
- the fully drained traversal
-
none
default Traversal<S,E> none()
Filter all traversers in the traversal. This step has narrow use cases and is primarily intended for use as a signal to remote servers thatiterate()
was called. While it may be directly used, it is often a sign that a traversal should be re-written in another form.- Returns:
- the updated traversal with respective
NoneStep
.
-
profile
default Traversal<S,TraversalMetrics> profile()
Profile the traversal.- Returns:
- the updated traversal with respective
ProfileSideEffectStep
.
-
explain
default TraversalExplanation explain()
Return aTraversalExplanation
that shows how this traversal will mutate with each appliedTraversalStrategy
.- Returns:
- a traversal explanation
-
forEachRemaining
default <E2> void forEachRemaining(Class<E2> endType, Consumer<E2> consumer)
A traversal can be rewritten such that its defined end type E may yield objects of a different type. This helper method allows for the casting of the output to the known the type.- Type Parameters:
E2
- the known output type of the traversal- Parameters:
endType
- the true output type of the traversalconsumer
- aConsumer
to process each output
-
forEachRemaining
default void forEachRemaining(Consumer<? super E> action)
- Specified by:
forEachRemaining
in interfaceIterator<S>
-
close
default void close() throws Exception
Releases resources opened in any steps that implementAutoCloseable
. If this method is overridden,the implementer should invokenotifyClose()
.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
notifyClose
default void notifyClose()
-
-