当前位置: 首页>>代码示例>>Java>>正文


Java TraversalHelper类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper的典型用法代码示例。如果您正苦于以下问题:Java TraversalHelper类的具体用法?Java TraversalHelper怎么用?Java TraversalHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TraversalHelper类属于org.apache.tinkerpop.gremlin.process.traversal.util包,在下文中一共展示了TraversalHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal);
        Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer))
                        tinkerGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:23,代码来源:TinkerGraphStepStrategy.java

示例2: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal))
        return;
    final List<Step> steps = traversal.getSteps();
    if (steps.size() < 2 ||
            !(steps.get(0) instanceof GraphStep) ||
            0 != ((GraphStep) steps.get(0)).getIds().length ||
            !(steps.get(steps.size() - 1) instanceof CountGlobalStep))
        return;
    for (int i = 1; i < steps.size() - 1; i++) {
        final Step current = steps.get(i);
        if (!(current instanceof MapStep ||
                current instanceof IdentityStep ||
                current instanceof NoOpBarrierStep ||
                current instanceof CollectingBarrierStep) ||
                (current instanceof TraversalParent &&
                        TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current)))
            return;
    }
    final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass();
    TraversalHelper.removeAllSteps(traversal);
    traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraphCountStrategy.java

示例3: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
	for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
		final BitsyGraphStep<?, ?> bitsyGraphStep = new BitsyGraphStep<>(originalGraphStep);
		TraversalHelper.replaceStep(originalGraphStep, bitsyGraphStep, traversal);
		Step<?, ?> currentStep = bitsyGraphStep.getNextStep();
		while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
			if (currentStep instanceof HasStep) {
				for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
					if (!GraphStep.processHasContainerIds(bitsyGraphStep, hasContainer))
						bitsyGraphStep.addHasContainer(hasContainer);
				}
				TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
				traversal.removeStep(currentStep);
			}
			currentStep = currentStep.getNextStep();
		}
	}
}
 
开发者ID:lambdazen,项目名称:bitsy,代码行数:20,代码来源:BitsyTraversalStrategy.java

示例4: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final VertexStep originalVertexStep : TraversalHelper.getStepsOfClass(VertexStep.class, traversal)) {
        final HBaseVertexStep<?> hbaseVertexStep = new HBaseVertexStep<>(originalVertexStep);
        TraversalHelper.replaceStep(originalVertexStep, hbaseVertexStep, traversal);
        Step<?, ?> currentStep = hbaseVertexStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    hbaseVertexStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
开发者ID:rayokota,项目名称:hgraphdb,代码行数:20,代码来源:HBaseVertexStepStrategy.java

示例5: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final HBaseGraphStep<?, ?> hbaseGraphStep = new HBaseGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, hbaseGraphStep, traversal);
        Step<?, ?> currentStep = hbaseGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(hbaseGraphStep, hasContainer))
                        hbaseGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
开发者ID:rayokota,项目名称:hgraphdb,代码行数:21,代码来源:HBaseGraphStepStrategy.java

