Skip to content

Commit 75f39a8

Browse files
committed
[CSV-99] Revert Builder implementation in CSVFormat.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1508470 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7dbc976 commit 75f39a8

10 files changed

Lines changed: 530 additions & 738 deletions

File tree

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

Lines changed: 282 additions & 427 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
* <pre>
4444
* Reader in = new StringReader(&quot;a\tb\nc\td&quot;);
45-
* Iterable&lt;CSVRecord&gt; parser = CSVFormat.newBuilder()
45+
* Iterable&lt;CSVRecord&gt; parser = CSVFormat.DEFAULT
4646
* .withCommentStart('#')
4747
* .withDelimiter('\t')
4848
* .withQuoteChar('"').parse(in);
@@ -120,8 +120,9 @@ public CSVParser(final Reader input) throws IOException {
120120
* If an I/O error occurs
121121
*/
122122
public CSVParser(final Reader input, final CSVFormat format) throws IOException {
123-
this.lexer = new CSVLexer(format, new ExtendedBufferedReader(input));
123+
format.validate();
124124
this.format = format;
125+
this.lexer = new CSVLexer(format, new ExtendedBufferedReader(input));
125126
this.headerMap = initializeHeader();
126127
}
127128

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class CSVPrinter implements Flushable, Closeable {
5858
public CSVPrinter(final Appendable out, final CSVFormat format) {
5959
this.out = out;
6060
this.format = format == null ? CSVFormat.DEFAULT : format;
61+
format.validate();
6162
}
6263

6364
// ======================================================

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Collection;
3333
import java.util.List;
3434

35-
import org.apache.commons.csv.CSVFormat.CSVFormatBuilder;
3635
import org.junit.Test;
3736
import org.junit.runner.RunWith;
3837
import org.junit.runners.Parameterized;
@@ -90,18 +89,17 @@ public void testCSVFile() throws Exception {
9089
assertTrue(testName+" require 1 param", split.length >= 1);
9190
// first line starts with csv data file name
9291
final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0])));
93-
final CSVFormatBuilder builder = CSVFormat.newBuilder(',').withQuoteChar('"');
94-
CSVFormat format = builder.build();
92+
CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('"');
9593
boolean checkComments = false;
9694
for(int i=1; i < split.length; i++) {
9795
final String option = split[i];
9896
final String[] option_parts = option.split("=",2);
9997
if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])){
100-
format = builder.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1])).build();
98+
format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1]));
10199
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
102-
format = builder.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1])).build();
100+
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
103101
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
104-
format = builder.withCommentStart(option_parts[1].charAt(0)).build();
102+
format = format.withCommentStart(option_parts[1].charAt(0));
105103
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
106104
checkComments = true;
107105
} else {

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

Lines changed: 0 additions & 202 deletions
This file was deleted.

0 commit comments

Comments
 (0)