Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.Step#addLabel()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.Step#addLabel() . 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: GraphTraversal.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * A step modulator that provides a label to the step that can be accessed later in the traversal by other steps.
 *
 * @param stepLabel  the name of the step
 * @param stepLabels additional names for the label
 * @return the traversal with the modified end step
 * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#as-step" target="_blank">Reference Documentation - As Step</a>
 * @since 3.0.0-incubating
 */
public default GraphTraversal<S, E> as(final String stepLabel, final String... stepLabels) {
    this.asAdmin().getBytecode().addStep(Symbols.as, stepLabel, stepLabels);
    if (this.asAdmin().getSteps().size() == 0) this.asAdmin().addStep(new StartStep<>(this.asAdmin()));
    final Step<?, E> endStep = this.asAdmin().getEndStep();
    endStep.addLabel(stepLabel);
    for (final String label : stepLabels) {
        endStep.addLabel(label);
    }
    return this;
}
 
Example 2
Source File: TraversalHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static void copyLabels(final Step<?, ?> fromStep, final Step<?, ?> toStep, final boolean moveLabels) {
    if (!fromStep.getLabels().isEmpty()) {
        for (final String label : moveLabels ? new LinkedHashSet<>(fromStep.getLabels()) : fromStep.getLabels()) {
            toStep.addLabel(label);
            if (moveLabels)
                fromStep.removeLabel(label);
        }
    }
}
 
Example 3
Source File: IncidentToAdjacentStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}