|
1 | 1 | package io.github.computerdaddyguy.jfiletreeprettyprinter.example; |
2 | 2 |
|
3 | | -import io.github.computerdaddyguy.jfiletreeprettyprinter.ChildLimitBuilder; |
| 3 | +import io.github.computerdaddyguy.jfiletreeprettyprinter.ChildLimits; |
4 | 4 | import io.github.computerdaddyguy.jfiletreeprettyprinter.FileTreePrettyPrinter; |
| 5 | +import io.github.computerdaddyguy.jfiletreeprettyprinter.LineExtensions; |
5 | 6 | import io.github.computerdaddyguy.jfiletreeprettyprinter.PathMatchers; |
6 | | -import io.github.computerdaddyguy.jfiletreeprettyprinter.PrettyPrintOptions.Sorts; |
| 7 | +import io.github.computerdaddyguy.jfiletreeprettyprinter.PathSorts; |
7 | 8 | import java.nio.file.Path; |
8 | 9 | import java.util.Comparator; |
9 | 10 | import java.util.function.Function; |
@@ -47,46 +48,38 @@ public static void main(String[] args) { |
47 | 48 | var fileFilter = PathMatchers.allOf( |
48 | 49 |
|
49 | 50 | // Hide files with names starting with "." |
50 | | - PathMatchers.not(PathMatchers.hasNameStartingWith(".")), |
51 | | - |
52 | | - // Inside "jfiletreeprettyprinter" folder, keep only "FileTreePrettyPrinter.java" |
53 | | - // Files in other folders are not restricted by this rule. |
54 | | - PathMatchers.ifMatchesThenElse( |
55 | | - /* if */ PathMatchers.hasDirectParentMatching(PathMatchers.hasName("jfiletreeprettyprinter")), |
56 | | - /* then */ PathMatchers.hasName("FileTreePrettyPrinter.java"), |
57 | | - /* else */ path -> true |
58 | | - ) |
| 51 | + PathMatchers.not(PathMatchers.hasNameStartingWith(".")) |
59 | 52 | ); |
60 | 53 |
|
61 | 54 | /* |
62 | 55 | * Limit the number of displayed children by directory: some content is not relevant and clutters the final result! |
63 | 56 | */ |
64 | | - var childLimitFunction = ChildLimitBuilder.builder() |
| 57 | + var childLimitFunction = ChildLimits.builder() |
65 | 58 | // Hide all files under renderer and scanner packages |
66 | | - .limit(PathMatchers.hasAbsolutePathMatchingGlob("**/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer"), 0) |
67 | | - .limit(PathMatchers.hasAbsolutePathMatchingGlob("**/io/github/computerdaddyguy/jfiletreeprettyprinter/scanner"), 0) |
| 59 | + .add(PathMatchers.hasAbsolutePathMatchingGlob("**/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer"), 0) |
| 60 | + .add(PathMatchers.hasAbsolutePathMatchingGlob("**/io/github/computerdaddyguy/jfiletreeprettyprinter/scanner"), 0) |
| 61 | + .add(PathMatchers.hasAbsolutePathMatchingGlob("**/io/github/computerdaddyguy/jfiletreeprettyprinter"), 3) |
68 | 62 | .build(); |
69 | 63 |
|
70 | 64 | /* |
71 | 65 | * Add some comments on a few files and directories |
72 | 66 | */ |
73 | | - Function<Path, String> lineExtension = path -> { |
74 | | - if (PathMatchers.hasName("project-structure.png").matches(path)) { |
75 | | - return "\t// This image"; |
76 | | - } else if (PathMatchers.hasName("FileTreePrettyPrinter.java").matches(path)) { |
77 | | - return "\t// Main entry point"; |
78 | | - } else if (PathMatchers.hasName("README.md").matches(path)) { |
79 | | - return "\t\t// You're reading at this!"; |
80 | | - } else if (PathMatchers.hasRelativePathMatchingGlob(projectFolder, "src/main/java").matches(path)) { |
81 | | - return ""; // Empty string: force line break in compact directory chain |
82 | | - } |
83 | | - return null; |
84 | | - }; |
| 67 | + Function<Path, String> lineExtension = LineExtensions.builder() |
| 68 | + .add(PathMatchers.hasName("project-structure.png"), "\t// This image") |
| 69 | + .add(PathMatchers.hasName("FileTreePrettyPrinter.java"), "\t// Main entry point") |
| 70 | + .add(PathMatchers.hasName("README.md"), "\t\t// You're reading at this!") |
| 71 | + .addLineBreak(PathMatchers.hasRelativePathMatchingGlob(projectFolder, "src/main/java")) |
| 72 | + .build(); |
85 | 73 |
|
86 | 74 | /* |
87 | | - * Sort all paths by directory first (then alphabetically by default) |
| 75 | + * Sort all paths by directory first (with highest precedence), |
| 76 | + * then "FileTreePrettyPrinter.java" has precedence "-100". |
| 77 | + * All other files have default precedence "0", and are then sorted alphabetically by default. |
88 | 78 | */ |
89 | | - Comparator<Path> pathComparator = Sorts.DIRECTORY_FIRST; |
| 79 | + Comparator<Path> pathComparator = PathSorts.builder() |
| 80 | + .addFirst(PathMatchers.isDirectory()) |
| 81 | + .add(PathMatchers.hasName("FileTreePrettyPrinter.java"), -100) // Default precedence is "0" |
| 82 | + .build(); |
90 | 83 |
|
91 | 84 | /* |
92 | 85 | * Build the final FileTreePrettyPrinter |
@@ -115,25 +108,27 @@ public static void main(String[] args) { |
115 | 108 | Expected result |
116 | 109 | ================================ |
117 | 110 | |
118 | | - 📂 JFileTreePrettyPrinter/ |
119 | | - ├─ 📂 assets/ |
120 | | - │ └─ 🖼️ project-structure.png // This image |
121 | | - ├─ 📂 src/main/java/ |
122 | | - │ └─ 📂 io/github/computerdaddyguy/jfiletreeprettyprinter/ |
123 | | - │ ├─ 📂 renderer/ |
124 | | - │ │ └─ ... (5 files and 2 directories skipped) |
125 | | - │ ├─ 📂 scanner/ |
126 | | - │ │ └─ ... (4 files skipped) |
127 | | - │ └─ ☕ FileTreePrettyPrinter.java // Main entry point |
128 | | - ├─ 🗺️ CHANGELOG.md |
129 | | - ├─ 📖 CONTRIBUTING.md |
130 | | - ├─ 📄 LICENSE |
131 | | - ├─ 📖 README.md // You're reading at this! |
132 | | - ├─ 🗺️ ROADMAP.md |
133 | | - ├─ 🛡️ SECURITY.md |
134 | | - ├─ 🏗️ pom.xml |
135 | | - ├─ 📖 release_process.md |
136 | | - └─ 📜 runMutationTests.sh |
| 111 | + 📂 JFileTreePrettyPrinter/ |
| 112 | + ├─ 📂 assets/ |
| 113 | + │ └─ 🖼️ project-structure.png // This image |
| 114 | + ├─ 📂 src/main/java/ |
| 115 | + │ └─ 📂 io/github/computerdaddyguy/jfiletreeprettyprinter/ |
| 116 | + │ ├─ 📂 renderer/ |
| 117 | + │ │ └─ ... (5 files and 2 directories skipped) |
| 118 | + │ ├─ 📂 scanner/ |
| 119 | + │ │ └─ ... (4 files skipped) |
| 120 | + │ ├─ ☕ FileTreePrettyPrinter.java // Main entry point |
| 121 | + │ └─ ... (10 files skipped) |
| 122 | + ├─ 🗺️ CHANGELOG.md |
| 123 | + ├─ 📖 CONTRIBUTING.md |
| 124 | + ├─ 📄 LICENSE |
| 125 | + ├─ 📖 README.md // You're reading at this! |
| 126 | + ├─ 🗺️ ROADMAP.md |
| 127 | + ├─ 🛡️ SECURITY.md |
| 128 | + ├─ 🏗️ pom.xml |
| 129 | + ├─ 📖 release_process.md |
| 130 | + └─ 📜 runMutationTests.sh |
| 131 | + |
137 | 132 | */ |
138 | 133 | } |
139 | 134 |
|
|
0 commit comments