本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep类的典型用法代码示例。如果您正苦于以下问题:Java MatchStep类的具体用法?Java MatchStep怎么用?Java MatchStep使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MatchStep类属于org.apache.tinkerpop.gremlin.process.traversal.step.map包,在下文中一共展示了MatchStep类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineStartLabelForHasPullOut
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
private String determineStartLabelForHasPullOut(final MatchStep<?, ?> matchStep) {
if (!(matchStep.getTraversal().getParent() instanceof EmptyStep))
return null;
else {
final String startLabel = MatchStep.Helper.computeStartLabel(matchStep.getGlobalChildren());
Step<?, ?> previousStep = matchStep.getPreviousStep();
if (previousStep.getLabels().contains(startLabel))
return startLabel;
while (!(previousStep instanceof EmptyStep)) {
if (!previousStep.getLabels().isEmpty())
return null;
previousStep = previousStep.getPreviousStep();
}
return startLabel;
}
}
示例2: getReferencedLabels
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
public static Set<String> getReferencedLabels(final Step step) {
final Set<String> referencedLabels = new HashSet<>();
if (step instanceof Scoping) {
final Set<String> labels = new HashSet<>(((Scoping) step).getScopeKeys());
if (step instanceof MatchStep) {
// if this is the last step, keep everything, else just add founds
if (step.getNextStep() instanceof EmptyStep) {
labels.addAll(((MatchStep) step).getMatchEndLabels());
labels.addAll(((MatchStep) step).getMatchStartLabels());
}
}
referencedLabels.addAll(labels);
}
return referencedLabels;
}
示例3: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
boolean changed = true; // recursively walk child traversals trying to inline them into the current traversal line.
while (changed) {
changed = false;
final Iterator<FilterStep> filterStepIterator = TraversalHelper.getStepsOfAssignableClass(FilterStep.class, traversal).iterator();
while (!changed && filterStepIterator.hasNext()) {
final FilterStep<?> step = filterStepIterator.next();
changed = step instanceof HasStep && InlineFilterStrategy.processHasStep((HasStep) step, traversal) ||
step instanceof TraversalFilterStep && InlineFilterStrategy.processTraversalFilterStep((TraversalFilterStep) step, traversal) ||
step instanceof OrStep && InlineFilterStrategy.processOrStep((OrStep) step, traversal) ||
step instanceof AndStep && InlineFilterStrategy.processAndStep((AndStep) step, traversal);
}
if (!changed && traversal.getParent() instanceof EmptyStep) {
final Iterator<MatchStep> matchStepIterator = TraversalHelper.getStepsOfClass(MatchStep.class, traversal).iterator();
while (!changed && matchStepIterator.hasNext()) {
if (InlineFilterStrategy.processMatchStep(matchStepIterator.next(), traversal))
changed = true;
}
}
}
}
示例4: getVariableLocations
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
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;
}
示例5: getReferencedLabels
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
public static Set<String> getReferencedLabels(final Step step) {
final Set<String> referencedLabels = new HashSet<>();
if (step instanceof Parameterizing) { // TODO: we should really make the mutation steps Scoping :|
final Parameters parameters = ((Parameterizing) step).getParameters();
for (final Traversal.Admin trav : parameters.getTraversals()) {
for (final Object ss : trav.getSteps()) {
if (ss instanceof Scoping) {
for (String label : ((Scoping) ss).getScopeKeys()) {
referencedLabels.add(label);
}
}
}
}
}
if (step instanceof Scoping) {
final Set<String> labels = new HashSet<>(((Scoping) step).getScopeKeys());
if (step instanceof MatchStep) {
// if this is the last step, keep everything, else just add founds
if (step.getNextStep() instanceof EmptyStep) {
labels.addAll(((MatchStep) step).getMatchEndLabels());
labels.addAll(((MatchStep) step).getMatchStartLabels());
}
}
referencedLabels.addAll(labels);
}
return referencedLabels;
}
示例6: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
for (final Step<?, ?> step : traversal.getSteps()) {
if (step instanceof MatchStep) {
((MatchStep) step).setMatchAlgorithm(this.matchAlgorithmClass);
}
}
}
示例7: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.hasStepOfClass(MatchStep.class, traversal) || TraversalHelper.hasStepOfClass(MatchStep.MatchStartStep.class, traversal))
return;
TraversalHelper.getStepsOfClass(WhereTraversalStep.class, traversal).forEach(whereTraversalStep -> {
Traversal.Admin innerWhereTraversal = ((Traversal) whereTraversalStep.getLocalChildren().get(0)).asAdmin();
TraversalHelper.getStepsOfClass(WhereTraversalStep.WhereStartStep.class, innerWhereTraversal).forEach(whereStartStep -> {
Iterator<String> iterator = whereStartStep.getScopeKeys().iterator();
String selectKey = null;
if (iterator.hasNext())
selectKey = iterator.next();
UniGraphWhereTraversalStep.UniGraphWhereStartStep uniGraphWhereStartStep =
new UniGraphWhereTraversalStep.UniGraphWhereStartStep(innerWhereTraversal,
selectKey);
TraversalHelper.replaceStep(whereStartStep, uniGraphWhereStartStep, innerWhereTraversal);
});
TraversalHelper.getStepsOfClass(WhereTraversalStep.WhereEndStep.class, innerWhereTraversal).forEach(whereEndStep -> {
UniGraphWhereTraversalStep.UniGraphWhereEndStep uniGraphWhereEndStep =
new UniGraphWhereTraversalStep.UniGraphWhereEndStep(innerWhereTraversal,
whereEndStep.getScopeKeys().iterator().next().toString());
TraversalHelper.replaceStep(whereEndStep, uniGraphWhereEndStep, innerWhereTraversal);
});
UniGraphWhereTraversalStep uniGraphWhereTraversalStep = new UniGraphWhereTraversalStep(traversal, innerWhereTraversal);
TraversalHelper.replaceStep(whereTraversalStep, uniGraphWhereTraversalStep, traversal);
});
}
示例8: getVariableLocations
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
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) {
for (final Traversal.Admin<?, ?> global : ((MatchStep<?, ?>) startStep).getGlobalChildren()) {
TraversalHelper.getVariableLocations(variables, global);
}
} else if (startStep instanceof ConnectiveStep || startStep instanceof NotStep || startStep instanceof WhereTraversalStep) {
for (final Traversal.Admin<?, ?> local : ((TraversalParent) startStep).getLocalChildren()) {
TraversalHelper.getVariableLocations(variables, local);
}
}
///
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;
}
示例9: doStrategy
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
private boolean doStrategy(final Step step) {
if (!(step instanceof CountGlobalStep) ||
!(step.getNextStep() instanceof IsStep) ||
step.getPreviousStep() instanceof RangeGlobalStep) // if a RangeStep was provided, assume that the user knows what he's doing
return false;
final Step parent = step.getTraversal().getParent().asStep();
return (parent instanceof FilterStep || parent.getLabels().isEmpty()) && // if the parent is labeled, then the count matters
!(parent.getNextStep() instanceof MatchStep.MatchEndStep && // if this is in a pattern match, then don't do it.
((MatchStep.MatchEndStep) parent.getNextStep()).getMatchKey().isPresent());
}
示例10: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (!TraversalHelper.hasStepOfClass(MatchStep.class, traversal))
return;
TraversalHelper.getStepsOfClass(MatchStep.class, traversal).forEach(matchStep -> {
// match().select().where() --> match(where()).select()
// match().select().dedup() --> match(dedup()).select()
Step<?, ?> nextStep = matchStep.getNextStep();
while (nextStep instanceof WherePredicateStep ||
nextStep instanceof WhereTraversalStep ||
(nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty()) ||
(nextStep instanceof SelectStep && ((SelectStep) nextStep).getLocalChildren().isEmpty()) ||
(nextStep instanceof SelectOneStep && ((SelectOneStep) nextStep).getLocalChildren().isEmpty())) {
if (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep) {
traversal.removeStep(nextStep);
matchStep.addGlobalChild(traversal instanceof GraphTraversal ?
new DefaultGraphTraversal<>().addStep(nextStep) :
new DefaultTraversal<>().addStep(nextStep));
nextStep = matchStep.getNextStep();
} else if (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty() && !TraversalHelper.onGraphComputer(traversal)) {
traversal.removeStep(nextStep);
matchStep.setDedupLabels(((DedupGlobalStep<?>) nextStep).getScopeKeys());
nextStep = matchStep.getNextStep();
} else if (nextStep.getLabels().isEmpty()) {
nextStep = nextStep.getNextStep();
} else
break;
}
});
}
示例11: processMatchStep
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
private static final boolean processMatchStep(final MatchStep<?, ?> step, final Traversal.Admin<?, ?> traversal) {
if (step.getPreviousStep() instanceof EmptyStep)
return false;
boolean changed = false;
final String startLabel = MatchStep.Helper.computeStartLabel(step.getGlobalChildren());
for (final Traversal.Admin<?, ?> matchTraversal : new ArrayList<>(step.getGlobalChildren())) {
if (TraversalHelper.hasAllStepsOfClass(matchTraversal,
HasStep.class,
MatchStep.MatchStartStep.class,
MatchStep.MatchEndStep.class) &&
matchTraversal.getStartStep() instanceof MatchStep.MatchStartStep &&
startLabel.equals(((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().orElse(null))) {
changed = true;
step.removeGlobalChild(matchTraversal);
final String endLabel = ((MatchStep.MatchEndStep) matchTraversal.getEndStep()).getMatchKey().orElse(null); // why would this exist? but just in case
matchTraversal.removeStep(0); // remove MatchStartStep
matchTraversal.removeStep(matchTraversal.getSteps().size() - 1); // remove MatchEndStep
TraversalHelper.applySingleLevelStrategies(traversal, matchTraversal, InlineFilterStrategy.class);
matchTraversal.getEndStep().addLabel(startLabel);
if (null != endLabel) matchTraversal.getEndStep().addLabel(endLabel);
TraversalHelper.insertTraversal((Step) step.getPreviousStep(), matchTraversal, traversal);
}
}
if (step.getGlobalChildren().isEmpty())
traversal.removeStep(step);
return changed;
}
示例12: isLocalStarGraph
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
private static char isLocalStarGraph(final Traversal.Admin<?, ?> traversal, char state) {
if (state == 'u' &&
(traversal instanceof ElementValueTraversal ||
(traversal instanceof TokenTraversal && !((TokenTraversal) traversal).getToken().equals(T.id))))
return 'x';
for (final Step step : traversal.getSteps()) {
if ((step instanceof PropertiesStep || step instanceof LabelStep || step instanceof PropertyMapStep) && state == 'u')
return 'x';
else if (step instanceof VertexStep) {
if (state == 'u') return 'x';
state = ((VertexStep) step).returnsVertex() ? 'u' : 'e';
} else if (step instanceof EdgeVertexStep) {
state = 'u';
} else if (step instanceof HasContainerHolder && state == 'u') {
if (((HasContainerHolder) step).getHasContainers().stream()
.filter(c -> !c.getKey().equals(T.id.getAccessor()))
.findAny().isPresent()) return 'x';
} else if (step instanceof TraversalParent) {
final char currState = state;
Set<Character> states = ((TraversalParent) step).getLocalChildren().stream()
.map(t -> isLocalStarGraph(t.asAdmin(), currState))
.collect(Collectors.toSet());
if (states.contains('x'))
return 'x';
else if (!(step instanceof ByModulating)) {
if (states.contains('u'))
state = 'u';
else if (states.contains('e'))
state = 'e';
}
states = ((TraversalParent) step).getGlobalChildren().stream()
.map(t -> isLocalStarGraph(t.asAdmin(), currState))
.collect(Collectors.toSet());
if (states.contains('x'))
return 'x';
else if (states.contains('u'))
state = 'u';
else if (states.contains('e'))
state = 'e';
if (state != currState && (step instanceof RepeatStep || step instanceof MatchStep))
return 'x';
}
}
return state;
}
示例13: MatchAlgorithmStrategy
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
private MatchAlgorithmStrategy(final Class<? extends MatchStep.MatchAlgorithm> matchAlgorithmClass) {
this.matchAlgorithmClass = matchAlgorithmClass;
}
示例14: algorithm
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
public Builder algorithm(final Class<? extends MatchStep.MatchAlgorithm> matchAlgorithmClass) {
this.matchAlgorithmClass = matchAlgorithmClass;
return this;
}
示例15: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (!TraversalHelper.hasStepOfClass(MatchStep.class, traversal))
return;
TraversalHelper.getStepsOfClass(MatchStep.class, traversal).forEach(matchStep -> {
// match().select().where() --> match(where()).select()
// match().select().dedup() --> match(dedup()).select()
Step<?, ?> nextStep = matchStep.getNextStep();
while (nextStep instanceof WherePredicateStep ||
nextStep instanceof WhereTraversalStep ||
(nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty()) ||
(nextStep instanceof SelectStep && ((SelectStep) nextStep).getLocalChildren().isEmpty()) ||
(nextStep instanceof SelectOneStep && ((SelectOneStep) nextStep).getLocalChildren().isEmpty())) {
if (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep) {
traversal.removeStep(nextStep);
matchStep.addGlobalChild(new DefaultTraversal<>().addStep(nextStep));
nextStep = matchStep.getNextStep();
} else if (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty() && !TraversalHelper.onGraphComputer(traversal)) {
traversal.removeStep(nextStep);
matchStep.setDedupLabels(((DedupGlobalStep<?>) nextStep).getScopeKeys());
nextStep = matchStep.getNextStep();
} else if (nextStep.getLabels().isEmpty()) {
nextStep = nextStep.getNextStep();
} else
break;
}
// match(as('a').has(key,value),...) --> as('a').has(key,value).match(...)
final String startLabel = this.determineStartLabelForHasPullOut(matchStep);
if (null != startLabel) {
((MatchStep<?, ?>) matchStep).getGlobalChildren().stream().collect(Collectors.toList()).forEach(matchTraversal -> {
if (matchTraversal.getStartStep() instanceof MatchStep.MatchStartStep &&
((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().isPresent() &&
((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().get().equals(startLabel) &&
!(matchStep.getPreviousStep() instanceof EmptyStep) &&
!matchTraversal.getSteps().stream()
.filter(step -> !(step instanceof MatchStep.MatchStartStep) &&
!(step instanceof MatchStep.MatchEndStep) &&
!(step instanceof HasStep))
.findAny()
.isPresent()) {
matchStep.removeGlobalChild(matchTraversal);
matchTraversal.removeStep(0); // remove MatchStartStep
matchTraversal.removeStep(matchTraversal.getSteps().size() - 1); // remove MatchEndStep
matchStep.getPreviousStep().addLabel(startLabel);
TraversalHelper.insertTraversal(matchStep.getPreviousStep(), matchTraversal, traversal);
}
});
}
});
}