From 079b10f8f9fcb5a751e855e3571eaa20bdf973b2 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 25 Nov 2019 12:21:32 +0100 Subject: [PATCH] Improved JavaJsonLineCounter a bit --- .../mograsim/logic/model/JavaJsonLineCounter.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/JavaJsonLineCounter.java b/tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/JavaJsonLineCounter.java index 7811638b..de713723 100644 --- a/tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/JavaJsonLineCounter.java +++ b/tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/JavaJsonLineCounter.java @@ -3,26 +3,30 @@ package net.mograsim.logic.model; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; import java.util.stream.StreamSupport; public class JavaJsonLineCounter { public static void main(String[] args) throws IOException { - printLineCount("..\\..", "java"); - printLineCount("..\\..", "json"); + printLineCount("../..", "java", "bin", "classes", "SWTHelper"); + printLineCount("../..", "json", "bin", "classes", "SWTHelper"); } - private static void printLineCount(String path, String filetype) throws IOException + private static void printLineCount(String path, String filetype, String... excludedDirectoryNames) throws IOException { + Set excludedDirectoryPaths = Arrays.stream(excludedDirectoryNames).map(Paths::get).collect(Collectors.toSet()); AtomicLong lineCount = new AtomicLong(); AtomicLong byteSize = new AtomicLong(); AtomicLong fileCount = new AtomicLong(); Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype)) - .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("bin")::equals)) - .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("classes")::equals)).forEach(p -> + .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(excludedDirectoryPaths::contains)).forEach(p -> { try { -- 2.17.1