From dfd58d8a9442440ae4d3ed3cb491bddeba9ad60b Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2019 20:58:07 -0400 Subject: [PATCH] More lambdas, less boilerplate. --- .../apache/commons/csv/CSVFileParserTest.java | 8 +---- .../apache/commons/csv/PerformanceTest.java | 30 ++++--------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java index c81ebe52..92ede5bb 100644 --- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java @@ -69,13 +69,7 @@ public class CSVFileParserTest { public static Collection generateData() { final List list = new ArrayList<>(); - final FilenameFilter fileNameFilter = new FilenameFilter() { - - @Override - public boolean accept(final File dir, final String name) { - return name.startsWith("test") && name.endsWith(".txt"); - } - }; + final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt"); final File[] files = BASE.listFiles(fileNameFilter); if (files != null) { for (final File f : files) { diff --git a/src/test/java/org/apache/commons/csv/PerformanceTest.java b/src/test/java/org/apache/commons/csv/PerformanceTest.java index 1727b79d..0f1bb2c9 100644 --- a/src/test/java/org/apache/commons/csv/PerformanceTest.java +++ b/src/test/java/org/apache/commons/csv/PerformanceTest.java @@ -240,45 +240,25 @@ public class PerformanceTest { show(); } + @FunctionalInterface private static interface CSVParserFactory { public CSVParser createParser() throws IOException; } private static void testParseCommonsCSV() throws Exception { - testParser("CSV", new CSVParserFactory() { - @Override - public CSVParser createParser() throws IOException { - return new CSVParser(createReader(), format); - } - }); + testParser("CSV", () -> new CSVParser(createReader(), format)); } private static void testParsePath() throws Exception { - testParser("CSV-PATH", new CSVParserFactory() { - @Override - public CSVParser createParser() throws IOException { - return CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format); - } - }); + testParser("CSV-PATH", () -> CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format)); } private static void testParsePathDoubleBuffering() throws Exception { - testParser("CSV-PATH-DB", new CSVParserFactory() { - @Override - public CSVParser createParser() throws IOException { - return CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format); - } - }); + testParser("CSV-PATH-DB", () -> CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format)); } private static void testParseURL() throws Exception { - testParser("CSV-URL", new CSVParserFactory() { - @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); - } - }); + testParser("CSV-URL", () -> CSVParser.parse(BIG_FILE.toURI().toURL(), StandardCharsets.ISO_8859_1, format)); } private static Constructor getLexerCtor(final String clazz) throws Exception {