Skip to content

Commit 389cf00

Browse files
committed
Add comments to iterator() and stream()
1 parent f36e0f5 commit 389cf00

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,24 @@ private boolean isStrictQuoteMode() {
734734
* {@link IllegalStateException}.
735735
* </p>
736736
* <p>
737-
* If the parser is closed a call to {@link Iterator#next()} will throw a
737+
* If the parser is closed, the iterator will not yield any more records.
738+
* A call to {@link Iterator#hasNext()} will return {@code false} and
739+
* a call to {@link Iterator#next()} will throw a
738740
* {@link NoSuchElementException}.
739741
* </p>
742+
* <p>
743+
* For example, the iterator from code such as
744+
* <pre>
745+
* Iterator{@code<CSVRecord>} items() throws IOException {
746+
* try (CSVParser parser = CSVParser.parse( ... )) {
747+
* return parser.iterator();
748+
* }
749+
* }
750+
* </pre>
751+
* will never yield any records because the parser is closed by the
752+
* try-with-resources block.
753+
* An alternative is to extract all records as a list with
754+
* {@link getRecords()}, and return an iterator to that list.
740755
*/
741756
@Override
742757
public Iterator<CSVRecord> iterator() {
@@ -799,7 +814,9 @@ CSVRecord nextRecord() throws IOException {
799814

800815
/**
801816
* Returns a sequential {@code Stream} with this collection as its source.
802-
*
817+
* <p>
818+
* If the parser is closed, the stream will not produce any more values.
819+
* See the comments in {@link iterator()}.
803820
* @return a sequential {@code Stream} with this collection as its source.
804821
* @since 1.9.0
805822
*/

0 commit comments

Comments
 (0)