From: Daniel Kirschten Date: Thu, 12 Sep 2019 10:32:39 +0000 (+0200) Subject: Added simple line counter to be able to show off and feel great ;) X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=72fa36c6c75e52baa60454cf180b3c6ee6aca86a;p=Mograsim.git Added simple line counter to be able to show off and feel great ;) --- diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/JavaJsonLineCounter.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/JavaJsonLineCounter.java new file mode 100644 index 00000000..2f6cd4e3 --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/JavaJsonLineCounter.java @@ -0,0 +1,35 @@ +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; + +public class JavaJsonLineCounter +{ + public static void main(String[] args) throws IOException + { + 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 -> + { + try + { + return Files.lines(p); + } + catch (IOException e) + { + throw new UncheckedIOException(e); + } + }).count(); + System.out.println("Total lines in " + filetype + " files: " + lineCount); + } +} \ No newline at end of file