Skip to content

Commit 225cbe9

Browse files
committed
Document how the pintRecord(s) methods work
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1610502 13f79535-47bb-0310-9956-ffa450edef68
1 parent 040c260 commit 225cbe9

1 file changed

Lines changed: 59 additions & 7 deletions

File tree

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

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ public void println() throws IOException {
341341
}
342342

343343
/**
344-
* Prints a single line of delimiter separated values. The values will be quoted if needed. Quotes and newLine
345-
* characters will be escaped.
344+
* Prints the given values a single record of delimiter separated values followed by the record separator.
345+
*
346+
* <p>
347+
* The values will be quoted if needed. Quotes and newLine characters will be escaped.
348+
* </p>
346349
*
347350
* @param values
348351
* values to output.
@@ -357,8 +360,11 @@ public void printRecord(final Iterable<?> values) throws IOException {
357360
}
358361

359362
/**
360-
* Prints a single line of delimiter separated values. The values will be quoted if needed. Quotes and newLine
361-
* characters will be escaped.
363+
* Prints the given values a single record of delimiter separated values followed by the record separator.
364+
*
365+
* <p>
366+
* The values will be quoted if needed. Quotes and newLine characters will be escaped.
367+
* </p>
362368
*
363369
* @param values
364370
* values to output.
@@ -373,7 +379,30 @@ public void printRecord(final Object... values) throws IOException {
373379
}
374380

375381
/**
376-
* Prints all the objects in the given collection.
382+
* Prints all the objects in the given collection handling nested collections/arrays as records.
383+
*
384+
* <p>If the given collection only contains simple objects, this method will print a single record like
385+
* {@link #printRecord(Iterable)}. If the given collections contains nested collections/arrays those nested elements
386+
* will each be printed as records using {@link #printRecord(Object...)}.</p>
387+
*
388+
* <p>Given the following data structure:</p>
389+
* <pre>
390+
* <source>
391+
* List&lt;String[]&gt; data = ...
392+
* data.add(new String[]{ "A", "B", "C" });
393+
* data.add(new String[]{ "1", "2", "3" });
394+
* data.add(new String[]{ "A1", "B2", "C3" });
395+
* </source>
396+
* </pre>
397+
*
398+
* <p>Calling this method will print:</p>
399+
* <pre>
400+
* <source>
401+
* A, B, C
402+
* 1, 2, 3
403+
* A1, B2, C3
404+
* </source>
405+
* </pre>
377406
*
378407
* @param values
379408
* the values to print.
@@ -393,14 +422,37 @@ public void printRecords(final Iterable<?> values) throws IOException {
393422
}
394423

395424
/**
396-
* Prints all the objects in the given array.
425+
* Prints all the objects in the given array handling nested collections/arrays as records.
426+
*
427+
* <p>If the given array only contains simple objects, this method will print a single record like
428+
* {@link #printRecord(Object...)}. If the given collections contains nested collections/arrays those nested elements
429+
* will each be printed as records using {@link #printRecord(Object...)}.</p>
430+
*
431+
* <p>Given the following data structure:</p>
432+
* <pre>
433+
* <source>
434+
* String[][] data = new String[3][]
435+
* data[0] = String[]{ "A", "B", "C" };
436+
* data[1] = new String[]{ "1", "2", "3" };
437+
* data[2] = new String[]{ "A1", "B2", "C3" };
438+
* </source>
439+
* </pre>
440+
*
441+
* <p>Calling this method will print:</p>
442+
* <pre>
443+
* <source>
444+
* A, B, C
445+
* 1, 2, 3
446+
* A1, B2, C3
447+
* </source>
448+
* </pre>
397449
*
398450
* @param values
399451
* the values to print.
400452
* @throws IOException
401453
* If an I/O error occurs
402454
*/
403-
public void printRecords(final Object[] values) throws IOException {
455+
public void printRecords(final Object... values) throws IOException {
404456
for (final Object value : values) {
405457
if (value instanceof Object[]) {
406458
this.printRecord((Object[]) value);

0 commit comments

Comments
 (0)