Search in sources :

Example 1 with B_O_S_SE_SL_Traverser

use of org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser in project unipop by unipop-graph.

the class UniGraphCoalesceStep method process.

@Override
protected Iterator<Traverser.Admin<E>> process(List<Traverser.Admin<S>> traversers) {
    List<Traverser.Admin<E>> coalesce = new ArrayList<>();
    List<Traverser.Admin<S>> traversersList = Lists.newArrayList(traversers);
    traversersList.forEach(t -> {
        t.setSideEffects(new DefaultTraversalSideEffects() {

            {
                register(t.toString(), () -> t, BinaryOperator.maxBy((o1, o2) -> 1));
                set(t.toString(), t);
            }
        });
    });
    coalesceTraversals.forEach(t -> {
        traversersList.forEach(t::addStart);
        while (t.hasNext()) {
            Traverser<E> item = (Traverser<E>) t.next();
            ((B_O_S_SE_SL_Traverser) item).getSideEffects().forEach((key, value) -> {
                if (value != null && value instanceof Traverser)
                    traversersList.remove(value);
            });
            coalesce.add((item.asAdmin()));
        }
    });
    return coalesce.iterator();
}
Also used : TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) DefaultTraversalSideEffects(org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalSideEffects) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) B_O_S_SE_SL_Traverser(org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser)

Example 2 with B_O_S_SE_SL_Traverser

use of org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser in project unipop by unipop-graph.

the class UniGraphWhereTraversalStep method processNextStart.

@Override
protected Traverser.Admin<S> processNextStart() throws NoSuchElementException {
    if (this.starts.hasNext()) {
        this.starts.forEachRemaining(start -> {
            start.setSideEffects(new DefaultTraversalSideEffects() {

                {
                    register("_whereStep", () -> start, (sAdmin, sAdmin2) -> sAdmin);
                }
            });
            whereTraversal.asAdmin().addStart(start);
            originals.add(start);
            if (whereTraversal.asAdmin().getStartStep() instanceof UniGraphWhereStartStep) {
                ((UniGraphWhereStartStep) whereTraversal.asAdmin().getStartStep()).addOriginal(start);
            }
        });
        had = true;
    }
    if (had && !results.hasNext()) {
        HashSet<Traverser.Admin<S>> resultsList = new HashSet<>();
        while (whereTraversal.hasNext()) {
            had = false;
            B_O_S_SE_SL_Traverser next = (B_O_S_SE_SL_Traverser) whereTraversal.next();
            Object whereStep = next.getSideEffects().get("_whereStep");
            if (whereStep instanceof Traverser)
                resultsList.add((Traverser.Admin<S>) whereStep);
            else {
                results = ((ArrayList<Traverser.Admin<S>>) whereStep).iterator();
            }
        }
        if (resultsList.size() > 0)
            results = resultsList.iterator();
    }
    return results.next();
}
Also used : java.util(java.util) Pop(org.apache.tinkerpop.gremlin.process.traversal.Pop) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) UniGraphTraverserStep(org.unipop.process.traverser.UniGraphTraverserStep) AbstractStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep) Scoping(org.apache.tinkerpop.gremlin.process.traversal.step.Scoping) Element(org.apache.tinkerpop.gremlin.structure.Element) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) DefaultTraversalSideEffects(org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalSideEffects) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) StringFactory(org.apache.tinkerpop.gremlin.structure.util.StringFactory) B_O_S_SE_SL_Traverser(org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser) FastNoSuchElementException(org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException) DefaultTraversalSideEffects(org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalSideEffects) B_O_S_SE_SL_Traverser(org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) B_O_S_SE_SL_Traverser(org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser)

Aggregations

Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)2 TraversalParent (org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent)2 B_O_S_SE_SL_Traverser (org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser)2 TraverserRequirement (org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement)2 DefaultTraversalSideEffects (org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalSideEffects)2 java.util (java.util)1 Pop (org.apache.tinkerpop.gremlin.process.traversal.Pop)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 Scoping (org.apache.tinkerpop.gremlin.process.traversal.step.Scoping)1 AbstractStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep)1 FastNoSuchElementException (org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException)1 Element (org.apache.tinkerpop.gremlin.structure.Element)1 StringFactory (org.apache.tinkerpop.gremlin.structure.util.StringFactory)1 EmptyIterator (org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)1 UniGraphTraverserStep (org.unipop.process.traverser.UniGraphTraverserStep)1