From ace62eb5e445dd364a104eda0ce2ae06c9628dcd Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 19 Sep 2019 21:21:07 +0200 Subject: [PATCH] Fixed & extended JavaJsonLineCounter --- .../logic/model/JavaJsonLineCounter.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 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 2f6cd4e3..7811638b 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,33 +3,38 @@ 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.function.Function; -import java.util.stream.Stream; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.StreamSupport; public class JavaJsonLineCounter { public static void main(String[] args) throws IOException { - printLineCount("..", "java"); - printLineCount("..", "json"); + printLineCount("..\\..", "java"); + printLineCount("..\\..", "json"); } private static void printLineCount(String path, String filetype) throws IOException { - long lineCount = Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype)) - .flatMap((Function>) p -> + 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 -> { 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 -- 2.17.1