public static void setMemorySideEffects(final Traversal.Admin<?, ?> traversal, final Memory memory, final ProgramPhase phase) {
        final TraversalSideEffects sideEffects = traversal.getSideEffects();
        if (!(sideEffects instanceof MemoryTraversalSideEffects)) {
            traversal.setSideEffects(new MemoryTraversalSideEffects(sideEffects));
        }
        final MemoryTraversalSideEffects memoryTraversalSideEffects = ((MemoryTraversalSideEffects) traversal.getSideEffects());
        memoryTraversalSideEffects.memory = memory;
        memoryTraversalSideEffects.phase = phase;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/MemoryTraversalSideEffects.java