You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/09/13 00:58:12 UTC

[commons-csv] branch master updated: More lambdas, less boilerplate.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new dfd58d8  More lambdas, less boilerplate.
dfd58d8 is described below

commit dfd58d8a9442440ae4d3ed3cb491bddeba9ad60b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 20:58:07 2019 -0400

    More lambdas, less boilerplate.
---
 .../org/apache/commons/csv/CSVFileParserTest.java  |  8 +-----
 .../org/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 c81ebe5..92ede5b 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<Object[]> generateData() {
         final List<Object[]> 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 1727b79..0f1bb2c 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<Lexer> getLexerCtor(final String clazz) throws Exception {