You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2022/01/24 21:47:14 UTC
[tinkerpop] branch TINKERPOP-2681 updated: Cleaned up option() implementation in GraphTraversal
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2681
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/TINKERPOP-2681 by this push:
new d34a421 Cleaned up option() implementation in GraphTraversal
d34a421 is described below
commit d34a42121dd445fedeb3803521c488f1769df48a
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Mon Jan 24 16:46:44 2022 -0500
Cleaned up option() implementation in GraphTraversal
---
.../language/grammar/TraversalMethodVisitor.java | 27 ++++++++++
.../traversal/dsl/graph/GraphTraversal.java | 59 +++++++++-------------
2 files changed, 51 insertions(+), 35 deletions(-)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java
index e4eaa4d..ed1ae19 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java
@@ -89,46 +89,73 @@ public class TraversalMethodVisitor extends TraversalRootVisitor<GraphTraversal>
return this.graphTraversal.addV(GenericLiteralVisitor.getStringLiteral(ctx.stringLiteral()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_mergeV_Map(final GremlinParser.TraversalMethod_mergeV_MapContext ctx) {
return this.graphTraversal.mergeV(GenericLiteralVisitor.getMapLiteral(ctx.genericLiteralMap()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_mergeV_Traversal(final GremlinParser.TraversalMethod_mergeV_TraversalContext ctx) {
return this.graphTraversal.mergeV(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Traversal visitTraversalMethod_mergeV_empty(final GremlinParser.TraversalMethod_mergeV_emptyContext ctx) {
return this.graphTraversal.mergeV();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Traversal visitTraversalMethod_mergeE_empty(final GremlinParser.TraversalMethod_mergeE_emptyContext ctx) {
return this.graphTraversal.mergeE();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_mergeE_Map(final GremlinParser.TraversalMethod_mergeE_MapContext ctx) {
return this.graphTraversal.mergeE(GenericLiteralVisitor.getMapLiteral(ctx.genericLiteralMap()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_mergeE_Traversal(final GremlinParser.TraversalMethod_mergeE_TraversalContext ctx) {
return this.graphTraversal.mergeE(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_addE_Traversal(final GremlinParser.TraversalMethod_addE_TraversalContext ctx) {
return this.graphTraversal.addE(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_addV_Traversal(final GremlinParser.TraversalMethod_addV_TraversalContext ctx) {
return this.graphTraversal.addV(antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public GraphTraversal visitTraversalMethod_addE_String(final GremlinParser.TraversalMethod_addE_StringContext ctx) {
final int childIndexOfParameterEdgeLabel = 2;
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 53eb732..7a985dc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -3146,64 +3146,53 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
////
/**
- * This step modifies {@link #choose(Function)} to specifies the available choices that might be executed.
+ * This is a step modulator to a {@link TraversalOptionParent} like {@code choose()} or {@code mergeV()} where the
+ * provided argument associated to the {@code token} is applied according to the semantics of the step. Please see
+ * the documentation of such steps to understand the usage context.
*
- * @param pick the token that would trigger this option which may be a {@link Pick},
- * a {@link Traversal}, {@link Predicate}, or object depending on the step being modulated.
+ * @param token the token that would trigger this option which may be a {@link Pick}, {@link Merge},
+ * a {@link Traversal}, {@link Predicate}, or object depending on the step being modulated.
* @param traversalOption the option as a traversal
* @return the traversal with the modulated step
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#choose-step" target="_blank">Reference Documentation - Choose Step</a>
+ * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergev-step" target="_blank">Reference Documentation - MergeV Step</a>
+ * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergee-step" target="_blank">Reference Documentation - MergeE Step</a>
* @since 3.0.0-incubating
*/
- public default <M, E2> GraphTraversal<S, E> option(final M pick, final Traversal<?, E2> traversalOption) {
- this.asAdmin().getBytecode().addStep(Symbols.option, pick, traversalOption);
- ((TraversalOptionParent<M, E, E2>) this.asAdmin().getEndStep()).addChildOption(pick, (Traversal.Admin<E, E2>) traversalOption.asAdmin());
+ public default <M, E2> GraphTraversal<S, E> option(final M token, final Traversal<?, E2> traversalOption) {
+ this.asAdmin().getBytecode().addStep(Symbols.option, token, traversalOption);
+ ((TraversalOptionParent<M, E, E2>) this.asAdmin().getEndStep()).addChildOption(token, (Traversal.Admin<E, E2>) traversalOption.asAdmin());
return this;
}
/**
- * This step modifies {@link #choose(Function)} to specifies the available choices that might be executed.
+ * This is a step modulator to a {@link TraversalOptionParent} like {@code choose()} or {@code mergeV()} where the
+ * provided argument associated to the {@code token} is applied according to the semantics of the step. Please see
+ * the documentation of such steps to understand the usage context.
*
- * @param traversalOption the option as a traversal
- * @return the traversal with the modulated step
- * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#choose-step" target="_blank">Reference Documentation - Choose Step</a>
- * @since 3.0.0-incubating
- */
- public default <E2> GraphTraversal<S, E> option(final Traversal<?, E2> traversalOption) {
- this.asAdmin().getBytecode().addStep(Symbols.option, traversalOption);
- ((TraversalOptionParent<Object, E, E2>) this.asAdmin().getEndStep()).addChildOption(Pick.any, (Traversal.Admin<E, E2>) traversalOption.asAdmin());
- return this;
- }
-
- /**
- * This step modifies merge related steps to specify the available choices that might be executed on the available
- * {@link Merge} options.
- *
- * @param traversal the option as a traversal
+ * @param m Provides a {@code Map} as the option which is the same as doing {@code constant(m)}.
* @return the traversal with the modulated step
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergev-step" target="_blank">Reference Documentation - MergeV Step</a>
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergee-step" target="_blank">Reference Documentation - MergeE Step</a>
* @since 3.6.0
*/
- public default <E2> GraphTraversal<S, E> option(final Merge merge, final Traversal<?, E2> traversal) {
- this.asAdmin().getBytecode().addStep(Symbols.option, merge, traversal);
- ((TraversalOptionParent<Merge, E, E2>) this.asAdmin().getEndStep()).addChildOption(merge, (Traversal.Admin<E, E2>) traversal.asAdmin());
+ public default <M, E2> GraphTraversal<S, E> option(final M token, final Map<Object, Object> m) {
+ this.asAdmin().getBytecode().addStep(Symbols.option, token, m);
+ ((TraversalOptionParent<M, E, E2>) this.asAdmin().getEndStep()).addChildOption(token, (Traversal.Admin<E, E2>) new ConstantTraversal<>(m).asAdmin());
return this;
}
/**
- * This step modifies merge related steps to specify the available choices that might be executed on the available
- * {@link Merge} options.
+ * This step modifies {@link #choose(Function)} to specifies the available choices that might be executed.
*
- * @param m
+ * @param traversalOption the option as a traversal
* @return the traversal with the modulated step
- * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergev-step" target="_blank">Reference Documentation - MergeV Step</a>
- * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergee-step" target="_blank">Reference Documentation - MergeE Step</a>
- * @since 3.6.0
+ * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#choose-step" target="_blank">Reference Documentation - Choose Step</a>
+ * @since 3.0.0-incubating
*/
- public default <E2> GraphTraversal<S, E> option(final Merge merge, final Map<Object, Object> m) {
- this.asAdmin().getBytecode().addStep(Symbols.option, merge, m);
- ((TraversalOptionParent<Merge, E, E2>) this.asAdmin().getEndStep()).addChildOption(merge, (Traversal.Admin<E, E2>) new ConstantTraversal<>(m).asAdmin());
+ public default <E2> GraphTraversal<S, E> option(final Traversal<?, E2> traversalOption) {
+ this.asAdmin().getBytecode().addStep(Symbols.option, traversalOption);
+ ((TraversalOptionParent<Object, E, E2>) this.asAdmin().getEndStep()).addChildOption(Pick.any, (Traversal.Admin<E, E2>) traversalOption.asAdmin());
return this;
}