示例6: supply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
protected E supply() {
    if (null == this.sideEffectCapableSteps) {
        this.sideEffectCapableSteps = new HashMap<>();
        Traversal.Admin<?, ?> parentTraversal = this.getTraversal();
        while (!(parentTraversal instanceof EmptyTraversal)) {
            for (final SideEffectCapable<Object, E> capableStep : TraversalHelper.getStepsOfAssignableClassRecursively(SideEffectCapable.class, parentTraversal)) {
                if (this.sideEffectKeys.contains(capableStep.getSideEffectKey()) && !this.sideEffectCapableSteps.containsKey(capableStep.getSideEffectKey()))
                    this.sideEffectCapableSteps.put(capableStep.getSideEffectKey(), capableStep);
            }
            if (this.sideEffectKeys.size() == this.sideEffectCapableSteps.size())
                break;
            parentTraversal = parentTraversal.getParent().asStep().getTraversal();
        }
    }
    ////////////
    if (this.sideEffectKeys.size() == 1) {
        final String sideEffectKey = this.sideEffectKeys.get(0);
        final E result = this.getTraversal().getSideEffects().<E>get(sideEffectKey);
        final SideEffectCapable<Object, E> sideEffectCapable = this.sideEffectCapableSteps.get(sideEffectKey);
        final E finalResult = null == sideEffectCapable ? result : sideEffectCapable.generateFinalResult(result);
        this.getTraversal().getSideEffects().set(sideEffectKey, finalResult);
        return finalResult;
    } else
        return (E) this.getMapOfSideEffects();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:27,代码来源:SideEffectCapStep.java

示例7: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES, TraversalHelper.getRootTraversal(traversal)))
        return;
    final Collection<Pair<VertexStep, Step>> stepsToReplace = new ArrayList<>();
    Step prev = null;
    for (final Step curr : traversal.getSteps()) {
        if (isOptimizable(prev, curr)) {
            stepsToReplace.add(Pair.with((VertexStep) prev, curr));
        }
        prev = curr;
    }
    if (!stepsToReplace.isEmpty()) {
        for (final Pair<VertexStep, Step> pair : stepsToReplace) {
            optimizeSteps(traversal, pair.getValue0(), pair.getValue1());
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:IncidentToAdjacentStrategy.java

示例8: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!traversal.getStrategies().toList().contains(ComputerVerificationStrategy.instance())) {
        if (!TraversalHelper.getStepsOfAssignableClass(VertexComputing.class, traversal).isEmpty())
            throw new VerificationException("VertexComputing steps must be executed with a GraphComputer: " + TraversalHelper.getStepsOfAssignableClass(VertexComputing.class, traversal), traversal);
    }

    traversal.getSteps().forEach(step -> {
        if (step instanceof ReducingBarrierStep && step.getTraversal().getParent() instanceof RepeatStep && step.getTraversal().getParent().getGlobalChildren().get(0).getSteps().contains(step))
            throw new VerificationException("The parent of a reducing barrier can not be repeat()-step: " + step, traversal);
    });

    // The ProfileSideEffectStep must be the last step or the 2nd last step when accompanied by the cap step.
    if (TraversalHelper.hasStepOfClass(ProfileSideEffectStep.class, traversal) &&
            !(traversal.asAdmin().getEndStep() instanceof ProfileSideEffectStep) &&
            !(traversal.asAdmin().getEndStep() instanceof SideEffectCapStep && traversal.asAdmin().getEndStep().getPreviousStep() instanceof ProfileSideEffectStep)) {
        throw new VerificationException("When specified, the profile()-Step must be the last step or followed only by the cap()-step.", traversal);
    }

    if (TraversalHelper.getStepsOfClass(ProfileSideEffectStep.class, traversal).size() > 1) {
        throw new VerificationException("The profile()-Step cannot be specified multiple times.", traversal);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:24,代码来源:StandardVerificationStrategy.java

示例9: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.getStepsOfAssignableClass(VertexProgramStep.class, traversal).size() > 1)  // do not do if there is an OLAP chain
        return;
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // given that this strategy only works for single OLAP jobs, the graph is the traversal graph
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {   // will be zero or one step
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        final Computer computer = step.getComputer();
        if (null == computer.getEdges() && !GraphComputer.Persist.EDGES.equals(computer.getPersist())) {  // if edges() already set, use it
            final Traversal.Admin<Vertex, Edge> edgeFilter = getEdgeFilter(computerTraversal);
            if (null != edgeFilter)  // if no edges can be filtered, then don't set edges()
                step.setComputer(computer.edges(edgeFilter));
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GraphFilterStrategy.java

示例10: shouldIdentifyLocalChildren

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Test
public void shouldIdentifyLocalChildren() {
    final Traversal.Admin<?, ?> localChild = __.as("x").select("a", "b").by("name").asAdmin();
    new LocalStep<>(new DefaultTraversal(), localChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
    ///
    new WhereTraversalStep<>(new DefaultTraversal(), localChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
    ///
    new TraversalFilterStep<>(new DefaultTraversal(), localChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
    ///
    new TraversalMapStep<>(new DefaultTraversal(), localChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
    ///
    new TraversalFlatMapStep<>(new DefaultTraversal(), localChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
    ///
    final Traversal.Admin<?, ?> remoteLocalChild = __.repeat(localChild).asAdmin();
    new LocalStep<>(new DefaultTraversal<>(), remoteLocalChild);
    assertFalse(TraversalHelper.isGlobalChild(localChild));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:TraversalHelperTest.java

示例11: shouldIdentifyGlobalChildren

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Test
public void shouldIdentifyGlobalChildren() {
    final Traversal.Admin<?, ?> globalChild = __.select("a", "b").by("name").asAdmin();
    TraversalParent parent = new RepeatStep<>(new DefaultTraversal());
    ((RepeatStep) parent).setRepeatTraversal(globalChild);
    assertTrue(TraversalHelper.isGlobalChild(globalChild));
    ///
    new UnionStep<>(new DefaultTraversal(), globalChild);
    assertTrue(TraversalHelper.isGlobalChild(globalChild));
    ///
    new TraversalVertexProgramStep(new DefaultTraversal<>(), globalChild);
    assertTrue(TraversalHelper.isGlobalChild(globalChild));
    ///
    final Traversal.Admin<?, ?> remoteRemoteChild = __.repeat(globalChild).asAdmin();
    new UnionStep<>(new DefaultTraversal(), remoteRemoteChild);
    assertTrue(TraversalHelper.isGlobalChild(globalChild));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:TraversalHelperTest.java

示例12: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(originalGraphStep -> {
        final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, (Step) tinkerGraphStep, traversal);
        Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
        while (currentStep instanceof HasContainerHolder) {
            ((HasContainerHolder) currentStep).getHasContainers().forEach(hasContainer -> {
                if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer))
                    tinkerGraphStep.addHasContainer(hasContainer);
            });
            currentStep.getLabels().forEach(tinkerGraphStep::addLabel);
            traversal.removeStep(currentStep);
            currentStep = currentStep.getNextStep();
        }
    });
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:TinkerGraphStepStrategy.java

示例13: isLegal

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
public static boolean isLegal(final Traversal.Admin<?, ?> traversal) {
    final Step<?, ?> startStep = traversal.getStartStep();
    final Step<?, ?> endStep = traversal.getEndStep();
    if (!startStep.getClass().equals(GraphStep.class) || ((GraphStep) startStep).returnsEdge())
        return false;
    if (!endStep.getClass().equals(CountGlobalStep.class) &&
            !endStep.getClass().equals(SumGlobalStep.class) &&
            !endStep.getClass().equals(MeanGlobalStep.class) &&
            !endStep.getClass().equals(MaxGlobalStep.class) &&
            !endStep.getClass().equals(MinGlobalStep.class) &&
            !endStep.getClass().equals(FoldStep.class) &&
            !endStep.getClass().equals(GroupStep.class) &&
            !endStep.getClass().equals(GroupCountStep.class))
        // TODO: tree()
        return false;
    if (TraversalHelper.getStepsOfAssignableClassRecursively(Scope.global, Barrier.class, traversal).size() != 1)
        return false;
    if (traversal.getTraverserRequirements().contains(TraverserRequirement.SACK))
        return false;
    return TraversalHelper.isLocalStarGraph(traversal);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:22,代码来源:SparkStarBarrierInterceptor.java

示例14: apply

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // best guess at what the graph will be as its dynamically determined
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        boolean doesMessagePass = TraversalHelper.hasStepOfAssignableClassRecursively(Scope.global, MULTI_ITERATION_CLASSES, computerTraversal);
        if (!doesMessagePass) {
            for (final VertexStep vertexStep : TraversalHelper.getStepsOfAssignableClassRecursively(Scope.global, VertexStep.class, computerTraversal)) {
                if (vertexStep.returnsVertex() || !vertexStep.getDirection().equals(Direction.OUT)) { // in-edges require message pass in OLAP
                    doesMessagePass = true;
                    break;
                }
            }
        }
        if (!doesMessagePass) {
            step.setComputer(step.getComputer()
                    // if no message passing, don't partition the loaded graph
                    .configure(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, true)
                            // if no message passing, don't cache the loaded graph
                    .configure(Constants.GREMLIN_SPARK_SKIP_GRAPH_CACHE, true));
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:SparkSingleIterationStrategy.java

示例15: test

import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入依赖的package包/类
private static <R> void test(Class<? extends VertexProgramInterceptor> expectedInterceptor, R expectedResult, final Traversal<?, R> traversal) throws Exception {
    final Traversal.Admin<?, ?> clone = traversal.asAdmin().clone();
    clone.applyStrategies();
    final Map<String, Object> configuration = TraversalHelper.getFirstStepOfAssignableClass(TraversalVertexProgramStep.class, clone).get().getComputer().getConfiguration();
    final String interceptor = (String) configuration.getOrDefault(Constants.GREMLIN_HADOOP_VERTEX_PROGRAM_INTERCEPTOR, null);
    if (null == expectedInterceptor) {
        assertNull(interceptor);
        assertFalse((Boolean) configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, false));
        assertFalse((Boolean) configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, false));
    } else {
        assertEquals(expectedInterceptor, Class.forName(interceptor));
        if (interceptor.equals(SparkStarBarrierInterceptor.class.getCanonicalName())) {
            assertTrue((Boolean) configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, false));
            assertTrue((Boolean) configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, false));
        }
    }
    assertEquals(expectedResult, traversal.next());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:SparkInterceptorStrategyTest.java


注:本文中的org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。