Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.Traverser#Admin

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.Traverser#Admin . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlgPropertiesStep.java    From sqlg with MIT License 6 votes vote down vote up
@Override
protected Iterator<E> flatMap(final Traverser.Admin<Element> traverser) {
    for (String appliesToLabel : appliesToLabels) {
        String label = SqlgUtil.originalLabel(appliesToLabel);
        Object o = traverser.path().get(label);
        if (o instanceof List) {
            List<SqlgElement> objects = (List) o;
            SqlgElement last = objects.get(objects.size() - 1);
            if (this.returnType.equals(PropertyType.VALUE)) {
                return last.values(this.propertyKeys);
            } else {
                return (Iterator)last.properties(this.propertyKeys);
            }
        } else {
            SqlgElement sqlgElement = traverser.path().get(label);
            if (this.returnType.equals(PropertyType.VALUE)) {
                return sqlgElement.values(this.propertyKeys);
            } else {
                return (Iterator) sqlgElement.properties(this.propertyKeys);
            }
        }
    }
    return EmptyIterator.INSTANCE;
}
 
Example 2
Source File: GraphStep.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
protected Traverser.Admin<E> processNextStart() {
    while (true) {
        if (this.iterator.hasNext()) {
            return this.isStart ? this.getTraversal().getTraverserGenerator().generate(this.iterator.next(), (Step) this, 1l) : this.head.split(this.iterator.next(), this);
        } else {
            if (this.isStart) {
                if (this.done)
                    throw FastNoSuchElementException.instance();
                else {
                    this.done = true;
                    this.iterator = null == this.iteratorSupplier ? EmptyIterator.instance() : this.iteratorSupplier.get();
                }
            } else {
                this.head = this.starts.next();
                this.iterator = null == this.iteratorSupplier ? EmptyIterator.instance() : this.iteratorSupplier.get();
            }
        }
    }
}
 
Example 3
Source File: ShortestPathVertexProgram.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void updateHaltedTraversers(final Vertex vertex, final Memory memory) {
    if (isStartVertex(vertex)) {
        final List<Path> paths = memory.get(SHORTEST_PATHS);
        if (vertex.property(TraversalVertexProgram.HALTED_TRAVERSERS).isPresent()) {
            // replace the current set of halted traversers with new new traversers that hold the shortest paths
            // found for this vertex
            final TraverserSet<Vertex> haltedTraversers = vertex.value(TraversalVertexProgram.HALTED_TRAVERSERS);
            final TraverserSet<Path> newHaltedTraversers = new TraverserSet<>();
            for (final Traverser.Admin<Vertex> traverser : haltedTraversers) {
                final Vertex v = traverser.get();
                for (final Path path : paths) {
                    if (path.get(0).equals(v)) {
                        newHaltedTraversers.add(traverser.split(path, this.programStep));
                    }
                }
            }
            vertex.property(VertexProperty.Cardinality.single, TraversalVertexProgram.HALTED_TRAVERSERS, newHaltedTraversers);
        }
    }
}
 
Example 4
Source File: LocalStep.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
protected Traverser.Admin<E> processNextStart() throws NoSuchElementException {
    if (this.first) {
        this.first = false;
        this.localTraversal.addStart(this.starts.next());
    }
    while (true) {
        if (this.localTraversal.hasNext())
            return this.localTraversal.nextTraverser();
        else if (this.starts.hasNext()) {
            this.localTraversal.reset();
            this.localTraversal.addStart(this.starts.next());
        } else {
            throw FastNoSuchElementException.instance();
        }
    }
}
 
Example 5
Source File: Scoping.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the object with the specified key for the current traverser and throws an exception if the key cannot
 * be found.
 *
 * @throws KeyNotFoundException if the key does not exist
 */
public default <S> S getScopeValue(final Pop pop, final Object key, final Traverser.Admin<?> traverser) throws KeyNotFoundException {
    final Object object = traverser.get();
    if (object instanceof Map && ((Map) object).containsKey(key))
        return (S) ((Map) object).get(key);

    if (key instanceof String) {
        final String k = (String) key;
        if (traverser.getSideEffects().exists(k))
            return traverser.getSideEffects().get(k);

        final Path path = traverser.path();
        if (path.hasLabel(k))
            return null == pop ? path.get(k) : path.get(pop, k);
    }

    throw new KeyNotFoundException(key, this);
}
 
Example 6
Source File: SqlgComputerAwareStep.java    From sqlg with MIT License 5 votes vote down vote up
@Override
protected Traverser.Admin<E> processNextStart() throws NoSuchElementException {
    while (true) {
        if (this.previousIterator.hasNext())
            return this.previousIterator.next();
        this.previousIterator = this.traverserStepIdAndLabelsSetByChild ? this.computerAlgorithm() : this.standardAlgorithm();
    }
}
 
