Java Reference
In-Depth Information
return nextElement = line;
} catch (IOException ioe) {
this.exception = ioe;
explodeIfException();
throw new IllegalStateException("This code should never be reached!");
}
}
/**
* Returns {@code true} if the iteration has more elements.
* (In other words, returns {@code true} if {@link #next} would
* return an element rather than throwing an exception.)
*
* @return {@code true} if the iteration has more elements
*/
@Override
public boolean hasNext() {
explodeIfException();
if (nextElement != null) return true;
if (closed) return false;
if (nextLine() != null) return true;
return false;
}
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration
* @throws java.util.NoSuchElementException if the iteration has no
* more elements
*/
@Override
public String next() {
explodeIfException();
if (nextElement != null || nextLine() != null) {
String toReturn = nextElement;
nextElement = null;
return toReturn;
}
throw new NoSuchElementException("No more lines to be read!");
}
/**
* Provides the element that will be returned by {@link #next()}
* without progressing the iterator.
*
* @return What will be the next element, or {@code null} if there is
* no next element.
*/
Search WWH ::




Custom Search