Skip to content

Commit 7ac5dd3

Browse files
committed
Rename methods that create a builder newBuilder().
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1409455 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6a34b82 commit 7ac5dd3

7 files changed

Lines changed: 37 additions & 37 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class CSVFormat implements Serializable {
6262
* </ul>
6363
*/
6464
public static final CSVFormat RFC4180 =
65-
defaults()
65+
newBuilder()
6666
.withIgnoreEmptyLines(false)
6767
.build();
6868

@@ -76,7 +76,7 @@ public class CSVFormat implements Serializable {
7676
* </ul>
7777
*/
7878
public static final CSVFormat DEFAULT = // TODO rename to something more meaningful
79-
defaults()
79+
newBuilder()
8080
.build();
8181

8282
/**
@@ -97,13 +97,13 @@ public class CSVFormat implements Serializable {
9797
* Note: this is currently the same as RFC4180
9898
*/
9999
public static final CSVFormat EXCEL =
100-
defaults()
100+
newBuilder()
101101
.withIgnoreEmptyLines(false)
102102
.build();
103103

104104
/** Tab-delimited format, with quote; leading and trailing spaces ignored. */
105105
public static final CSVFormat TDF =
106-
defaults()
106+
newBuilder()
107107
.withDelimiter(TAB)
108108
.withIgnoreSurroundingSpaces(true)
109109
.build();
@@ -117,7 +117,7 @@ public class CSVFormat implements Serializable {
117117
* http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
118118
*/
119119
public static final CSVFormat MYSQL =
120-
defaults()
120+
newBuilder()
121121
.withDelimiter(TAB)
122122
.withQuoteChar(null)
123123
.withEscape(ESCAPE)
@@ -126,13 +126,13 @@ public class CSVFormat implements Serializable {
126126
.build();
127127

128128
/**
129-
* Factory method for creating CSV formats.
129+
* Creates a new CSV format builds.
130130
*
131131
* @param delimiter
132132
* the char used for value separation, must not be a line break character
133133
* @throws IllegalArgumentException if the delimiter is a line break character
134134
*/
135-
public static CSVFormatBuilder newFormat(char delimiter) {
135+
public static CSVFormatBuilder newBuilder(char delimiter) {
136136
return new CSVFormatBuilder(delimiter);
137137
}
138138

@@ -145,7 +145,7 @@ public static CSVFormatBuilder newFormat(char delimiter) {
145145
* <li>withLineSeparator(CRLF)</li>
146146
* </ul>
147147
*/
148-
public static CSVFormatBuilder defaults() {
148+
public static CSVFormatBuilder newBuilder() {
149149
return new CSVFormatBuilder(COMMA, DOUBLE_QUOTE, null, null, null, false, true, CRLF, null);
150150
}
151151

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testCSVFile() throws Exception {
9090
assertTrue(testName+" require 1 param", split.length >= 1);
9191
// first line starts with csv data file name
9292
final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0])));
93-
CSVFormatBuilder builder = CSVFormat.newFormat(',').withQuoteChar('"');
93+
CSVFormatBuilder builder = CSVFormat.newBuilder(',').withQuoteChar('"');
9494
CSVFormat fmt = builder.build();
9595
boolean checkComments = false;
9696
for(int i=1; i < split.length; i++) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public void testDelimiter() {
4545

4646
@Test(expected = IllegalArgumentException.class)
4747
public void testNewFormatLFThrowsException() {
48-
CSVFormat.newFormat(LF);
48+
CSVFormat.newBuilder(LF);
4949
}
5050

5151
@Test(expected = IllegalArgumentException.class)
5252
public void testNewFormatCRThrowsException() {
53-
CSVFormat.newFormat(CR);
53+
CSVFormat.newBuilder(CR);
5454
}
5555

5656
@Test(expected = IllegalArgumentException.class)
@@ -101,7 +101,7 @@ public void testQuotePolicy() {
101101

102102
@Test(expected = IllegalStateException.class)
103103
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
104-
CSVFormat.newFormat('!').withQuotePolicy(Quote.NONE).build();
104+
CSVFormat.newBuilder('!').withQuotePolicy(Quote.NONE).build();
105105
}
106106

107107
@Test

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void assertTokenEquals(final Token.Type expectedType, final String expec
5151
@Test
5252
public void testNextToken1() throws IOException {
5353
final String code = "abc,def, hijk, lmnop, qrst,uv ,wxy ,z , ,";
54-
final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
54+
final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
5555
assertTokenEquals(TOKEN, "abc", parser.nextToken(new Token()));
5656
assertTokenEquals(TOKEN, "def", parser.nextToken(new Token()));
5757
assertTokenEquals(TOKEN, "hijk", parser.nextToken(new Token()));
@@ -83,7 +83,7 @@ public void testNextToken2() throws IOException {
8383
"\n"+
8484
"\n"+
8585
"# Final comment\n"; // 7
86-
final CSVFormat format = CSVFormat.defaults().withCommentStart('#').build();
86+
final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').build();
8787
assertTrue("Should ignore empty lines", format.getIgnoreEmptyLines());
8888

8989
final Lexer parser = getLexer(code, format);
@@ -126,7 +126,7 @@ public void testNextToken2EmptyLines() throws IOException {
126126
"\n"+ // 6b
127127
"\n"+ // 6c
128128
"# Final comment\n"; // 7
129-
final CSVFormat format = CSVFormat.defaults().withCommentStart('#').withIgnoreEmptyLines(false).build();
129+
final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').withIgnoreEmptyLines(false).build();
130130
assertFalse("Should not ignore empty lines", format.getIgnoreEmptyLines());
131131

132132
final Lexer parser = getLexer(code, format);
@@ -187,7 +187,7 @@ public void testNextToken3Escaping() throws IOException {
187187
* \,,
188188
*/
189189
final String code = "a,\\,,b\\\\\n\\,,\\\nc,d\\\r\ne";
190-
final CSVFormat format = CSVFormat.defaults().withEscape('\\').withIgnoreEmptyLines(false).build();
190+
final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').withIgnoreEmptyLines(false).build();
191191
assertTrue(format.isEscaping());
192192
final Lexer parser = getLexer(code, format);
193193

@@ -204,7 +204,7 @@ public void testNextToken3Escaping() throws IOException {
204204
@Test
205205
public void testNextToken3BadEscaping() throws IOException {
206206
final String code = "a,b,c\\";
207-
final CSVFormat format = CSVFormat.defaults().withEscape('\\').build();
207+
final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').build();
208208
assertTrue(format.isEscaping());
209209
final Lexer parser = getLexer(code, format);
210210

@@ -226,7 +226,7 @@ public void testNextToken4() throws IOException {
226226
* a, " foo " ,b
227227
*/
228228
final String code = "a,\"foo\",b\na, \" foo\",b\na,\"foo \" ,b\na, \" foo \" ,b";
229-
final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
229+
final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
230230
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
231231
assertTokenEquals(TOKEN, "foo", parser.nextToken(new Token()));
232232
assertTokenEquals(EORECORD, "b", parser.nextToken(new Token()));
@@ -264,7 +264,7 @@ public void testNextToken6() throws IOException {
264264
* ;;
265265
*/
266266
final String code = "a;'b and '' more\n'\n!comment;;;;\n;;";
267-
final CSVFormat format = CSVFormat.defaults().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
267+
final CSVFormat format = CSVFormat.newBuilder().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
268268
final Lexer parser = getLexer(code, format);
269269
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
270270
assertTokenEquals(EORECORD, "b and ' more\n", parser.nextToken(new Token()));

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class CSVParserTest {
7171

7272
@Test
7373
public void testGetLine() throws IOException {
74-
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
74+
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
7575
for (final String[] re : RESULT) {
7676
assertArrayEquals(re, parser.nextRecord().values());
7777
}
@@ -81,7 +81,7 @@ public void testGetLine() throws IOException {
8181

8282
@Test
8383
public void testGetRecords() throws IOException {
84-
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
84+
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
8585
final List<CSVRecord> records = parser.getRecords();
8686
assertEquals(RESULT.length, records.size());
8787
assertTrue(records.size() > 0);
@@ -312,7 +312,7 @@ public void testBackslashEscaping() throws IOException {
312312
};
313313

314314

315-
final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'').withEscape('/')
315+
final CSVFormat format = CSVFormat.newBuilder(',').withQuoteChar('\'').withEscape('/')
316316
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
317317

318318
final CSVParser parser = new CSVParser(code, format);
@@ -342,7 +342,7 @@ public void testBackslashEscaping2() throws IOException {
342342
};
343343

344344

345-
final CSVFormat format = CSVFormat.newFormat(',').withEscape('/')
345+
final CSVFormat format = CSVFormat.newBuilder(',').withEscape('/')
346346
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
347347

348348
final CSVParser parser = new CSVParser(code, format);
@@ -381,7 +381,7 @@ public void testDefaultFormat() throws IOException {
381381
{"\n", " ", "#"},
382382
};
383383

384-
format = CSVFormat.defaults().withCommentStart('#').build();
384+
format = CSVFormat.newBuilder().withCommentStart('#').build();
385385
parser = new CSVParser(code, format);
386386
records = parser.getRecords();
387387

@@ -481,7 +481,7 @@ public void testIterator() throws Exception {
481481
public void testHeader() throws Exception {
482482
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
483483

484-
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader().build().parse(in).iterator();
484+
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader().build().parse(in).iterator();
485485

486486
for (int i = 0; i < 2; i++) {
487487
assertTrue(records.hasNext());
@@ -498,7 +498,7 @@ public void testHeader() throws Exception {
498498
public void testHeaderComment() throws Exception {
499499
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
500500

501-
final Iterator<CSVRecord> records = CSVFormat.defaults().withCommentStart('#').withHeader().build().parse(in).iterator();
501+
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withCommentStart('#').withHeader().build().parse(in).iterator();
502502

503503
for (int i = 0; i < 2; i++) {
504504
assertTrue(records.hasNext());
@@ -515,7 +515,7 @@ public void testHeaderComment() throws Exception {
515515
public void testProvidedHeader() throws Exception {
516516
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
517517

518-
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B", "C").build().parse(in).iterator();
518+
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A", "B", "C").build().parse(in).iterator();
519519

520520
for (int i = 0; i < 3; i++) {
521521
assertTrue(records.hasNext());
@@ -536,7 +536,7 @@ public void testProvidedHeader() throws Exception {
536536
public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception {
537537
final Reader in = new StringReader("a,b,c\n1,2\nx,y,z");
538538

539-
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B", "C").build().parse(in).iterator();
539+
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A", "B", "C").build().parse(in).iterator();
540540

541541
// header record
542542
assertTrue(records.hasNext());
@@ -578,7 +578,7 @@ record = records.next();
578578
}
579579

580580
public void testGetHeaderMap() throws Exception {
581-
final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.defaults().withHeader("A", "B", "C").build());
581+
final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.newBuilder().withHeader("A", "B", "C").build());
582582
final Map<String, Integer> headerMap = parser.getHeaderMap();
583583
final Iterator<String> columnNames = headerMap.keySet().iterator();
584584
// Headers are iterated in column order.
@@ -622,7 +622,7 @@ public void testGetRecordNumberWithLF() throws Exception {
622622
@Test
623623
public void testGetRecordWithMultiiLineValues() throws Exception {
624624
final CSVParser parser = new CSVParser("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"",
625-
CSVFormat.defaults().withRecordSeparator(CRLF).build());
625+
CSVFormat.newBuilder().withRecordSeparator(CRLF).build());
626626
CSVRecord record;
627627
assertEquals(0, parser.getRecordNumber());
628628
assertEquals(0, parser.getLineNumber());
@@ -654,7 +654,7 @@ public void testGetRecordNumberWithCR() throws Exception {
654654
}
655655

656656
private void validateRecordNumbers(String lineSeparator) throws IOException {
657-
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
657+
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
658658
CSVRecord record;
659659
assertEquals(0, parser.getRecordNumber());
660660
assertNotNull(record = parser.nextRecord());
@@ -671,7 +671,7 @@ private void validateRecordNumbers(String lineSeparator) throws IOException {
671671
}
672672

673673
private void validateLineNumbers(String lineSeparator) throws IOException {
674-
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
674+
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
675675
assertEquals(0, parser.getLineNumber());
676676
assertNotNull(parser.nextRecord());
677677
assertEquals(1, parser.getLineNumber());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
220220
@Test
221221
public void testMultiLineComment() throws IOException {
222222
final StringWriter sw = new StringWriter();
223-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
223+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
224224
printer.printComment("This is a comment\non multiple lines");
225225

226226
assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString());
@@ -293,15 +293,15 @@ public void testPrintNullValues() throws IOException {
293293
@Test
294294
public void testQuoteAll() throws IOException {
295295
final StringWriter sw = new StringWriter();
296-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.ALL).build());
296+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.ALL).build());
297297
printer.printRecord("a", "b\nc", "d");
298298
assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString());
299299
}
300300

301301
@Test
302302
public void testQuoteNonNumeric() throws IOException {
303303
final StringWriter sw = new StringWriter();
304-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.NON_NUMERIC).build());
304+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.NON_NUMERIC).build());
305305
printer.printRecord("a", "b\nc", Integer.valueOf(1));
306306
assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString());
307307
}
@@ -317,7 +317,7 @@ public void testRandom() throws Exception {
317317
@Test
318318
public void testSingleLineComment() throws IOException {
319319
final StringWriter sw = new StringWriter();
320-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
320+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
321321
printer.printComment("This is a comment");
322322

323323
assertEquals("# This is a comment" + recordSeparator, sw.toString());

src/test/java/org/apache/commons/csv/perf/PerformanceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private BufferedReader getBufferedReader() throws IOException {
6666
}
6767

6868
private long parse(final Reader in, boolean traverseColumns) throws IOException {
69-
final CSVFormat format = CSVFormat.defaults().withIgnoreSurroundingSpaces(false).build();
69+
final CSVFormat format = CSVFormat.newBuilder().withIgnoreSurroundingSpaces(false).build();
7070
long recordCount = 0;
7171
for (final CSVRecord record : format.parse(in)) {
7272
recordCount++;

0 commit comments

Comments
 (0)