@Override
    public void applyStrategies() throws IllegalStateException {
        if (this.locked) throw Traversal.Exceptions.traversalIsLocked();

        // apply strategies in order on a root traversal only or a traversal that is logically considered a root
        // for GraphComputer as a child of VertexProgramStep.
        if (isRoot() || this.getParent() instanceof VertexProgramStep) {
            final Iterator<TraversalStrategy<?>> strategyIterator = this.strategies.iterator();
            while (strategyIterator.hasNext()) {
                final TraversalStrategy<?> strategy = strategyIterator.next();
                TraversalHelper.applyTraversalRecursively(strategy::apply, this);
            }
        }

        // Grouping steps potentially have barriers. those barriers need to get reset after strategies are applied
        // or else they can old incorrect references if those barriers are rewritten by strategies.
        steps.stream().filter(s -> s instanceof Grouping).forEach(
                step -> ((Grouping<?, ?, ?>) step).resetBarrierFromValueTraversal());

        // lock the traversal and its children for execution, finalizing the copy of any data from parent to child
        // as needed
        this.lock();
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java