2f6cd4e3e536d4c3216cde95db610a4ef60feeea
[Mograsim.git] / net.mograsim.logic.model.am2900 / test / net / mograsim / logic / model / JavaJsonLineCounter.java
1 package net.mograsim.logic.model;
2
3 import java.io.IOException;
4 import java.io.UncheckedIOException;
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.Paths;
8 import java.util.function.Function;
9 import java.util.stream.Stream;
10
11 public class JavaJsonLineCounter
12 {
13         public static void main(String[] args) throws IOException
14         {
15                 printLineCount("..", "java");
16                 printLineCount("..", "json");
17         }
18
19         private static void printLineCount(String path, String filetype) throws IOException
20         {
21                 long lineCount = Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype))
22                                 .flatMap((Function<Path, Stream<String>>) p ->
23                                 {
24                                         try
25                                         {
26                                                 return Files.lines(p);
27                                         }
28                                         catch (IOException e)
29                                         {
30                                                 throw new UncheckedIOException(e);
31                                         }
32                                 }).count();
33                 System.out.println("Total lines in " + filetype + " files: " + lineCount);
34         }
35 }