private void addToGremlin(final String name, final Object... arguments) {
        final Object[] flattenedArguments = flattenArguments(arguments);

        // todo: figure out solution for AbstractLambdaTraversal
        if ("CardinalityValueTraversal".equals(name)) {
            gremlin.append("Cardinality.").append(flattenedArguments[0])
                    .append("(").append(flattenedArguments[1]).append(")");
            return;
        }

        gremlin.append(".").append(name).append('(');

        for (int i = 0; i < flattenedArguments.length; i++) {
            if (i != 0) {
                gremlin.append(',');
            }
            gremlin.append(argAsString(flattenedArguments[i]));
        }

        gremlin.append(')');
    }
This class helps to build a gremlin-lang compatible string representation based on a {@link TraversalSource}
and then a {@link Traversal}.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLang.java