Skip to content

Commit f9a3162

Browse files
committed
Use "Character" as the postfix is ivar names. Use the method name pattern isFooSet() for ivar "foo" for methods that test foo for null (foo != null).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1612352 13f79535-47bb-0310-9956-ffa450edef68
1 parent a72c71f commit f9a3162

8 files changed

Lines changed: 118 additions & 118 deletions

File tree

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

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

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ private void print(final Object object, final CharSequence value,
118118
if (!newRecord) {
119119
out.append(format.getDelimiter());
120120
}
121-
if (format.isQuoting()) {
121+
if (format.isQuoteCharacterSet()) {
122122
// the original object is needed so can check for Number
123123
printAndQuote(object, value, offset, len);
124-
} else if (format.isEscaping()) {
124+
} else if (format.isEscapeCharacterSet()) {
125125
printAndEscape(value, offset, len);
126126
} else {
127127
out.append(value, offset, offset + len);
@@ -138,7 +138,7 @@ private void printAndEscape(final CharSequence value, final int offset, final in
138138
final int end = offset + len;
139139

140140
final char delim = format.getDelimiter();
141-
final char escape = format.getEscape().charValue();
141+
final char escape = format.getEscapeCharacter().charValue();
142142

143143
while (pos < end) {
144144
char c = value.charAt(pos);
@@ -180,7 +180,7 @@ private void printAndQuote(final Object object, final CharSequence value,
180180
final int end = offset + len;
181181

182182
final char delimChar = format.getDelimiter();
183-
final char quoteChar = format.getQuoteChar().charValue();
183+
final char quoteChar = format.getQuoteCharacter().charValue();
184184

185185
QuoteMode quoteModePolicy = format.getQuoteMode();
186186
if (quoteModePolicy == null) {
@@ -297,13 +297,13 @@ private void printAndQuote(final Object object, final CharSequence value,
297297
* If an I/O error occurs
298298
*/
299299
public void printComment(final String comment) throws IOException {
300-
if (!format.isCommentingEnabled()) {
300+
if (!format.isCommentStartCharacterSet()) {
301301
return;
302302
}
303303
if (!newRecord) {
304304
println();
305305
}
306-
out.append(format.getCommentStart().charValue());
306+
out.append(format.getCommentStartCharacter().charValue());
307307
out.append(SP);
308308
for (int i = 0; i < comment.length(); i++) {
309309
final char c = comment.charAt(i);
@@ -315,7 +315,7 @@ public void printComment(final String comment) throws IOException {
315315
//$FALL-THROUGH$ break intentionally excluded.
316316
case LF:
317317
println();
318-
out.append(format.getCommentStart().charValue());
318+
out.append(format.getCommentStartCharacter().charValue());
319319
out.append(SP);
320320
break;
321321
default:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ final class Lexer implements Closeable {
6262
Lexer(final CSVFormat format, final ExtendedBufferedReader reader) {
6363
this.reader = reader;
6464
this.delimiter = format.getDelimiter();
65-
this.escape = mapNullToDisabled(format.getEscape());
66-
this.quoteChar = mapNullToDisabled(format.getQuoteChar());
67-
this.commentStart = mapNullToDisabled(format.getCommentStart());
65+
this.escape = mapNullToDisabled(format.getEscapeCharacter());
66+
this.quoteChar = mapNullToDisabled(format.getQuoteCharacter());
67+
this.commentStart = mapNullToDisabled(format.getCommentStartCharacter());
6868
this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
6969
this.ignoreEmptyLines = format.getIgnoreEmptyLines();
7070
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testCSVFile() throws Exception {
9090
final String[] split = line.split(" ");
9191
assertTrue(testName+" require 1 param", split.length >= 1);
9292
// first line starts with csv data file name
93-
CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('"');
93+
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
9494
boolean checkComments = false;
9595
for(int i=1; i < split.length; i++) {
9696
final String option = split[i];
@@ -134,7 +134,7 @@ public void testCSVUrl() throws Exception {
134134
final String[] split = line.split(" ");
135135
assertTrue(testName + " require 1 param", split.length >= 1);
136136
// first line starts with csv data file name
137-
CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('"');
137+
CSVFormat format = CSVFormat.newFormat(',').withQuote('"');
138138
boolean checkComments = false;
139139
for (int i = 1; i < split.length; i++) {
140140
final String option = split[i];

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void testEquals() {
8686
@Test
8787
public void testEqualsCommentStart() {
8888
final CSVFormat right = CSVFormat.newFormat('\'')
89-
.withQuoteChar('"')
89+
.withQuote('"')
9090
.withCommentMarker('#')
9191
.withQuoteMode(QuoteMode.ALL);
9292
final CSVFormat left = right
@@ -106,7 +106,7 @@ public void testEqualsDelimiter() {
106106
@Test
107107
public void testEqualsEscape() {
108108
final CSVFormat right = CSVFormat.newFormat('\'')
109-
.withQuoteChar('"')
109+
.withQuote('"')
110110
.withCommentMarker('#')
111111
.withEscape('+')
112112
.withQuoteMode(QuoteMode.ALL);
@@ -125,7 +125,7 @@ public void testEqualsHeader() {
125125
.withHeader("One", "Two", "Three")
126126
.withIgnoreEmptyLines(true)
127127
.withIgnoreSurroundingSpaces(true)
128-
.withQuoteChar('"')
128+
.withQuote('"')
129129
.withQuoteMode(QuoteMode.ALL);
130130
final CSVFormat left = right
131131
.withHeader("Three", "Two", "One");
@@ -140,7 +140,7 @@ public void testEqualsIgnoreEmptyLines() {
140140
.withEscape('+')
141141
.withIgnoreEmptyLines(true)
142142
.withIgnoreSurroundingSpaces(true)
143-
.withQuoteChar('"')
143+
.withQuote('"')
144144
.withQuoteMode(QuoteMode.ALL);
145145
final CSVFormat left = right
146146
.withIgnoreEmptyLines(false);
@@ -154,7 +154,7 @@ public void testEqualsIgnoreSurroundingSpaces() {
154154
.withCommentMarker('#')
155155
.withEscape('+')
156156
.withIgnoreSurroundingSpaces(true)
157-
.withQuoteChar('"')
157+
.withQuote('"')
158158
.withQuoteMode(QuoteMode.ALL);
159159
final CSVFormat left = right
160160
.withIgnoreSurroundingSpaces(false);
@@ -164,16 +164,16 @@ public void testEqualsIgnoreSurroundingSpaces() {
164164

165165
@Test
166166
public void testEqualsQuoteChar() {
167-
final CSVFormat right = CSVFormat.newFormat('\'').withQuoteChar('"');
168-
final CSVFormat left = right.withQuoteChar('!');
167+
final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"');
168+
final CSVFormat left = right.withQuote('!');
169169

170170
assertNotEquals(right, left);
171171
}
172172

173173
@Test
174174
public void testEqualsQuotePolicy() {
175175
final CSVFormat right = CSVFormat.newFormat('\'')
176-
.withQuoteChar('"')
176+
.withQuote('"')
177177
.withQuoteMode(QuoteMode.ALL);
178178
final CSVFormat left = right
179179
.withQuoteMode(QuoteMode.MINIMAL);
@@ -189,7 +189,7 @@ public void testEqualsRecordSeparator() {
189189
.withEscape('+')
190190
.withIgnoreEmptyLines(true)
191191
.withIgnoreSurroundingSpaces(true)
192-
.withQuoteChar('"')
192+
.withQuote('"')
193193
.withQuoteMode(QuoteMode.ALL);
194194
final CSVFormat left = right
195195
.withRecordSeparator(LF);
@@ -205,7 +205,7 @@ public void testEqualsNullString() {
205205
.withEscape('+')
206206
.withIgnoreEmptyLines(true)
207207
.withIgnoreSurroundingSpaces(true)
208-
.withQuoteChar('"')
208+
.withQuote('"')
209209
.withQuoteMode(QuoteMode.ALL)
210210
.withNullString("null");
211211
final CSVFormat left = right
@@ -222,7 +222,7 @@ public void testEqualsSkipHeaderRecord() {
222222
.withEscape('+')
223223
.withIgnoreEmptyLines(true)
224224
.withIgnoreSurroundingSpaces(true)
225-
.withQuoteChar('"')
225+
.withQuote('"')
226226
.withQuoteMode(QuoteMode.ALL)
227227
.withNullString("null")
228228
.withSkipHeaderRecord(true);
@@ -275,18 +275,18 @@ public void testNullRecordSeparatorCsv106() {
275275

276276
@Test(expected = IllegalArgumentException.class)
277277
public void testQuoteCharSameAsCommentStartThrowsException() {
278-
CSVFormat.DEFAULT.withQuoteChar('!').withCommentMarker('!');
278+
CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!');
279279
}
280280

281281
@Test(expected = IllegalArgumentException.class)
282282
public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
283283
// Cannot assume that callers won't use different Character objects
284-
CSVFormat.DEFAULT.withQuoteChar(new Character('!')).withCommentMarker('!');
284+
CSVFormat.DEFAULT.withQuote(new Character('!')).withCommentMarker('!');
285285
}
286286

287287
@Test(expected = IllegalArgumentException.class)
288288
public void testQuoteCharSameAsDelimiterThrowsException() {
289-
CSVFormat.DEFAULT.withQuoteChar('!').withDelimiter('!');
289+
CSVFormat.DEFAULT.withQuote('!').withDelimiter('!');
290290
}
291291

292292
@Test(expected = IllegalArgumentException.class)
@@ -296,11 +296,11 @@ public void testQuotePolicyNoneWithoutEscapeThrowsException() {
296296

297297
@Test
298298
public void testRFC4180() {
299-
assertEquals(null, RFC4180.getCommentStart());
299+
assertEquals(null, RFC4180.getCommentStartCharacter());
300300
assertEquals(',', RFC4180.getDelimiter());
301-
assertEquals(null, RFC4180.getEscape());
301+
assertEquals(null, RFC4180.getEscapeCharacter());
302302
assertFalse(RFC4180.getIgnoreEmptyLines());
303-
assertEquals(Character.valueOf('"'), RFC4180.getQuoteChar());
303+
assertEquals(Character.valueOf('"'), RFC4180.getQuoteCharacter());
304304
assertEquals(null, RFC4180.getQuoteMode());
305305
assertEquals("\r\n", RFC4180.getRecordSeparator());
306306
}
@@ -320,18 +320,18 @@ public void testSerialization() throws Exception {
320320

321321
assertNotNull(format);
322322
assertEquals("delimiter", CSVFormat.DEFAULT.getDelimiter(), format.getDelimiter());
323-
assertEquals("encapsulator", CSVFormat.DEFAULT.getQuoteChar(), format.getQuoteChar());
324-
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStart(), format.getCommentStart());
323+
assertEquals("encapsulator", CSVFormat.DEFAULT.getQuoteCharacter(), format.getQuoteCharacter());
324+
assertEquals("comment start", CSVFormat.DEFAULT.getCommentStartCharacter(), format.getCommentStartCharacter());
325325
assertEquals("record separator", CSVFormat.DEFAULT.getRecordSeparator(), format.getRecordSeparator());
326-
assertEquals("escape", CSVFormat.DEFAULT.getEscape(), format.getEscape());
326+
assertEquals("escape", CSVFormat.DEFAULT.getEscapeCharacter(), format.getEscapeCharacter());
327327
assertEquals("trim", CSVFormat.DEFAULT.getIgnoreSurroundingSpaces(), format.getIgnoreSurroundingSpaces());
328328
assertEquals("empty lines", CSVFormat.DEFAULT.getIgnoreEmptyLines(), format.getIgnoreEmptyLines());
329329
}
330330

331331
@Test
332332
public void testWithCommentStart() throws Exception {
333333
final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentMarker('#');
334-
assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentStart());
334+
assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentStartCharacter());
335335
}
336336

337337
@Test(expected = IllegalArgumentException.class)
@@ -353,7 +353,7 @@ public void testWithDelimiterLFThrowsException() {
353353
@Test
354354
public void testWithEscape() throws Exception {
355355
final CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&');
356-
assertEquals(Character.valueOf('&'), formatWithEscape.getEscape());
356+
assertEquals(Character.valueOf('&'), formatWithEscape.getEscapeCharacter());
357357
}
358358

359359
@Test(expected = IllegalArgumentException.class)
@@ -394,13 +394,13 @@ public void testWithNullString() throws Exception {
394394

395395
@Test
396396
public void testWithQuoteChar() throws Exception {
397-
final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuoteChar('"');
398-
assertEquals(Character.valueOf('"'), formatWithQuoteChar.getQuoteChar());
397+
final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuote('"');
398+
assertEquals(Character.valueOf('"'), formatWithQuoteChar.getQuoteCharacter());
399399
}
400400

401401
@Test(expected = IllegalArgumentException.class)
402402
public void testWithQuoteLFThrowsException() {
403-
CSVFormat.DEFAULT.withQuoteChar(LF);
403+
CSVFormat.DEFAULT.withQuote(LF);
404404
}
405405

406406
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testBackslashEscaping() throws IOException {
112112
};
113113

114114

115-
final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'')
115+
final CSVFormat format = CSVFormat.newFormat(',').withQuote('\'')
116116
.withRecordSeparator(CRLF).withEscape('/').withIgnoreEmptyLines(true);
117117

118118
final CSVParser parser = CSVParser.parse(code, format);
@@ -274,7 +274,7 @@ public void testDefaultFormat() throws IOException {
274274
};
275275

276276
CSVFormat format = CSVFormat.DEFAULT;
277-
assertFalse(format.isCommentingEnabled());
277+
assertFalse(format.isCommentStartCharacterSet());
278278

279279
CSVParser parser = CSVParser.parse(code, format);
280280
List<CSVRecord> records = parser.getRecords();

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public void testRandom() throws Exception {
378378
@Test
379379
public void testPlainQuoted() throws IOException {
380380
final StringWriter sw = new StringWriter();
381-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar('\''));
381+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''));
382382
printer.print("abc");
383383
assertEquals("abc", sw.toString());
384384
printer.close();
@@ -397,7 +397,7 @@ public void testSingleLineComment() throws IOException {
397397
@Test
398398
public void testSingleQuoteQuoted() throws IOException {
399399
final StringWriter sw = new StringWriter();
400-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar('\''));
400+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''));
401401
printer.print("a'b'c");
402402
printer.print("xyz");
403403
assertEquals("'a''b''c',xyz", sw.toString());
@@ -407,7 +407,7 @@ public void testSingleQuoteQuoted() throws IOException {
407407
@Test
408408
public void testDelimeterQuoted() throws IOException {
409409
final StringWriter sw = new StringWriter();
410-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar('\''));
410+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''));
411411
printer.print("a,b,c");
412412
printer.print("xyz");
413413
assertEquals("'a,b,c',xyz", sw.toString());
@@ -428,7 +428,7 @@ public void testDelimeterQuoteNONE() throws IOException {
428428
@Test
429429
public void testEOLQuoted() throws IOException {
430430
final StringWriter sw = new StringWriter();
431-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar('\''));
431+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''));
432432
printer.print("a\rb\nc");
433433
printer.print("x\by\fz");
434434
assertEquals("'a\rb\nc',x\by\fz", sw.toString());
@@ -438,7 +438,7 @@ public void testEOLQuoted() throws IOException {
438438
@Test
439439
public void testPlainEscaped() throws IOException {
440440
final StringWriter sw = new StringWriter();
441-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null).withEscape('!'));
441+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null).withEscape('!'));
442442
printer.print("abc");
443443
printer.print("xyz");
444444
assertEquals("abc,xyz", sw.toString());
@@ -448,7 +448,7 @@ public void testPlainEscaped() throws IOException {
448448
@Test
449449
public void testDelimiterEscaped() throws IOException {
450450
final StringWriter sw = new StringWriter();
451-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape('!').withQuoteChar(null));
451+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape('!').withQuote(null));
452452
printer.print("a,b,c");
453453
printer.print("xyz");
454454
assertEquals("a!,b!,c,xyz", sw.toString());
@@ -458,7 +458,7 @@ public void testDelimiterEscaped() throws IOException {
458458
@Test
459459
public void testEOLEscaped() throws IOException {
460460
final StringWriter sw = new StringWriter();
461-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null).withEscape('!'));
461+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null).withEscape('!'));
462462
printer.print("a\rb\nc");
463463
printer.print("x\fy\bz");
464464
assertEquals("a!rb!nc,x\fy\bz", sw.toString());
@@ -468,7 +468,7 @@ public void testEOLEscaped() throws IOException {
468468
@Test
469469
public void testPlainPlain() throws IOException {
470470
final StringWriter sw = new StringWriter();
471-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null));
471+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null));
472472
printer.print("abc");
473473
printer.print("xyz");
474474
assertEquals("abc,xyz", sw.toString());
@@ -478,7 +478,7 @@ public void testPlainPlain() throws IOException {
478478
@Test
479479
public void testDelimiterPlain() throws IOException {
480480
final StringWriter sw = new StringWriter();
481-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null));
481+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null));
482482
printer.print("a,b,c");
483483
printer.print("xyz");
484484
assertEquals("a,b,c,xyz", sw.toString());
@@ -488,7 +488,7 @@ public void testDelimiterPlain() throws IOException {
488488
@Test
489489
public void testHeader() throws IOException {
490490
final StringWriter sw = new StringWriter();
491-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null)
491+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null)
492492
.withHeader("C1", "C2", "C3"));
493493
printer.printRecord("a", "b", "c");
494494
printer.printRecord("x", "y", "z");
@@ -499,7 +499,7 @@ public void testHeader() throws IOException {
499499
@Test
500500
public void testEOLPlain() throws IOException {
501501
final StringWriter sw = new StringWriter();
502-
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteChar(null));
502+
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null));
503503
printer.print("a\rb\nc");
504504
printer.print("x\fy\bz");
505505
assertEquals("a\rb\nc,x\fy\bz", sw.toString());

0 commit comments

Comments
 (0)