code: public static int size(Iterator<?> iterator) {
      long count = 0L;
      while (iterator.hasNext()) {
        iterator.next();
        count++;
      }
      return Ints.saturatedCast(count);
    }
docs: Returns the number of elements remaining in {@code iterator}. The iterator will be left
  exhausted: its {@code hasNext()} method will return {@code false}.