@Override
    protected E map(final Traverser.Admin<S> traverser) {
        final S items = traverser.get();

        if (null == items) {
            return null;
        } else if (items instanceof String) {
            return (E) new StringBuilder(((String) items)).reverse().toString();
        } else if ((items instanceof Iterable) || (items instanceof Iterator) || items.getClass().isArray()) {
            final List itemsAsList = IteratorUtils.asList(items);
            Collections.reverse(itemsAsList);
            return (E) itemsAsList;
        } else {
            // null traversers are passed on without throwing an exception so the same should be done with other types.
            return (E) items;
        }
    }
Reference implementation for reverse() step, a mid-traversal step which returns the reverse value.
Null values are not processed and remain as null when returned.

@author David Bechberger (http://bechberger.com)
@author Yang Xia (http://github.com/xiazcy)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReverseStep.java