code: public static <T> Iterator<T> checkHasNext(Iterator<T> iterator, String message) throws NoSuchElementException {
          if (!iterator.hasNext()) {
              throw new NoSuchElementException(message);
          }
          return iterator;
      }
docs: Check if iterator has next element. If not throw NoSuchElementException
  
  @param iterator
  @param message
  @return the iterator itself
  @throws java.util.NoSuchElementException if iterator.hasNext returns false