Package com.tinkerpop.gremlin.process

Examples of com.tinkerpop.gremlin.process.Step


        boolean done = false;
        while (!done) {
            done = true;
            for (int i = 0; i < traversal.getSteps().size(); i++) {
                final Step step1 = traversal.getSteps().get(i);
                if (step1 instanceof DedupStep && !((DedupStep) step1).hasUniqueFunction()) {
                    for (int j = i; j >= 0; j--) {
                        final Step step2 = traversal.getSteps().get(j);
                        if (BIJECTIVE_PIPES.stream().filter(c -> c.isAssignableFrom(step2.getClass())).findAny().isPresent()) {
                            TraversalHelper.removeStep(step1, traversal);
                            TraversalHelper.insertStep(step1, j, traversal);
                            done = false;
                            break;
                        }
View Full Code Here


    @Override
    public void apply(final Traversal traversal, final TraversalEngine traversalEngine) {
        if (traversal.getSteps().get(0) instanceof Neo4jGraphStep) {
            final Neo4jGraphStep neo4jGraphStep = (Neo4jGraphStep) traversal.getSteps().get(0);
            Step currentStep = neo4jGraphStep.getNextStep();
            while (true) {
                if (currentStep == EmptyStep.instance() || TraversalHelper.isLabeled(currentStep)) break;

                if (currentStep instanceof HasStep) {
                    neo4jGraphStep.hasContainers.addAll(((HasStep) currentStep).getHasContainers());
                    TraversalHelper.removeStep(currentStep, traversal);
                } else if (currentStep instanceof IntervalStep) {
                    neo4jGraphStep.hasContainers.addAll(((IntervalStep) currentStep).getHasContainers());
                    TraversalHelper.removeStep(currentStep, traversal);
                } else if (currentStep instanceof IdentityStep) {
                    // do nothing
                } else {
                    break;
                }
                currentStep = currentStep.getNextStep();
            }
        }
    }
View Full Code Here

    @Override
    public void apply(final Traversal<?, ?> traversal, final TraversalEngine engine) {
        if (engine.equals(TraversalEngine.STANDARD))
            return;

        final Step endStep = TraversalHelper.getEnd(traversal);
        if (endStep instanceof Reducing) {
            TraversalHelper.insertAfterStep(new ReducingIdentity(traversal, ((Reducing) endStep).getReducer()), endStep, traversal);
            TraversalHelper.removeStep(endStep, traversal);
        }
    }
View Full Code Here

                .filter(JumpStep::unRollable)
                        // TODO: filter() when do unroll and when not to depending on the depth of looping?
                .forEach(toStep -> {
                    if (toStep.isDoWhile()) {
                        // DO WHILE SEMANTICS
                        final Step fromStep = TraversalHelper.getStep(toStep.getJumpLabel(), traversal);
                        final List<Step> stepsToClone = TraversalHelper.isolateSteps(fromStep, toStep);
                        stepsToClone.forEach(stepToClone -> TraversalHelper.removeStep(stepToClone, traversal));
                        for (int i = 0; i < (short) toStep.getJumpLoops().getValue0(); i++) {
                            for (int j = stepsToClone.size() - 1; j >= 0; j--) {
                                try {
                                    final Step clonedStep = stepsToClone.get(j).clone();
                                    TraversalHelper.insertStep(clonedStep, traversal.getSteps().indexOf(fromStep) + 1, traversal);
                                } catch (final CloneNotSupportedException e) {
                                    throw new IllegalStateException(e.getMessage(), e);
                                }
                            }
                        }
                        if (TraversalHelper.isLabeled(toStep))
                            toStep.getPreviousStep().setLabel(toStep.getLabel());
                        TraversalHelper.removeStep(toStep, traversal);
                    } else {
                        // WHILE DO SEMANTICS
                        final JumpStep fromStep = (JumpStep) TraversalHelper.getStep(toStep.getJumpLabel(), traversal);
                        final List<Step> stepsToClone = TraversalHelper.isolateSteps(toStep, fromStep);
                        stepsToClone.forEach(stepToClone -> TraversalHelper.removeStep(stepToClone, traversal));
                        for (int i = 0; i < ((short) toStep.getJumpLoops().getValue0() + 1); i++) {
                            for (int j = stepsToClone.size() - 1; j >= 0; j--) {
                                try {
                                    final Step clonedStep = stepsToClone.get(j).clone();
                                    TraversalHelper.insertStep(clonedStep, traversal.getSteps().indexOf(fromStep) + 1, traversal);
                                } catch (final CloneNotSupportedException e) {
                                    throw new IllegalStateException(e.getMessage(), e);
                                }
                            }
View Full Code Here

            final BranchStep<?> branchStep = new BranchStep<>(traversal);
            branchStep.setFunctions(branchFunctions.toArray(new Function[branchFunctions.size()]));
            TraversalHelper.replaceStep(unionStep, branchStep, traversal);

            Step currentStep = branchStep;
            for (int i = 0; i < unionStep.getTraversals().length; i++) {
                final String unionBranchStart = UNION + unionStepCounter + "." + i;
                int c = 0;
                for (final Step branchstep : unionStep.getTraversals()[i].getSteps()) {
                    TraversalHelper.insertAfterStep(branchstep, currentStep, traversal);
                    currentStep = branchstep;
                    if (c++ == 0) currentStep.setLabel(unionBranchStart);
                }
                final BranchStep breakStep = new BranchStep(traversal);
                breakStep.setFunctions(new BranchStep.GoToLabel(endLabel));
                TraversalHelper.insertAfterStep(breakStep, currentStep, traversal);
                currentStep = breakStep;
View Full Code Here

    }

    @Test
    public void shouldIsolateSteps() {
        Traversal traversal = new DefaultTraversal<>();
        Step step1 = new IdentityStep(traversal);
        Step step2 = new TimeLimitStep<>(traversal, 100);
        Step step3 = new RandomStep<>(traversal, 0.5);
        Step step4 = new PropertyMapStep(traversal, PropertyType.PROPERTY, "name");
        Step step5 = new ShuffleStep<>(traversal);
        traversal.addStep(step1);
        traversal.addStep(step2);
        traversal.addStep(step3);
        traversal.addStep(step4);
        traversal.addStep(step5);
View Full Code Here

        assertEquals(traversal.getSteps().size(), 3);
    }

    @Test
    public void shouldTruncateLongName() {
        Step s = Mockito.mock(Step.class);
        Mockito.when(s.toString()).thenReturn("0123456789");
        assertEquals("0123...", TraversalHelper.getShortName(s, 7));
    }
View Full Code Here

            return;

        final List<MatchStep> matchSteps = TraversalHelper.getStepsOfClass(MatchStep.class, traversal);
        for (final MatchStep matchStep : matchSteps) {
            boolean foundWhereWithNoTraversal = false;
            Step currentStep = matchStep.getNextStep();
            while (currentStep instanceof WhereStep || currentStep instanceof SelectStep || currentStep instanceof IdentityStep) {
                if (currentStep instanceof WhereStep) {
                    if (!((WhereStep) currentStep).hasBiPredicate()) {
                        matchStep.addTraversal(((WhereStep) currentStep).getConstraint());
                        TraversalHelper.removeStep(currentStep, traversal);
                    } else {
                        foundWhereWithNoTraversal = true;
                    }
                } else if (currentStep instanceof SelectStep) {
                    if (((SelectStep) currentStep).hasStepFunctions() || foundWhereWithNoTraversal)
                        break;
                // else is the identity step
                currentStep = currentStep.getNextStep();
            }
        }
    }
View Full Code Here

        if (startStep.startAssignableTo(Vertex.class, Edge.class)) {
            final GiraphElement element = ((StartStep<?>) startStep).getStart();
            final String label = TraversalHelper.getStart(traversal).getLabel();
            TraversalHelper.removeStep(TraversalHelper.getStart(traversal), traversal);
            if (TraversalHelper.isLabeled(label)) {
                final Step identityStep = new IdentityStep(traversal);
                identityStep.setLabel(label);
                TraversalHelper.insertStep(identityStep, 0, traversal);
            }
            TraversalHelper.insertStep(new HasStep(traversal, new HasContainer(T.id, Compare.eq, element.id())), 0, traversal);
            TraversalHelper.insertStep(new GiraphGraphStep<>(traversal, element.getClass(), (GiraphGraph) element.graph()), 0, traversal);
        }
View Full Code Here

                final String goTo = objectToString(currentStepCounter, chooseStep.getMapFunction().apply(traverser));
                return TraversalHelper.hasLabel(goTo, traversal) ? goTo : BranchStep.EMPTY_LABEL;
            });
            TraversalHelper.replaceStep(chooseStep, branchStep, traversal);

            Step currentStep = branchStep;
            for (final Map.Entry<?, Traversal<?, ?>> entry : (Set<Map.Entry>) chooseStep.getChoices().entrySet()) {
                int c = 0;
                for (final Step mapStep : entry.getValue().getSteps()) {
                    TraversalHelper.insertAfterStep(mapStep, currentStep, traversal);
                    currentStep = mapStep;
                    if (c++ == 0) currentStep.setLabel(objectToString(currentStepCounter, entry.getKey()));
                }
                final BranchStep breakStep = new BranchStep(traversal);
                breakStep.setFunctions(new BranchStep.GoToLabel(endLabel));
                TraversalHelper.insertAfterStep(breakStep, currentStep, traversal);
                currentStep = breakStep;
View Full Code Here

TOP

Related Classes of com.tinkerpop.gremlin.process.Step

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.