Here I think you can use `Iterators.size` and `Iterables.size` from guava:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Iterators.html#size(java.util.Iterator)
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Iterables.html#size(java.lang.Iterable)