7811638b889a4660ec1000fc613bedbdaf9a3bf9
[Mograsim.git] / tests / net.mograsim.logic.model.am2900.tests / src / 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.Paths;
7 import java.util.concurrent.atomic.AtomicLong;
8 import java.util.stream.StreamSupport;
9
10 public class JavaJsonLineCounter
11 {
12         public static void main(String[] args) throws IOException
13         {
14                 printLineCount("..\\..", "java");
15                 printLineCount("..\\..", "json");
16         }
17
18         private static void printLineCount(String path, String filetype) throws IOException
19         {
20                 AtomicLong lineCount = new AtomicLong();
21                 AtomicLong byteSize = new AtomicLong();
22                 AtomicLong fileCount = new AtomicLong();
23                 Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype))
24                                 .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("bin")::equals))
25                                 .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(Paths.get("classes")::equals)).forEach(p ->
26                                 {
27                                         try
28                                         {
29                                                 lineCount.addAndGet(Files.lines(p).count());
30                                                 byteSize.addAndGet(Files.size(p));
31                                                 fileCount.incrementAndGet();
32                                         }
33                                         catch (IOException e)
34                                         {
35                                                 throw new UncheckedIOException(e);
36                                         }
37                                 });
38                 System.out.println(filetype + ": " + fileCount + " files; " + lineCount + " lines; " + byteSize + " bytes");
39         }
40 }