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

        if (null == item) {
            // we will pass null values to next step
            return null;
        } else if (item instanceof String) {
            return (E) Integer.valueOf(((String) item).length());
        } else {
            throw new IllegalArgumentException(
                    String.format("The length() step can only take string as argument, encountered %s", item.getClass()));
        }

    }
Reference implementation for length() step, a mid-traversal step which returns the length of the incoming string
traverser. Null values are not processed and remain as null when returned. If the incoming traverser is a non-String
value then an {@code IllegalArgumentException} will be thrown.

@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/LengthGlobalStep.java