本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper.replaceStep方法的典型用法代码示例。如果您正苦于以下问题:Java TraversalHelper.replaceStep方法的具体用法?Java TraversalHelper.replaceStep怎么用?Java TraversalHelper.replaceStep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper
的用法示例。
在下文中一共展示了TraversalHelper.replaceStep方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
}
示例2: 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();
}
}
}
示例3: 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();
}
}
}
示例4: 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();
}
}
}
示例5: apply
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
final Step<?, ?> startStep = traversal.getStartStep();
// only apply once
if (startStep instanceof GraphStep && !(startStep instanceof OrientGraphStep)) {
final GraphStep<?, ?> originalGraphStep = (GraphStep) startStep;
final OrientGraphStep<?, ?> orientGraphStep = new OrientGraphStep<>(originalGraphStep);
TraversalHelper.replaceStep(startStep, (Step) orientGraphStep, traversal);
Step<?, ?> currentStep = orientGraphStep.getNextStep();
while (currentStep instanceof HasContainerHolder) {
((HasContainerHolder) currentStep).getHasContainers().forEach(orientGraphStep::addHasContainer);
currentStep.getLabels().forEach(orientGraphStep::addLabel);
traversal.removeStep(currentStep);
currentStep = currentStep.getNextStep();
}
}
}
示例6: 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 Neo4jGraphStep<?, ?> neo4jGraphStep = new Neo4jGraphStep<>(originalGraphStep);
TraversalHelper.replaceStep(originalGraphStep, neo4jGraphStep, traversal);
Step<?, ?> currentStep = neo4jGraphStep.getNextStep();
while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
if (currentStep instanceof HasStep) {
for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
if (!GraphStep.processHasContainerIds(neo4jGraphStep, hasContainer))
neo4jGraphStep.addHasContainer(hasContainer);
}
TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
traversal.removeStep(currentStep);
}
currentStep = currentStep.getNextStep();
}
}
}
示例7: executeStrategy
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
/**
* Replace the {@code graphStep} and {@code filterStep} with a new {@link JanusPreviousPropertyStep} in the given
* {@code traversal}.
*/
private void executeStrategy(
Traversal.Admin<?, ?> traversal, GraphStep<?, ?> graphStep, TraversalFilterStep<Vertex> filterStep,
String propertyKey, String label) {
JanusPreviousPropertyStep newStep = new JanusPreviousPropertyStep(traversal, propertyKey, label);
traversal.removeStep(filterStep);
TraversalHelper.replaceStep(graphStep, newStep, traversal);
}
示例8: optimizeSteps
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
/**
* Optimizes the given edge-emitting step and the vertex-emitting step by replacing them with a single
* vertex-emitting step.
*
* @param traversal the traversal that holds the given steps
* @param step1 the edge-emitting step to replace
* @param step2 the vertex-emitting step to replace
*/
private static void optimizeSteps(final Traversal.Admin traversal, final VertexStep step1, final Step step2) {
final Step newStep = new VertexStep(traversal, Vertex.class, step1.getDirection(), step1.getEdgeLabels());
for (final String label : (Iterable<String>) step2.getLabels()) {
newStep.addLabel(label);
}
TraversalHelper.replaceStep(step1, newStep, traversal);
traversal.removeStep(step2);
}
示例9: shouldReplaceStep
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
@Test
public void shouldReplaceStep() {
final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
final HasStep hasStep = new HasStep(traversal);
final IdentityStep identityStep = new IdentityStep(traversal);
traversal.asAdmin().addStep(0, new HasStep(traversal));
traversal.asAdmin().addStep(0, hasStep);
traversal.asAdmin().addStep(0, new HasStep(traversal));
TraversalHelper.replaceStep(hasStep, identityStep, traversal);
assertEquals(traversal.asAdmin().getSteps().get(1), identityStep);
assertEquals(3, traversal.asAdmin().getSteps().size());
}
示例10: apply
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (traversal.getEngine().isComputer())
return;
final Step<?, ?> startStep = traversal.getStartStep();
if (startStep instanceof GraphStep) {
final GraphStep<?> originalGraphStep = (GraphStep) startStep;
if (originalGraphStep.getIds() == null || originalGraphStep.getIds().length == 0) {
//Try to optimize for index calls
final TitanGraphStep<?> titanGraphStep = new TitanGraphStep<>(originalGraphStep);
TraversalHelper.replaceStep(startStep, (Step) titanGraphStep, traversal);
HasStepFolder.foldInHasContainer(titanGraphStep, traversal);
HasStepFolder.foldInOrder(titanGraphStep, traversal, traversal, titanGraphStep.returnsVertex());
HasStepFolder.foldInRange(titanGraphStep, traversal);
} else {
//Make sure that any provided "start" elements are instantiated in the current transaction
Object[] ids = originalGraphStep.getIds();
ElementUtils.verifyArgsMustBeEitherIdorElement(ids);
if (ids[0] instanceof Element) {
//GraphStep constructor ensures that the entire array is elements
final Object[] elementIds = new Object[ids.length];
for (int i = 0; i < ids.length; i++) {
elementIds[i] = ((Element) ids[i]).id();
}
originalGraphStep.setIteratorSupplier(() -> (Iterator) (originalGraphStep.returnsVertex() ?
originalGraphStep.getTraversal().getGraph().get().vertices(elementIds) :
originalGraphStep.getTraversal().getGraph().get().edges(elementIds)));
}
}
}
}
示例11: processOrStep
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
private static final boolean processOrStep(final OrStep<?> step, final Traversal.Admin<?, ?> traversal) {
boolean process = true;
String key = null;
P predicate = null;
final List<String> labels = new ArrayList<>();
for (final Traversal.Admin<?, ?> childTraversal : step.getLocalChildren()) {
InlineFilterStrategy.instance().apply(childTraversal); // todo: this may be a bad idea, but I can't seem to find a test case to break it
for (final Step<?, ?> childStep : childTraversal.getSteps()) {
if (childStep instanceof HasStep) {
for (final HasContainer hasContainer : ((HasStep<?>) childStep).getHasContainers()) {
if (null == key)
key = hasContainer.getKey();
else if (!hasContainer.getKey().equals(key)) {
process = false;
break;
}
predicate = null == predicate ?
hasContainer.getPredicate() :
predicate.or(hasContainer.getPredicate());
}
labels.addAll(childStep.getLabels());
} else {
process = false;
break;
}
}
if (!process)
break;
}
if (process) {
final HasStep hasStep = new HasStep<>(traversal, new HasContainer(key, predicate));
TraversalHelper.replaceStep(step, hasStep, traversal);
TraversalHelper.copyLabels(step, hasStep, false);
for (final String label : labels) {
hasStep.addLabel(label);
}
return true;
}
return false;
}
示例12: shouldSetPreviousStepToEmptyStep
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; //导入方法依赖的package包/类
@Test
public void shouldSetPreviousStepToEmptyStep() {
final Traversal.Admin<?, ?> traversal = __.V().out().asAdmin();
//transform the traversal to __.V().not(out())
//the VertexStep's previousStep should be the EmptyStep
Optional<VertexStep> vertexStepOpt = TraversalHelper.getFirstStepOfAssignableClass(VertexStep.class, traversal);
assertTrue(vertexStepOpt.isPresent());
Traversal.Admin<?,?> inner = __.start().asAdmin();
inner.addStep(0, vertexStepOpt.get());
TraversalHelper.replaceStep(vertexStepOpt.get(), new NotStep<>(__.identity().asAdmin(), inner), traversal);
List<VertexStep> vertexSteps = TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal);
assertEquals(1, vertexSteps.size());
VertexStep vertexStep = vertexSteps.get(0);
assertTrue("Expected the previousStep to be an EmptyStep, found instead " + vertexStep.getPreviousStep().toString(),vertexStep.getPreviousStep() == EmptyStep.instance());
}