Improved JavaJsonLineCounter a bit
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 25 Nov 2019 11:21:32 +0000 (12:21 +0100)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 25 Nov 2019 11:21:32 +0000 (12:21 +0100)
tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/JavaJsonLineCounter.java

index 7811638..de71372 100644 (file)
@@ -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<Path> 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
                                        {