Example 7
Source File: Parameters.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the array of keys/values of the parameters while resolving parameter values that contain
 * {@link Traversal} instances.
 */
public <S> Object[] getKeyValues(final Traverser.Admin<S> traverser, final Object... exceptKeys) {
    if (this.parameters.isEmpty()) return EMPTY_ARRAY;
    final List<Object> keyValues = new ArrayList<>();
    for (final Map.Entry<Object, List<Object>> entry : this.parameters.entrySet()) {
        if (!ArrayUtils.contains(exceptKeys, entry.getKey())) {
            for (final Object value : entry.getValue()) {
                keyValues.add(entry.getKey() instanceof Traversal.Admin ? TraversalUtil.apply(traverser, (Traversal.Admin<S, ?>) entry.getKey()) : entry.getKey());
                keyValues.add(value instanceof Traversal.Admin ? TraversalUtil.apply(traverser, (Traversal.Admin<S, ?>) value) : value);
            }
        }
    }
    return keyValues.toArray(new Object[keyValues.size()]);
}
 
Example 8
Source File: O_Traverser.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void merge(final Traverser.Admin<?> other) {
    if (!other.getTags().isEmpty()) {
        if (this.tags == null) this.tags = new HashSet<>();
        this.tags.addAll(other.getTags());
    }
}
 
Example 9
Source File: SqlgComputerAwareStep.java    From sqlg with MIT License 5 votes vote down vote up
@Override
protected Traverser.Admin<S> processNextStart() throws NoSuchElementException {
    final Traverser.Admin<S> start = this.starts.next();
    if (this.traverserStepIdAndLabelsSetByChild) {
        final ComputerAwareStep<?, ?> step = (ComputerAwareStep<?, ?>) this.getTraversal().getParent();
        start.setStepId(step.getNextStep().getId());
        start.addLabels(step.getLabels());
    }
    return start;
}
 
Example 10
Source File: ComputerResultStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected Traverser.Admin<S> processNextStart() throws NoSuchElementException {
    while (true) {
        if (this.currentIterator.hasNext())
            return this.currentIterator.next();
        else {
            final ComputerResult result = this.starts.next().get();
            this.currentIterator = attach(result.memory().exists(TraversalVertexProgram.HALTED_TRAVERSERS)
                    ? result.memory().<TraverserSet<S>>get(TraversalVertexProgram.HALTED_TRAVERSERS).iterator()
                    : EmptyIterator.instance(), result.graph());
        }
    }
}
 
Example 11
Source File: TinkerCountGlobalStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 12
Source File: AbstractStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private final Traverser.Admin<E> prepareTraversalForNextStep(final Traverser.Admin<E> traverser) {
    if (!this.traverserStepIdAndLabelsSetByChild) {
        traverser.setStepId(this.nextStep.getId());
        traverser.addLabels(this.labels);
    }
    return traverser;
}
 
Example 13
Source File: TraversalUtil.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static final <S, E> Iterator<E> applyAll(final Traverser.Admin<S> traverser, final Traversal.Admin<S, E> traversal) {
    final Traverser.Admin<S> split = traverser.split();
    split.setSideEffects(traversal.getSideEffects());
    split.setBulk(1l);
    traversal.reset();
    traversal.addStart(split);
    return traversal; // flatmap
}
 
Example 14
Source File: LambdaFilterStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean filter(final Traverser.Admin<S> traverser) {
    return this.predicate.test(traverser);
}
 
Example 15
Source File: TraverserSet.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public boolean offer(final Traverser.Admin<S> traverser) {
    return this.add(traverser);
}
 
Example 16
Source File: JanusGraphVertexStep.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected Traverser.Admin<E> processNextStart() {
    if (!initialized) initialize();
    return super.processNextStart();
}
 
Example 17
Source File: MathStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected Traverser.Admin<Double> processNextStart() {
    return PathProcessor.processTraverserPathLabels(super.processNextStart(), this.keepLabels);
}
 
Example 18
Source File: B_LP_O_P_S_SE_SL_Traverser.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Traverser.Admin<T> detach() {
    super.detach();
    this.path = ReferenceFactory.detach(this.path);
    return this;
}
 
Example 19
Source File: TreeSideEffectStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected Traverser.Admin<S> processNextStart() {
    return PathProcessor.processTraverserPathLabels(super.processNextStart(), this.keepLabels);
}
 
Example 20
Source File: SqlgMapStep.java    From sqlg with MIT License votes vote down vote up
protected abstract E map(final Traverser.Admin<S> traverser);