From: Daniel Kirschten Date: Mon, 25 Nov 2019 11:21:32 +0000 (+0100) Subject: Improved JavaJsonLineCounter a bit X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=079b10f8f9fcb5a751e855e3571eaa20bdf973b2 Improved JavaJsonLineCounter a bit --- 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 {