Skip to content

Commit 323b7ae

Browse files
committed
Varargs for CSVPrinter.println()
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1297136 13f79535-47bb-0310-9956-ffa450edef68
1 parent f6c0433 commit 323b7ae

2 files changed

Lines changed: 11 additions & 23 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void flush() throws IOException {
7878
*
7979
* @param values values to be outputted.
8080
*/
81-
public void println(String[] values) throws IOException {
81+
public void println(String... values) throws IOException {
8282
for (String value : values) {
8383
print(value);
8484
}

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.commons.csv;
1818

1919
import java.io.IOException;
20-
import java.io.StringReader;
2120
import java.io.StringWriter;
2221
import java.util.Random;
2322

@@ -33,72 +32,63 @@ public class CSVPrinterTest extends TestCase {
3332
public void testPrinter1() throws IOException {
3433
StringWriter sw = new StringWriter();
3534
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
36-
String[] line1 = {"a", "b"};
37-
printer.println(line1);
35+
printer.println("a", "b");
3836
assertEquals("a,b" + lineSeparator, sw.toString());
3937
}
4038

4139
public void testPrinter2() throws IOException {
4240
StringWriter sw = new StringWriter();
4341
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
44-
String[] line1 = {"a,b", "b"};
45-
printer.println(line1);
42+
printer.println("a,b", "b");
4643
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
4744
}
4845

4946
public void testPrinter3() throws IOException {
5047
StringWriter sw = new StringWriter();
5148
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
52-
String[] line1 = {"a, b", "b "};
53-
printer.println(line1);
49+
printer.println("a, b", "b ");
5450
assertEquals("\"a, b\",\"b \"" + lineSeparator, sw.toString());
5551
}
5652

5753
public void testPrinter4() throws IOException {
5854
StringWriter sw = new StringWriter();
5955
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
60-
String[] line1 = {"a", "b\"c"};
61-
printer.println(line1);
56+
printer.println("a", "b\"c");
6257
assertEquals("a,\"b\"\"c\"" + lineSeparator, sw.toString());
6358
}
6459

6560
public void testPrinter5() throws IOException {
6661
StringWriter sw = new StringWriter();
6762
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
68-
String[] line1 = {"a", "b\nc"};
69-
printer.println(line1);
63+
printer.println("a", "b\nc");
7064
assertEquals("a,\"b\nc\"" + lineSeparator, sw.toString());
7165
}
7266

7367
public void testPrinter6() throws IOException {
7468
StringWriter sw = new StringWriter();
7569
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
76-
String[] line1 = {"a", "b\r\nc"};
77-
printer.println(line1);
70+
printer.println("a", "b\r\nc");
7871
assertEquals("a,\"b\r\nc\"" + lineSeparator, sw.toString());
7972
}
8073

8174
public void testPrinter7() throws IOException {
8275
StringWriter sw = new StringWriter();
8376
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
84-
String[] line1 = {"a", "b\\c"};
85-
printer.println(line1);
77+
printer.println("a", "b\\c");
8678
assertEquals("a,b\\c" + lineSeparator, sw.toString());
8779
}
8880

8981
public void testExcelPrinter1() throws IOException {
9082
StringWriter sw = new StringWriter();
9183
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL);
92-
String[] line1 = {"a", "b"};
93-
printer.println(line1);
84+
printer.println("a", "b");
9485
assertEquals("a,b" + lineSeparator, sw.toString());
9586
}
9687

9788
public void testExcelPrinter2() throws IOException {
9889
StringWriter sw = new StringWriter();
9990
CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL);
100-
String[] line1 = {"a,b", "b"};
101-
printer.println(line1);
91+
printer.println("a,b", "b");
10292
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
10393
}
10494

@@ -172,9 +162,7 @@ public void doOneRandom() throws Exception {
172162
String result = sw.toString();
173163
// System.out.println("### :" + printable(result));
174164

175-
StringReader reader = new StringReader(result);
176-
177-
CSVParser parser = new CSVParser(reader, format);
165+
CSVParser parser = new CSVParser(result, format);
178166
String[][] parseResult = parser.getRecords();
179167

180168
if (!equals(lines, parseResult)) {

0 commit comments

Comments
 (0)