1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package Torello.Java.Build;

import Torello.Java.StringParse;
import Torello.Java.FileRW;
import Torello.Java.FileNode;
import Torello.Java.RTC;
import Torello.Java.Q;

import static Torello.Java.C.BGREEN;
import static Torello.Java.C.BRED;
import static Torello.Java.C.BYELLOW;
import static Torello.Java.C.RESET;

import java.util.Iterator;
import java.util.Vector;

import java.util.function.IntFunction;

import java.io.File;
import java.io.IOException;

class LineLengths
{
    static void check(String directoryName) throws IOException
    {
        Iterator<String> javaFiles = FileNode
            .createRoot(directoryName)
            .loadTree(-1, (File dir, String fileName) -> fileName.endsWith(".java"), null)
            .flattenJustFiles(RTC.FULLPATH_ITERATOR());

        while (javaFiles.hasNext())
        {
            String              fileName    = javaFiles.next();
            Vector<String>      lines       = FileRW.loadFileToVector(fileName, true);
            boolean             hadMatch    = false;
            IntFunction<String> zeroPad     = (lines.size() < 999)
                                                ? StringParse::zeroPad
                                                : StringParse::zeroPad10e4;

            System.out.println("Checking File: " + BYELLOW + fileName + RESET);

            for (int i=0; i < lines.size(); i++)

                if (lines.elementAt(i).length() > 100)
                {
                    String l = lines.elementAt(i);

                    System.out.print(
                        "Line-Number: " +

                        // NOTE: add one to the line number, when printing it.  The lines
                        //       vector index starts at zero, not one.

                        '[' + BGREEN + zeroPad.apply(i + 1) + RESET + ", " +
                        "Has Length: " + BRED + l.length() + RESET + '\n' +

                        // Print the line
                        l
                    );

                    hadMatch = true;
                }

            if (hadMatch) if (! Q.YN("continue?")) System.exit(0);
        }
    }
}