X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=tests%2Fnet.mograsim.logic.model.am2900.tests%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2FJavaJsonLineCounter.java;h=de71372325932b744c4510bd67d9013aaf9da95e;hb=079b10f8f9fcb5a751e855e3571eaa20bdf973b2;hp=2f6cd4e3e536d4c3216cde95db610a4ef60feeea;hpb=58babf45ae7d259a296656451d796dbe601377a4;p=Mograsim.git 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 2f6cd4e3..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 @@ -5,31 +5,40 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.function.Function; -import java.util.stream.Stream; +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 { - long lineCount = Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype)) - .flatMap((Function>) p -> + 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(excludedDirectoryPaths::contains)).forEach(p -> { try { - return Files.lines(p); + lineCount.addAndGet(Files.lines(p).count()); + byteSize.addAndGet(Files.size(p)); + fileCount.incrementAndGet(); } catch (IOException e) { throw new UncheckedIOException(e); } - }).count(); - System.out.println("Total lines in " + filetype + " files: " + lineCount); + }); + System.out.println(filetype + ": " + fileCount + " files; " + lineCount + " lines; " + byteSize + " bytes"); } } \ No newline at end of file