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
This commit is contained in:
parent
a36bbffdd3
commit
152d50c4f7
|
@ -103,7 +103,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static CSVParser parseFile(File file, final CSVFormat format) throws IOException {
|
||||
public static CSVParser parse(File file, final CSVFormat format) throws IOException {
|
||||
return new CSVParser(new FileReader(file), format);
|
||||
}
|
||||
|
||||
|
@ -126,13 +126,13 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static CSVParser parseResource(String resource, Charset charset, ClassLoader classLoader,
|
||||
public static CSVParser parse(String resource, Charset charset, ClassLoader classLoader,
|
||||
final CSVFormat format) throws IOException {
|
||||
final URL url = classLoader.getResource(resource);
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("Resource cannot be found: " + resource);
|
||||
}
|
||||
return parseURL(url, charset, format);
|
||||
return parse(url, charset, format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,12 +152,12 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static CSVParser parseResource(String resource, Charset charset, final CSVFormat format) throws IOException {
|
||||
public static CSVParser parse(String resource, Charset charset, final CSVFormat format) throws IOException {
|
||||
final URL url = ClassLoader.getSystemResource(resource);
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("System resource cannot be found: " + resource);
|
||||
}
|
||||
return parseURL(url, charset, format);
|
||||
return parse(url, charset, format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,7 +171,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static CSVParser parseString(String string, final CSVFormat format) throws IOException {
|
||||
public static CSVParser parse(String string, final CSVFormat format) throws IOException {
|
||||
return new CSVParser(new StringReader(string), format);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
|||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static CSVParser parseURL(URL url, Charset charset, final CSVFormat format) throws IOException {
|
||||
public static CSVParser parse(URL url, Charset charset, final CSVFormat format) throws IOException {
|
||||
return new CSVParser(new InputStreamReader(url.openStream(),
|
||||
charset == null ? Charset.forName("UTF-8") : charset), format);
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class CSVFileParserTest {
|
|||
|
||||
// Now parse the file and compare against the expected results
|
||||
// We use a buffered reader internally so no need to create one here.
|
||||
final CSVParser parser = CSVParser.parseFile(new File(BASE, split[0]), format);
|
||||
final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), format);
|
||||
for(final CSVRecord record : parser) {
|
||||
String parsed = record.toString();
|
||||
if (checkComments) {
|
||||
|
@ -153,7 +153,7 @@ public class CSVFileParserTest {
|
|||
assertEquals(testName + " Expected format ", line, format.toString());
|
||||
|
||||
// Now parse the file and compare against the expected results
|
||||
final CSVParser parser = CSVParser.parseResource("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
|
||||
final CSVParser parser = CSVParser.parse("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
|
||||
this.getClass().getClassLoader(), format);
|
||||
for (final CSVRecord record : parser) {
|
||||
String parsed = record.toString();
|
||||
|
|
|
@ -70,7 +70,7 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testGetLine() throws IOException {
|
||||
final CSVParser parser = CSVParser.parseString(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
|
||||
final CSVParser parser = CSVParser.parse(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
|
||||
for (final String[] re : RESULT) {
|
||||
assertArrayEquals(re, parser.nextRecord().values());
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testGetRecords() throws IOException {
|
||||
final CSVParser parser = CSVParser.parseString(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
|
||||
final CSVParser parser = CSVParser.parse(CSVINPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(true));
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(RESULT.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -101,7 +101,7 @@ public class CSVParserTest {
|
|||
{""},
|
||||
{"\"hello\"", " \"world\"", "abc\ndef", ""}
|
||||
};
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -120,7 +120,7 @@ public class CSVParserTest {
|
|||
{""},
|
||||
{"world", ""}
|
||||
};
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -148,7 +148,7 @@ public class CSVParserTest {
|
|||
};
|
||||
|
||||
for (final String code : codes) {
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -175,7 +175,7 @@ public class CSVParserTest {
|
|||
{"world", ""}
|
||||
};
|
||||
for (final String code : codes) {
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -199,7 +199,7 @@ public class CSVParserTest {
|
|||
{""}
|
||||
};
|
||||
for (final String code : codes) {
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.EXCEL);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -221,7 +221,7 @@ public class CSVParserTest {
|
|||
{"hello", ""} // CSV format ignores empty lines
|
||||
};
|
||||
for (final String code : codes) {
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -233,13 +233,13 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testEmptyFile() throws Exception {
|
||||
final CSVParser parser = CSVParser.parseString("", CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
|
||||
assertNull(parser.nextRecord());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSV57() throws Exception {
|
||||
final CSVParser parser = CSVParser.parseString("", CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> list = parser.getRecords();
|
||||
assertNotNull(list);
|
||||
assertEquals(0, list.size());
|
||||
|
@ -269,7 +269,7 @@ public class CSVParserTest {
|
|||
{"a\\", "b"}, // a backslash must be returnd
|
||||
{"a\\\\,b"} // backslash in quotes only escapes a delimiter (",")
|
||||
};
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(res.length, records.size());
|
||||
assertTrue(records.size() > 0);
|
||||
|
@ -314,7 +314,7 @@ public class CSVParserTest {
|
|||
final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'')
|
||||
.withRecordSeparator(CRLF).withEscape('/').withIgnoreEmptyLines(true);
|
||||
|
||||
final CSVParser parser = CSVParser.parseString(code, format);
|
||||
final CSVParser parser = CSVParser.parse(code, format);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertTrue(records.size() > 0);
|
||||
|
||||
|
@ -343,7 +343,7 @@ public class CSVParserTest {
|
|||
final CSVFormat format = CSVFormat.newFormat(',')
|
||||
.withRecordSeparator(CRLF).withEscape('/').withIgnoreEmptyLines(true);
|
||||
|
||||
final CSVParser parser = CSVParser.parseString(code, format);
|
||||
final CSVParser parser = CSVParser.parse(code, format);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertTrue(records.size() > 0);
|
||||
|
||||
|
@ -368,7 +368,7 @@ public class CSVParserTest {
|
|||
CSVFormat format = CSVFormat.DEFAULT;
|
||||
assertFalse(format.isCommentingEnabled());
|
||||
|
||||
CSVParser parser = CSVParser.parseString(code, format);
|
||||
CSVParser parser = CSVParser.parse(code, format);
|
||||
List<CSVRecord> records = parser.getRecords();
|
||||
assertTrue(records.size() > 0);
|
||||
|
||||
|
@ -380,7 +380,7 @@ public class CSVParserTest {
|
|||
};
|
||||
|
||||
format = CSVFormat.DEFAULT.withCommentStart('#');
|
||||
parser = CSVParser.parseString(code, format);
|
||||
parser = CSVParser.parse(code, format);
|
||||
records = parser.getRecords();
|
||||
|
||||
Utils.compare("Failed to parse with comments", res_comments, records);
|
||||
|
@ -389,7 +389,7 @@ public class CSVParserTest {
|
|||
@Test
|
||||
public void testCarriageReturnLineFeedEndings() throws IOException {
|
||||
final String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu";
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(4, records.size());
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ public class CSVParserTest {
|
|||
@Test
|
||||
public void testCarriageReturnEndings() throws IOException {
|
||||
final String code = "foo\rbaar,\rhello,world\r,kanu";
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(4, records.size());
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class CSVParserTest {
|
|||
@Test
|
||||
public void testLineFeedEndings() throws IOException {
|
||||
final String code = "foo\nbaar,\nhello,world\n,kanu";
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(4, records.size());
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ public class CSVParserTest {
|
|||
final String code = "\nfoo,baar\n\r\n,\n\n,world\r\n\n";
|
||||
//String code = "world\r\n\n";
|
||||
//String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n";
|
||||
final CSVParser parser = CSVParser.parseString(code, CSVFormat.DEFAULT);
|
||||
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
assertEquals(3, records.size());
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ public class CSVParserTest {
|
|||
final StringWriter out = new StringWriter();
|
||||
final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT);
|
||||
final String input = "a,b,c\r\n1,2,3\r\nx,y,z\r\n";
|
||||
for (final CSVRecord record : CSVParser.parseString(input, CSVFormat.DEFAULT)) {
|
||||
for (final CSVRecord record : CSVParser.parse(input, CSVFormat.DEFAULT)) {
|
||||
printer.printRecord(record);
|
||||
}
|
||||
assertEquals(input, out.toString());
|
||||
|
@ -622,7 +622,7 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testGetHeaderMap() throws Exception {
|
||||
final CSVParser parser = CSVParser.parseString("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
|
||||
final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
|
||||
final Map<String, Integer> headerMap = parser.getHeaderMap();
|
||||
final Iterator<String> columnNames = headerMap.keySet().iterator();
|
||||
// Headers are iterated in column order.
|
||||
|
@ -665,7 +665,7 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testGetRecordWithMultiiLineValues() throws Exception {
|
||||
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\"",
|
||||
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\"",
|
||||
CSVFormat.DEFAULT.withRecordSeparator(CRLF));
|
||||
CSVRecord record;
|
||||
assertEquals(0, parser.getRecordNumber());
|
||||
|
@ -704,7 +704,7 @@ public class CSVParserTest {
|
|||
}
|
||||
|
||||
private void validateRecordNumbers(final String lineSeparator) throws IOException {
|
||||
final CSVParser parser = CSVParser.parseString("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
|
||||
final CSVParser parser = CSVParser.parse("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
|
||||
CSVRecord record;
|
||||
assertEquals(0, parser.getRecordNumber());
|
||||
assertNotNull(record = parser.nextRecord());
|
||||
|
@ -721,7 +721,7 @@ public class CSVParserTest {
|
|||
}
|
||||
|
||||
private void validateLineNumbers(final String lineSeparator) throws IOException {
|
||||
final CSVParser parser = CSVParser.parseString("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
|
||||
final CSVParser parser = CSVParser.parse("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.DEFAULT.withRecordSeparator(lineSeparator));
|
||||
assertEquals(0, parser.getCurrentLineNumber());
|
||||
assertNotNull(parser.nextRecord());
|
||||
assertEquals(1, parser.getCurrentLineNumber());
|
||||
|
|
|
@ -85,7 +85,7 @@ public class CSVPrinterTest {
|
|||
final String result = sw.toString();
|
||||
// System.out.println("### :" + printable(result));
|
||||
|
||||
final CSVParser parser = CSVParser.parseString(result, format);
|
||||
final CSVParser parser = CSVParser.parse(result, format);
|
||||
final List<CSVRecord> parseResult = parser.getRecords();
|
||||
|
||||
Utils.compare("Printer output :" + printable(result), lines, parseResult);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class FercGovTest {
|
|||
|
||||
@Test
|
||||
public void testContractFile() throws IOException {
|
||||
final CSVParser parser = CSVParser.parseResource("ferc.gov/contract.txt", US_ASCII,
|
||||
final CSVParser parser = CSVParser.parse("ferc.gov/contract.txt", US_ASCII,
|
||||
CSVFormat.DEFAULT.withHeader());
|
||||
try {
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
|
@ -65,7 +65,7 @@ public class FercGovTest {
|
|||
|
||||
@Test
|
||||
public void testTransactionFile() throws IOException {
|
||||
final CSVParser parser = CSVParser.parseResource("ferc.gov/transaction.txt", US_ASCII,
|
||||
final CSVParser parser = CSVParser.parse("ferc.gov/transaction.txt", US_ASCII,
|
||||
CSVFormat.DEFAULT.withHeader());
|
||||
try {
|
||||
final List<CSVRecord> records = parser.getRecords();
|
||||
|
|
Loading…
Reference in New Issue