Ejemplo n.º 1
0
 private static Set<String> getLabels(
     final Set<String> labels, final Traversal.Admin<?, ?> traversal) {
   for (final Step<?, ?> step : traversal.getSteps()) {
     labels.addAll(step.getLabels());
     if (step instanceof TraversalParent) {
       ((TraversalParent) step).getLocalChildren().forEach(child -> getLabels(labels, child));
       ((TraversalParent) step).getGlobalChildren().forEach(child -> getLabels(labels, child));
     }
   }
   return labels;
 }
Ejemplo n.º 2
0
 public static void reIdSteps(
     final StepPosition stepPosition, final Traversal.Admin<?, ?> traversal) {
   stepPosition.x = 0;
   stepPosition.y = -1;
   stepPosition.z = -1;
   stepPosition.parentId = null;
   Traversal.Admin<?, ?> current = traversal;
   while (!(current instanceof EmptyTraversal)) {
     stepPosition.y++;
     final TraversalParent parent = current.getParent();
     if (null == stepPosition.parentId && !(parent instanceof EmptyStep))
       stepPosition.parentId = parent.asStep().getId();
     if (-1 == stepPosition.z) {
       final int globalChildrenSize = parent.getGlobalChildren().size();
       for (int i = 0; i < globalChildrenSize; i++) {
         if (parent.getGlobalChildren().get(i) == current) {
           stepPosition.z = i;
         }
       }
       for (int i = 0; i < parent.getLocalChildren().size(); i++) {
         if (parent.getLocalChildren().get(i) == current) {
           stepPosition.z = i + globalChildrenSize;
         }
       }
     }
     current = parent.asStep().getTraversal();
   }
   if (-1 == stepPosition.z) stepPosition.z = 0;
   if (null == stepPosition.parentId) stepPosition.parentId = "";
   for (final Step<?, ?> step : traversal.getSteps()) {
     step.setId(stepPosition.nextXId());
   }
 }
Ejemplo n.º 3
0
 private static Set<Scoping.Variable> getVariableLocations(
     final Set<Scoping.Variable> variables, final Traversal.Admin<?, ?> traversal) {
   if (variables.size() == 2)
     return variables; // has both START and END so no need to compute further
   final Step<?, ?> startStep = traversal.getStartStep();
   if (StartStep.isVariableStartStep(startStep)) variables.add(Scoping.Variable.START);
   else if (startStep instanceof WherePredicateStep) {
     if (((WherePredicateStep) startStep).getStartKey().isPresent())
       variables.add(Scoping.Variable.START);
   } else if (startStep instanceof WhereTraversalStep.WhereStartStep) {
     if (!((WhereTraversalStep.WhereStartStep) startStep).getScopeKeys().isEmpty())
       variables.add(Scoping.Variable.START);
   } else if (startStep instanceof MatchStep.MatchStartStep) {
     if (((MatchStep.MatchStartStep) startStep).getSelectKey().isPresent())
       variables.add(Scoping.Variable.START);
   } else if (startStep instanceof MatchStep) {
     ((MatchStep<?, ?>) startStep)
         .getGlobalChildren()
         .forEach(child -> TraversalHelper.getVariableLocations(variables, child));
   } else if (startStep instanceof ConnectiveStep
       || startStep instanceof NotStep
       || startStep instanceof WhereTraversalStep)
     ((TraversalParent) startStep)
         .getLocalChildren()
         .forEach(child -> TraversalHelper.getVariableLocations(variables, child));
   ///
   final Step<?, ?> endStep = traversal.getEndStep();
   if (endStep instanceof WherePredicateStep) {
     if (((WherePredicateStep) endStep).getStartKey().isPresent())
       variables.add(Scoping.Variable.END);
   } else if (endStep instanceof WhereTraversalStep.WhereEndStep) {
     if (!((WhereTraversalStep.WhereEndStep) endStep).getScopeKeys().isEmpty())
       variables.add(Scoping.Variable.END);
   } else if (endStep instanceof MatchStep.MatchEndStep) {
     if (((MatchStep.MatchEndStep) endStep).getMatchKey().isPresent())
       variables.add(Scoping.Variable.END);
   } else if (!endStep.getLabels().isEmpty()) variables.add(Scoping.Variable.END);
   ///
   return variables;
 }