Skip to content

Commit 152d50c

Browse files
committed
Remove type names from static factory APIs in org.apache.commons.csv.CSVParser.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1511883 13f79535-47bb-0310-9956-ffa450edef68
1 parent a36bbff commit 152d50c

5 files changed

Lines changed: 36 additions & 36 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
103103
* @throws IOException
104104
* If an I/O error occurs
105105
*/
106-
public static CSVParser parseFile(File file, final CSVFormat format) throws IOException {
106+
public static CSVParser parse(File file, final CSVFormat format) throws IOException {
107107
return new CSVParser(new FileReader(file), format);
108108
}
109109

@@ -126,13 +126,13 @@ public static CSVParser parseFile(File file, final CSVFormat format) throws IOEx
126126
* @throws IOException
127127
* If an I/O error occurs
128128
*/
129-
public static CSVParser parseResource(String resource, Charset charset, ClassLoader classLoader,
129+
public static CSVParser parse(String resource, Charset charset, ClassLoader classLoader,
130130
final CSVFormat format) throws IOException {
131131
final URL url = classLoader.getResource(resource);
132132
if (url == null) {
133133
throw new IllegalArgumentException("Resource cannot be found: " + resource);
134134
}
135-
return parseURL(url, charset, format);
135+
return parse(url, charset, format);
136136
}
137137

138138
/**
@@ -152,12 +152,12 @@ public static CSVParser parseResource(String resource, Charset charset, ClassLoa
152152
* @throws IOException
153153
* If an I/O error occurs
154154
*/
155-
public static CSVParser parseResource(String resource, Charset charset, final CSVFormat format) throws IOException {
155+
public static CSVParser parse(String resource, Charset charset, final CSVFormat format) throws IOException {
156156
final URL url = ClassLoader.getSystemResource(resource);
157157
if (url == null) {
158158
throw new IllegalArgumentException("System resource cannot be found: " + resource);
159159
}
160-
return parseURL(url, charset, format);
160+
return parse(url, charset, format);
161161
}
162162

163163
/**
@@ -171,7 +171,7 @@ public static CSVParser parseResource(String resource, Charset charset, final CS
171171
* @throws IOException
172172
* If an I/O error occurs
173173
*/
174-
public static CSVParser parseString(String string, final CSVFormat format) throws IOException {
174+
public static CSVParser parse(String string, final CSVFormat format) throws IOException {
175175
return new CSVParser(new StringReader(string), format);
176176
}
177177

@@ -194,7 +194,7 @@ public static CSVParser parseString(String string, final CSVFormat format) throw
194194
* @throws IOException
195195
* If an I/O error occurs
196196
*/
197-
public static CSVParser parseURL(URL url, Charset charset, final CSVFormat format) throws IOException {
197+
public static CSVParser parse(URL url, Charset charset, final CSVFormat format) throws IOException {
198198
return new CSVParser(new InputStreamReader(url.openStream(),
199199
charset == null ? Charset.forName("UTF-8") : charset), format);
200200
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void testCSVFile() throws Exception {
111111

112112
// Now parse the file and compare against the expected results
113113
// We use a buffered reader internally so no need to create one here.
114-
final CSVParser parser = CSVParser.parseFile(new File(BASE, split[0]), format);
114+
final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), format);
115115
for(final CSVRecord record : parser) {
116116
String parsed = record.toString();
117117
if (checkComments) {
@@ -153,7 +153,7 @@ public void testCSVResource() throws Exception {
153153
assertEquals(testName + " Expected format ", line, format.toString());
154154

155155
// Now parse the file and compare against the expected results
156-
final CSVParser parser = CSVParser.parseResource("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
156+
final CSVParser parser = CSVParser.parse("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
157157
this.getClass().getClassLoader(), format);
158158
for (final CSVRecord record : parser) {
159159
String parsed = record.toString();

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class CSVParserTest {
7070

7171
@Test
7272
public void testGetLine() throws IOException {
73-
final CSVParser parser = CSVParser.parseString(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
73+
final CSVParser parser = CSVParser.parse(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
7474
for (final String[] re : RESULT) {
7575
assertArrayEquals(re, parser.nextRecord().values());
7676
}
@@ -80,7 +80,7 @@ public void testGetLine() throws IOException {
8080

8181
@Test
8282
public void testGetRecords() throws IOException {
83-
final CSVParser parser = CSVParser.parseString(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
83+
final CSVParser parser = CSVParser.parse(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
8484
final List<CSVRecord> records = parser.getRecords();
8585
assertEquals(RESULT.length, records.size());
8686
assertTrue(records.size() > 0);
@@ -101,7 +101,7 @@ public void testExcelFormat1() throws IOException {
101101
{""},
102102
{"\"hello\"", " \"world\"", "abc\ndef", ""}
103103
};
104-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
104+
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
105105
final List<CSVRecord> records = parser.getRecords();
106106
assertEquals(res.length, records.size());
107107
assertTrue(records.size() > 0);
@@ -120,7 +120,7 @@ public void testExcelFormat2() throws Exception {
120120
{""},
121121
{"world", ""}
122122
};
123-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
123+
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
124124
final List<CSVRecord> records = parser.getRecords();
125125
assertEquals(res.length, records.size());
126126
assertTrue(records.size() > 0);
@@ -148,7 +148,7 @@ public void testEndOfFileBehaviourExcel() throws Exception {
148148
};
149149

150150
for (final String code : codes) {
151-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
151+
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
152152
final List<CSVRecord> records = parser.getRecords();
153153
assertEquals(res.length, records.size());
154154
assertTrue(records.size() > 0);
@@ -175,7 +175,7 @@ public void testEndOfFileBehaviorCSV() throws Exception {
175175
{"world", ""}
176176
};
177177
for (final String code : codes) {
178-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
178+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
179179
final List<CSVRecord> records = parser.getRecords();
180180
assertEquals(res.length, records.size());
181181
assertTrue(records.size() > 0);
@@ -199,7 +199,7 @@ public void testEmptyLineBehaviourExcel() throws Exception {
199199
{""}
200200
};
201201
for (final String code : codes) {
202-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
202+
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
203203
final List<CSVRecord> records = parser.getRecords();
204204
assertEquals(res.length, records.size());
205205
assertTrue(records.size() > 0);
@@ -221,7 +221,7 @@ public void testEmptyLineBehaviourCSV() throws Exception {
221221
{"hello", ""} // CSV format ignores empty lines
222222
};
223223
for (final String code : codes) {
224-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
224+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
225225
final List<CSVRecord> records = parser.getRecords();
226226
assertEquals(res.length, records.size());
227227
assertTrue(records.size() > 0);
@@ -233,13 +233,13 @@ public void testEmptyLineBehaviourCSV() throws Exception {
233233

234234
@Test
235235
public void testEmptyFile() throws Exception {
236-
final CSVParser parser = CSVParser.parseString("", CSVFormat.DEFAULT);
236+
final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
237237
assertNull(parser.nextRecord());
238238
}
239239

240240
@Test
241241
public void testCSV57() throws Exception {
242-
final CSVParser parser = CSVParser.parseString("", CSVFormat.DEFAULT);
242+
final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
243243
final List<CSVRecord> list = parser.getRecords();
244244
assertNotNull(list);
245245
assertEquals(0, list.size());
@@ -269,7 +269,7 @@ public void testBackslashEscapingOld() throws IOException {
269269
{"a\\", "b"}, // a backslash must be returnd
270270
{"a\\\\,b"} // backslash in quotes only escapes a delimiter (",")
271271
};
272-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
272+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
273273
final List<CSVRecord> records = parser.getRecords();
274274
assertEquals(res.length, records.size());
275275
assertTrue(records.size() > 0);
@@ -314,7 +314,7 @@ public void testBackslashEscaping() throws IOException {
314314
final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'')
315315
.withRecordSeparator(CRLF).withEscape('/').withIgnoreEmptyLines(true);
316316

317-
final CSVParser parser = CSVParser.parseString(code, format);
317+
final CSVParser parser = CSVParser.parse(code, format);
318318
final List<CSVRecord> records = parser.getRecords();
319319
assertTrue(records.size() > 0);
320320

@@ -343,7 +343,7 @@ public void testBackslashEscaping2() throws IOException {
343343
final CSVFormat format = CSVFormat.newFormat(',')
344344
.withRecordSeparator(CRLF).withEscape('/').withIgnoreEmptyLines(true);
345345

346-
final CSVParser parser = CSVParser.parseString(code, format);
346+
final CSVParser parser = CSVParser.parse(code, format);
347347
final List<CSVRecord> records = parser.getRecords();
348348
assertTrue(records.size() > 0);
349349

@@ -368,7 +368,7 @@ public void testDefaultFormat() throws IOException {
368368
CSVFormat format = CSVFormat.DEFAULT;
369369
assertFalse(format.isCommentingEnabled());
370370

371-
CSVParser parser = CSVParser.parseString(code, format);
371+
CSVParser parser = CSVParser.parse(code, format);
372372
List<CSVRecord> records = parser.getRecords();
373373
assertTrue(records.size() > 0);
374374

@@ -380,7 +380,7 @@ public void testDefaultFormat() throws IOException {
380380
};
381381

382382
format = CSVFormat.DEFAULT.withCommentStart('#');
383-
parser = CSVParser.parseString(code, format);
383+
parser = CSVParser.parse(code, format);
384384
records = parser.getRecords();
385385

386386
Utils.compare("Failed to parse with comments", res_comments, records);
@@ -389,7 +389,7 @@ public void testDefaultFormat() throws IOException {
389389
@Test
390390
public void testCarriageReturnLineFeedEndings() throws IOException {
391391
final String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu";
392-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
392+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
393393
final List<CSVRecord> records = parser.getRecords();
394394
assertEquals(4, records.size());
395395
}
@@ -408,15 +408,15 @@ public void testClose() throws Exception {
408408
@Test
409409
public void testCarriageReturnEndings() throws IOException {
410410
final String code = "foo\rbaar,\rhello,world\r,kanu";
411-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
411+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
412412
final List<CSVRecord> records = parser.getRecords();
413413
assertEquals(4, records.size());
414414
}
415415

416416
@Test
417417
public void testLineFeedEndings() throws IOException {
418418
final String code = "foo\nbaar,\nhello,world\n,kanu";
419-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
419+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
420420
final List<CSVRecord> records = parser.getRecords();
421421
assertEquals(4, records.size());
422422
}
@@ -426,7 +426,7 @@ public void testIgnoreEmptyLines() throws IOException {
426426
final String code = "\nfoo,baar\n\r\n,\n\n,world\r\n\n";
427427
//String code = "world\r\n\n";
428428
//String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n";
429-
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
429+
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
430430
final List<CSVRecord> records = parser.getRecords();
431431
assertEquals(3, records.size());
432432
}
@@ -452,7 +452,7 @@ public void testRoundtrip() throws Exception {
452452
final StringWriter out = new StringWriter();
453453
final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT);
454454
final String input = "a,b,c\r\n1,2,3\r\nx,y,z\r\n";
455-
for (final CSVRecord record : CSVParser.parseString(input, CSVFormat.DEFAULT)) {
455+
for (final CSVRecord record : CSVParser.parse(input, CSVFormat.DEFAULT)) {
456456
printer.printRecord(record);
457457
}
458458
assertEquals(input, out.toString());
@@ -622,7 +622,7 @@ record = records.next();
622622

623623
@Test
624624
public void testGetHeaderMap() throws Exception {
625-
final CSVParser parser = CSVParser.parseString("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
625+
final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
626626
final Map<String, Integer> headerMap = parser.getHeaderMap();
627627
final Iterator<String> columnNames = headerMap.keySet().iterator();
628628
// Headers are iterated in column order.
@@ -665,7 +665,7 @@ public void testGetRecordNumberWithLF() throws Exception {
665665

666666
@Test
667667
public void testGetRecordWithMultiiLineValues() throws Exception {
668-
final CSVParser parser = CSVParser.parseString("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"",
668+
final CSVParser parser = CSVParser.parse("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"",
669669
CSVFormat.DEFAULT.withRecordSeparator(CRLF));
670670
CSVRecord record;
671671
assertEquals(0, parser.getRecordNumber());
@@ -704,7 +704,7 @@ public void testInvalidFormat() throws Exception {
704704
}
705705

706706
private void validateRecordNumbers(final String lineSeparator) throws IOException {
707-
final CSVParser parser = CSVParser.parseString("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
707+
final CSVParser parser = CSVParser.parse("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
708708
CSVRecord record;
709709
assertEquals(0, parser.getRecordNumber());
710710
assertNotNull(record = parser.nextRecord());
@@ -721,7 +721,7 @@ private void validateRecordNumbers(final String lineSeparator) throws IOExceptio
721721
}
722722

723723
private void validateLineNumbers(final String lineSeparator) throws IOException {
724-
final CSVParser parser = CSVParser.parseString("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
724+
final CSVParser parser = CSVParser.parse("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
725725
assertEquals(0, parser.getCurrentLineNumber());
726726
assertNotNull(parser.nextRecord());
727727
assertEquals(1, parser.getCurrentLineNumber());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void doOneRandom(final CSVFormat format) throws Exception {
8585
final String result = sw.toString();
8686
// System.out.println("### :" + printable(result));
8787

88-
final CSVParser parser = CSVParser.parseString(result, format);
88+
final CSVParser parser = CSVParser.parse(result, format);
8989
final List<CSVRecord> parseResult = parser.getRecords();
9090

9191
Utils.compare("Printer output :" + printable(result), lines, parseResult);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private enum ContractColumnNames {
4242

4343
@Test
4444
public void testContractFile() throws IOException {
45-
final CSVParser parser = CSVParser.parseResource("ferc.gov/contract.txt", US_ASCII,
45+
final CSVParser parser = CSVParser.parse("ferc.gov/contract.txt", US_ASCII,
4646
CSVFormat.DEFAULT.withHeader());
4747
try {
4848
final List<CSVRecord> records = parser.getRecords();
@@ -65,7 +65,7 @@ record = records.get(records.size() - 1);
6565

6666
@Test
6767
public void testTransactionFile() throws IOException {
68-
final CSVParser parser = CSVParser.parseResource("ferc.gov/transaction.txt", US_ASCII,
68+
final CSVParser parser = CSVParser.parse("ferc.gov/transaction.txt", US_ASCII,
6969
CSVFormat.DEFAULT.withHeader());
7070
try {
7171
final List<CSVRecord> records = parser.getRecords();

0 commit comments

Comments
 (0)