private static Integer computeIteratedObjectSize(final Object iteratedObject) {
        if (iteratedObject == null) {
            return Integer.valueOf(0);
        }
        if (iteratedObject instanceof Collection<?>) {
            return Integer.valueOf(((Collection<?>) iteratedObject).size());
        }
        if (iteratedObject instanceof Map<?,?>) {
            return Integer.valueOf(((Map<?, ?>) iteratedObject).size());
        }
        if (iteratedObject.getClass().isArray()) {
            return Integer.valueOf(Array.getLength(iteratedObject));
        }
        if (iteratedObject instanceof Iterable<?>) {
            return null; // Cannot determine before actually iterating
        }
        if (iteratedObject instanceof Iterator<?>) {
            return null; // Cannot determine before actually iterating
        }
        return Integer.valueOf(1); // In this case, we will iterate the object as a collection of size 1
    }
private static Integer computeIteratedObjectSize ( final Object iteratedObject ) { if ( iteratedObject == null ) { return Integer . valueOf ( 0 ) ; } if ( iteratedObject instanceof Collection < ? > ) { return Integer . valueOf ( ( ( Collection < ? > ) iteratedObject ) . size ( ) ) ; } if ( iteratedObject instanceof Map < ? , ? > ) { return Integer . valueOf ( ( ( Map < ? , ? > ) iteratedObject ) . size ( ) ) ; } if ( iteratedObject . getClass ( ) . isArray ( ) ) { return Integer . valueOf ( Array . getLength ( iteratedObject ) ) ; } if ( iteratedObject instanceof Iterable < ? > ) { return null ; } if ( iteratedObject instanceof Iterator < ? > ) { return null ; } return Integer . valueOf ( 1 ) ; }
/*
Whenever possible, compute the total size of the iterated object. Note sometimes we will not be able
to compute this size without traversing the entire collection/iterator (which we want to avoid), so
null will be returned.