Skip to content
This repository was archived by the owner on Sep 14, 2025. It is now read-only.

Commit dfd58d8

Browse files
author
Gary Gregory
committed
More lambdas, less boilerplate.
1 parent 2f1ac70 commit dfd58d8

2 files changed

Lines changed: 6 additions & 32 deletions

File tree

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ private String readTestData() throws IOException {
6969
public static Collection<Object[]> generateData() {
7070
final List<Object[]> list = new ArrayList<>();
7171

72-
final FilenameFilter fileNameFilter = new FilenameFilter() {
73-
74-
@Override
75-
public boolean accept(final File dir, final String name) {
76-
return name.startsWith("test") && name.endsWith(".txt");
77-
}
78-
};
72+
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
7973
final File[] files = BASE.listFiles(fileNameFilter);
8074
if (files != null) {
8175
for (final File f : files) {

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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,45 +240,25 @@ private static void testParser(final String msg, final CSVParserFactory fac) thr
240240
show();
241241
}
242242

243+
@FunctionalInterface
243244
private static interface CSVParserFactory {
244245
public CSVParser createParser() throws IOException;
245246
}
246247

247248
private static void testParseCommonsCSV() throws Exception {
248-
testParser("CSV", new CSVParserFactory() {
249-
@Override
250-
public CSVParser createParser() throws IOException {
251-
return new CSVParser(createReader(), format);
252-
}
253-
});
249+
testParser("CSV", () -> new CSVParser(createReader(), format));
254250
}
255251

256252
private static void testParsePath() throws Exception {
257-
testParser("CSV-PATH", new CSVParserFactory() {
258-
@Override
259-
public CSVParser createParser() throws IOException {
260-
return CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format);
261-
}
262-
});
253+
testParser("CSV-PATH", () -> CSVParser.parse(Files.newInputStream(Paths.get(BIG_FILE.toURI())), StandardCharsets.ISO_8859_1, format));
263254
}
264255

265256
private static void testParsePathDoubleBuffering() throws Exception {
266-
testParser("CSV-PATH-DB", new CSVParserFactory() {
267-
@Override
268-
public CSVParser createParser() throws IOException {
269-
return CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format);
270-
}
271-
});
257+
testParser("CSV-PATH-DB", () -> CSVParser.parse(Files.newBufferedReader(Paths.get(BIG_FILE.toURI()), StandardCharsets.ISO_8859_1), format));
272258
}
273259

274260
private static void testParseURL() throws Exception {
275-
testParser("CSV-URL", new CSVParserFactory() {
276-
@Override
277-
public CSVParser createParser() throws IOException {
278-
//NOTE: URL will always return a BufferedInputStream.
279-
return CSVParser.parse(BIG_FILE.toURI().toURL(), StandardCharsets.ISO_8859_1, format);
280-
}
281-
});
261+
testParser("CSV-URL", () -> CSVParser.parse(BIG_FILE.toURI().toURL(), StandardCharsets.ISO_8859_1, format));
282262
}
283263

284264
private static Constructor<Lexer> getLexerCtor(final String clazz) throws Exception {

0 commit comments

Comments
 (0)