本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.Traverser类的典型用法代码示例。如果您正苦于以下问题:Java Traverser类的具体用法?Java Traverser怎么用?Java Traverser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Traverser类属于org.apache.tinkerpop.gremlin.process.traversal包,在下文中一共展示了Traverser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: projectTraverser
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
public JSONObject projectTraverser(final Traverser.Admin<Path> traverser) {
final JSONObject root = new JSONObject();
JSONObject currentNode = root;
for (final Object object : traverser.get()) {
if (object instanceof Map) {
for(final Map.Entry entry : (Set<Map.Entry>)((Map)object).entrySet()) {
if(entry.getKey().equals(T.id))
currentNode.put(T.id.getAccessor(),entry.getValue());
else if(entry.getKey().equals(T.label))
currentNode.put(T.label.getAccessor(),entry.getValue());
else
currentNode.put(entry.getKey(),entry.getValue());
}
}
else if (object instanceof String)
currentNode.put(object, currentNode = new JSONObject());
}
return root;
}
示例2: nextBarrier
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
public Map<Object, Traverser.Admin<S>> nextBarrier() throws NoSuchElementException {
final Map<Object, Traverser.Admin<S>> map = new HashMap<>();
while (this.starts.hasNext()) {
final Traverser.Admin<S> traverser = this.starts.next();
final Object object;
if (null != this.dedupLabels) {
object = new ArrayList<>(this.dedupLabels.size());
for (final String label : this.dedupLabels) {
((List) object).add(TraversalUtil.applyNullable((S) this.getScopeValue(Pop.last, label, traverser), this.dedupTraversal));
}
} else {
object = TraversalUtil.applyNullable(traverser, this.dedupTraversal);
}
if (!map.containsKey(object)) {
traverser.setBulk(1l);
traverser.set(DetachedFactory.detach(traverser.get(), true));
map.put(object, traverser);
}
}
if (map.isEmpty())
throw FastNoSuchElementException.instance();
else
return map;
}
示例3: standardAlgorithm
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected Iterator<Traverser.Admin<S>> standardAlgorithm() throws NoSuchElementException {
final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent();
while (true) {
final Traverser.Admin<S> start = this.starts.next();
start.incrLoops(this.getId());
if (repeatStep.doUntil(start, false)) {
start.resetLoops();
return IteratorUtils.of(start);
} else {
if (!repeatStep.untilFirst && !repeatStep.emitFirst)
repeatStep.repeatTraversal.addStart(start);
else
repeatStep.addStart(start);
if (repeatStep.doEmit(start, false)) {
final Traverser.Admin<S> emitSplit = start.split();
emitSplit.resetLoops();
return IteratorUtils.of(emitSplit);
}
}
}
}
示例4: processNextStart
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected Traverser.Admin<Object> processNextStart() throws NoSuchElementException {
if (null == this.parent)
this.parent = ((MatchStep) this.getTraversal().getParent().asStep());
while (true) {
final Traverser.Admin traverser = this.starts.next();
// no end label
if (null == this.matchKey) {
// if (this.traverserStepIdAndLabelsSetByChild) -- traverser equality is based on stepId, lets ensure they are all at the parent
traverser.setStepId(this.parent.getId());
this.parent.getMatchAlgorithm().recordEnd(traverser, this.getTraversal());
return this.retractUnnecessaryLabels(traverser);
}
// TODO: sideEffect check?
// path check
final Path path = traverser.path();
if (!path.hasLabel(this.matchKey) || traverser.get().equals(path.get(Pop.last, this.matchKey))) {
// if (this.traverserStepIdAndLabelsSetByChild) -- traverser equality is based on stepId and thus, lets ensure they are all at the parent
traverser.setStepId(this.parent.getId());
traverser.addLabels(this.matchKeyCollection);
this.parent.getMatchAlgorithm().recordEnd(traverser, this.getTraversal());
return this.retractUnnecessaryLabels(traverser);
}
}
}
示例5: apply
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
public Traversal.Admin<Object, Object> apply(final Traverser.Admin<Object> traverser) {
// optimization to favor processing StarGraph local objects first to limit message passing (GraphComputer only)
// TODO: generalize this for future MatchAlgorithms (given that 3.2.0 will focus on RealTimeStrategy, it will probably go there)
if (this.onComputer) {
final List<Set<String>> labels = traverser.path().labels();
final Set<String> lastLabels = labels.get(labels.size() - 1);
Collections.sort(this.bundles,
Comparator.<Bundle>comparingLong(b -> Helper.getStartLabels(b.traversal).stream().filter(startLabel -> !lastLabels.contains(startLabel)).count()).
thenComparingInt(b -> b.traversalType.ordinal()).
thenComparingDouble(b -> b.multiplicity));
}
Bundle startLabelsBundle = null;
for (final Bundle bundle : this.bundles) {
if (!Helper.hasExecutedTraversal(traverser, bundle.traversal) && Helper.hasStartLabels(traverser, bundle.traversal)) {
if (bundle.traversalType != TraversalType.MATCH_TRAVERSAL || Helper.hasEndLabel(traverser, bundle.traversal))
return bundle.traversal;
else if (null == startLabelsBundle)
startLabelsBundle = bundle;
}
}
if (null != startLabelsBundle) return startLabelsBundle.traversal;
throw UNMATCHABLE_PATTERN.apply(this.bundles.stream().map(record -> record.traversal).collect(Collectors.toList()));
}
示例6: handleStart
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
private final void handleStart(final Traverser.Admin<S> start) {
final M choice = TraversalUtil.apply(start, this.branchTraversal);
final List<Traversal.Admin<S, E>> branch = this.traversalOptions.containsKey(choice) ? this.traversalOptions.get(choice) : this.traversalOptions.get(Pick.none);
if (null != branch) {
branch.forEach(traversal -> {
traversal.addStart(start.split());
});
}
if (choice != Pick.any) {
final List<Traversal.Admin<S, E>> anyBranch = this.traversalOptions.get(Pick.any);
if (null != anyBranch)
anyBranch.forEach(traversal -> {
traversal.addStart(start.split());
});
}
}
示例7: data
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"filter(x->true)", __.filter(x -> true), false},
{"map(Traverser::get)", __.map(Traverser::get), false},
{"sideEffect(x -> {int i = 1+1;})", __.sideEffect(x -> {
int i = 1 + 1;
}), false},
{"select('a','b').by(Object::toString)", __.select("a", "b").by(Object::toString), false},
{"order().by((a,b)->a.compareTo(b))", __.order().by((a, b) -> ((Integer) a).compareTo((Integer) b)), false},
{"order(local).by((a,b)->a.compareTo(b))", __.order(Scope.local).by((a, b) -> ((Integer) a).compareTo((Integer) b)), false},
{"__.choose(v->v.toString().equals(\"marko\"),__.out(),__.in())", __.choose(v -> v.toString().equals("marko"), __.out(), __.in()), false},
{"order(local).by(values,decr)", __.order(Scope.local).by(Column.values, (a, b) -> ((Double) a).compareTo((Double) b)), false},
//
{"order(local).by(values,decr)", __.order(Scope.local).by(Column.values, Order.decr), true},
{"order().by(label,decr)", __.order().by(T.label, Order.decr), true},
{"groupCount().by(label)", __.groupCount().by(T.label), true},
});
}
示例8: standardAlgorithm
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected Iterator<Traverser.Admin<E>> standardAlgorithm() {
while (true) {
if (!this.first) {
for (final List<Traversal.Admin<S, E>> options : this.traversalOptions.values()) {
for (final Traversal.Admin<S, E> option : options) {
if (option.hasNext())
return option.getEndStep();
}
}
}
this.first = false;
///
if (this.hasBarrier) {
if (!this.starts.hasNext())
throw FastNoSuchElementException.instance();
while (this.starts.hasNext()) {
this.handleStart(this.starts.next());
}
} else {
this.handleStart(this.starts.next());
}
}
}
示例9: map
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected S map(final Traverser.Admin<S> traverser) {
// We may consider optimizing the iteration of these containers using subtype-specific interfaces. For
// example, we could use descendingIterator if we have a Deque. But in general, we cannot reliably iterate a
// collection in reverse, so we use the range algorithm with dynamically computed boundaries.
final S start = traverser.get();
final long high =
start instanceof Map ? ((Map) start).size() :
start instanceof Collection ? ((Collection) start).size() :
start instanceof Path ? ((Path) start).size() :
start instanceof Iterable ? IteratorUtils.count((Iterable) start) :
this.limit;
final long low = high - this.limit;
final S result = RangeLocalStep.applyRange(start, low, high);
return result;
}
示例10: processNextStart
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected Traverser.Admin<Long> processNextStart() throws NoSuchElementException {
if (!this.done) {
this.done = true;
final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
return this.getTraversal().getTraverserGenerator().generate(Vertex.class.isAssignableFrom(this.elementClass) ?
(long) TinkerHelper.getVertices(graph).size() :
(long) TinkerHelper.getEdges(graph).size(),
(Step) this, 1L);
} else
throw FastNoSuchElementException.instance();
}
示例11: fromVertex
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
public static GephiNode fromVertex(Traverser<Vertex> v) {
Vertex vertex = v.get();
return new GephiNode()
.id(GephiFormat.computeElementId(vertex))
.label(GephiFormat.computeNodeLabel(vertex))
.size(GephiFormat.computeNodeSize(vertex))
.attributes(GephiFormat.computeNodeAttributes(vertex));
}
示例12: fromEdge
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
public static GephiEdge fromEdge(Traverser<Edge> e) {
Edge edge = e.get();
return new GephiEdge()
.id(GephiFormat.computeElementId(edge))
.source(GephiFormat.computeElementId(edge.outVertex()))
.target(GephiFormat.computeElementId(edge.inVertex()))
.title(edge.label());
}
示例13: flatMap
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
protected Iterator<JanusGraphVertex> flatMap(Traverser.Admin<S> traverser) {
JanusGraphTransaction tx = JanusGraphTraversalUtil.getTx(this.traversal);
// Retrieve property value to look-up, that is identified in the traversal by the `stepLabel`
Object value = getNullableScopeValue(Pop.first, stepLabel, traverser);
return value != null ? verticesWithProperty(tx, value) : emptyIterator();
}
示例14: tryUnrollTraverser
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
private void tryUnrollTraverser(final ResultQueue queue, final Object item) {
if (unrollTraversers && item instanceof Traverser) {
final Traverser t = (Traverser) item;
final Object traverserObject = t.get();
for (long ix = 0; ix < t.bulk(); ix++) {
queue.add(new Result(traverserObject));
}
} else {
queue.add(new Result(item));
}
}
示例15: split
import org.apache.tinkerpop.gremlin.process.traversal.Traverser; //导入依赖的package包/类
@Override
public <R> Traverser.Admin<R> split(final R r, final Step<T, R> step) {
final LP_O_OB_S_SE_SL_Traverser<R> clone = (LP_O_OB_S_SE_SL_Traverser<R>) super.split(r, step);
clone.path = clone.path.clone();
if (!step.getLabels().isEmpty()) clone.path = clone.path.extend(r, step.getLabels());
return clone;
}