1 package net.mograsim.logic.model;
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.Arrays;
10 import java.util.concurrent.atomic.AtomicLong;
11 import java.util.stream.Collectors;
12 import java.util.stream.StreamSupport;
14 public class JavaJsonLineCounter
16 public static void main(String[] args) throws IOException
18 printLineCount("../..", "java", "bin", "classes", "SWTHelper");
19 printLineCount("../..", "json", "bin", "classes", "SWTHelper");
22 private static void printLineCount(String path, String filetype, String... excludedDirectoryNames) throws IOException
24 Set<Path> excludedDirectoryPaths = Arrays.stream(excludedDirectoryNames).map(Paths::get).collect(Collectors.toSet());
25 AtomicLong lineCount = new AtomicLong();
26 AtomicLong byteSize = new AtomicLong();
27 AtomicLong fileCount = new AtomicLong();
28 Files.walk(Paths.get(path)).filter(Files::isRegularFile).filter(p -> p.toString().endsWith('.' + filetype))
29 .filter(p -> !StreamSupport.stream(p.spliterator(), false).anyMatch(excludedDirectoryPaths::contains)).forEach(p ->
33 lineCount.addAndGet(Files.lines(p).count());
34 byteSize.addAndGet(Files.size(p));
35 fileCount.incrementAndGet();
39 throw new UncheckedIOException(e);
42 System.out.println(filetype + ": " + fileCount + " files; " + lineCount + " lines; " + byteSize + " bytes");