mirror of
https://github.com/apache/commons-csv.git
synced 2025-02-27 13:34:59 +00:00
More lambdas, less boilerplate.
This commit is contained in:
parent
2f1ac70815
commit
dfd58d8a94
@ -69,13 +69,7 @@ public class CSVFileParserTest {
|
|||||||
public static Collection<Object[]> generateData() {
|
public static Collection<Object[]> generateData() {
|
||||||
final List<Object[]> list = new ArrayList<>();
|
final List<Object[]> list = new ArrayList<>();
|
||||||
|
|
||||||
final FilenameFilter fileNameFilter = new FilenameFilter() {
|
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept(final File dir, final String name) {
|
|
||||||
return name.startsWith("test") && name.endsWith(".txt");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final File[] files = BASE.listFiles(fileNameFilter);
|
final File[] files = BASE.listFiles(fileNameFilter);
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (final File f : files) {
|
for (final File f : files) {
|
||||||
|
@ -240,45 +240,25 @@ public class PerformanceTest {
|
|||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
private static interface CSVParserFactory {
|
private static interface CSVParserFactory {
|
||||||
public CSVParser createParser() throws IOException;
|
public CSVParser createParser() throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testParseCommonsCSV() throws Exception {
|
private static void testParseCommonsCSV() throws Exception {
|
||||||
testParser("CSV", new CSVParserFactory() {
|
testParser("CSV", () -> new CSVParser(createReader(), format));
|
||||||
@Override
|
|
||||||
public CSVParser createParser() throws IOException {
|
|
||||||
return new CSVParser(createReader(), format);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testParsePath() throws Exception {
|
private static void testParsePath() throws Exception {
|
||||||
testParser("CSV-PATH", new CSVParserFactory() {
|
testParser("CSV-PATH", () -> CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format));
|
||||||
@Override
|
|
||||||
public CSVParser createParser() throws IOException {
|
|
||||||
return CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testParsePathDoubleBuffering() throws Exception {
|
private static void testParsePathDoubleBuffering() throws Exception {
|
||||||
testParser("CSV-PATH-DB", new CSVParserFactory() {
|
testParser("CSV-PATH-DB", () -> CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format));
|
||||||
@Override
|
|
||||||
public CSVParser createParser() throws IOException {
|
|
||||||
return CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testParseURL() throws Exception {
|
private static void testParseURL() throws Exception {
|
||||||
testParser("CSV-URL", new CSVParserFactory() {
|
testParser("CSV-URL", () -> CSVParser.parse(BIG_FILE.toURI().toURL(), StandardCharsets.ISO_8859_1, format));
|
||||||
@Override
|
|
||||||
public CSVParser createParser() throws IOException {
|
|
||||||
//NOTE: URL will always return a BufferedInputStream.
|
|
||||||
return CSVParser.parse(BIG_FILE.toURI().toURL(), StandardCharsets.ISO_8859_1, format);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Constructor<Lexer> getLexerCtor(final String clazz) throws Exception {
|
private static Constructor<Lexer> getLexerCtor(final String clazz) throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user