Skip to content

Commit 6914ab9

Browse files
Skipped children simplification (#10)
1 parent 5fbc8ae commit 6914ab9

File tree

11 files changed

+34
-94
lines changed

11 files changed

+34
-94
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
---
99
## [0.0.6] - Unreleased
1010

11+
### Changed
12+
- Child limit: do not print skipped children count
13+
- Max depth: do not print "max depth reached"
14+
1115
---
1216
## [0.0.5] - 2025-10-04
1317

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ var prettyPrinter = FileTreePrettyPrinter.builder()
186186
> *Idea for a future version: option to allow custom emoji mapping*
187187
188188
## Child limit
189-
You can set a fixed limit to the number of children displayed for each directory.
189+
You can set a fixed limit to the number of children displayed for each directory. Each directory and file that pass filter (if set) counts for one.
190190

191191
```java
192192
// Example: ChildLimitStatic.java
@@ -202,13 +202,13 @@ child_limit_static/
202202
│ ├─ file_1_1
203203
│ ├─ file_1_2
204204
│ ├─ file_1_3
205-
│ └─ ... (2 files skipped)
205+
│ └─ ...
206206
├─ folder_2/
207207
│ ├─ file_2_1
208208
│ ├─ file_2_2
209209
│ ├─ file_2_3
210-
│ └─ ... (2 files skipped)
211-
└─ ... (3 directories skipped)
210+
│ └─ ...
211+
└─ ...
212212
213213
```
214214

@@ -237,7 +237,7 @@ child_limit_dynamic/
237237
│ ├─ file_1_4
238238
│ └─ file_1_5
239239
└─ node_modules/
240-
└─ ... (9 files skipped)
240+
└─ ...
241241
```
242242

243243
## Line extension

src/example/java/io/github/computerdaddyguy/jfiletreeprettyprinter/example/ProjectStructure.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ public static void main(String[] args) {
114114
├─ 📂 src/main/java/
115115
│ └─ 📂 io/github/computerdaddyguy/jfiletreeprettyprinter/
116116
│ ├─ 📂 renderer/
117-
│ │ └─ ... (5 files and 2 directories skipped)
117+
│ │ └─ ...
118118
│ ├─ 📂 scanner/
119-
│ │ └─ ... (4 files skipped)
119+
│ │ └─ ...
120120
│ ├─ ☕ FileTreePrettyPrinter.java // Main entry point
121-
│ └─ ... (10 files skipped)
121+
│ └─ ...
122122
├─ 🗺️ CHANGELOG.md
123123
├─ 📖 CONTRIBUTING.md
124124
├─ 📄 LICENSE

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/file/DefaultFileFormatter.java

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
66
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
77
import java.nio.file.Path;
8-
import java.util.Collection;
98
import java.util.List;
109
import java.util.stream.Collectors;
1110
import org.jspecify.annotations.NullMarked;
@@ -33,51 +32,12 @@ public String formatFile(FileEntry fileEntry) {
3332

3433
@Override
3534
public String formatChildLimitReached(SkippedChildrenEntry skippedChildrenEntry) {
36-
return "... (" + childrenAsString(skippedChildrenEntry.getSkippedChildren()) + " skipped)";
35+
return "...";
3736
}
3837

3938
@Override
4039
public String formatMaxDepthReached(MaxDepthReachEntry maxDepthReachEntry) {
41-
return "... (max depth reached)";
42-
}
43-
44-
private String childrenAsString(Collection<Path> notVisited) {
45-
46-
var dirCount = countDirs(notVisited);
47-
var fileCount = countFiles(notVisited, dirCount);
48-
49-
var dirText = dirText(dirCount);
50-
var fileText = fileText(fileCount);
51-
52-
return fileText + (!fileText.isEmpty() && !dirText.isEmpty() ? " and " : "") + dirText;
53-
}
54-
55-
private long countDirs(Collection<Path> notVisited) {
56-
return notVisited.stream().filter(path -> path.toFile().isDirectory()).count();
57-
}
58-
59-
private String dirText(long dirCount) {
60-
if (dirCount == 0) {
61-
return "";
62-
}
63-
if (dirCount == 1) {
64-
return "1 directory";
65-
}
66-
return dirCount + " directories";
67-
}
68-
69-
private long countFiles(Collection<Path> notVisited, long dirCount) {
70-
return notVisited.size() - dirCount;
71-
}
72-
73-
private String fileText(long fileCount) {
74-
if (fileCount == 0) {
75-
return "";
76-
}
77-
if (fileCount == 1) {
78-
return "1 file";
79-
}
80-
return fileCount + " files";
40+
return "...";
8141
}
8242

8343
}

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/scanner/DefaultPathToTreeScanner.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,7 @@ private List<TreeEntry> handleDirectoryChildren(Path root, int depth, Path dir,
8585

8686
// Loop has early exit?
8787
if (pathIterator.hasNext()) {
88-
childEntries.addAll(handleLeftOverChildren(root, depth, pathIterator, filter));
89-
}
90-
91-
return childEntries;
92-
}
93-
94-
private List<TreeEntry> handleLeftOverChildren(Path root, int depth, Iterator<Path> pathIterator, PathMatcher filter) {
95-
var childEntries = new ArrayList<TreeEntry>();
96-
97-
var skippedChildren = new ArrayList<Path>();
98-
while (pathIterator.hasNext()) {
99-
var child = pathIterator.next();
100-
var childEntry = handle(root, depth + 1, child, filter);
101-
if (childEntry != null) { // Is null if no children file is retained by filter
102-
skippedChildren.add(child);
103-
}
104-
}
105-
if (!skippedChildren.isEmpty()) {
106-
var childrenSkippedEntry = new SkippedChildrenEntry(skippedChildren);
107-
childEntries.add(childrenSkippedEntry);
88+
childEntries.add(new SkippedChildrenEntry(dir));
10889
}
10990

11091
return childEntries;

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/scanner/TreeEntry.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.nio.file.Path;
44
import java.nio.file.attribute.BasicFileAttributes;
5-
import java.util.Collection;
65
import java.util.List;
76
import java.util.Objects;
87
import org.jspecify.annotations.NullMarked;
@@ -62,19 +61,15 @@ public BasicFileAttributes getAttrs() {
6261

6362
final class SkippedChildrenEntry implements TreeEntry {
6463

65-
final Collection<Path> skippedChildren;
64+
final Path dir;
6665

67-
public SkippedChildrenEntry(List<Path> skippedChildren) {
68-
this.skippedChildren = Objects.requireNonNull(skippedChildren, "skippedChildren is null");
66+
public SkippedChildrenEntry(Path dir) {
67+
this.dir = Objects.requireNonNull(dir, "dir is null");
6968
}
7069

7170
@Override
7271
public String toString() {
73-
return "SkippedChildrenEntry[skippedChildren: " + skippedChildren.stream().map(Path::getFileName).toList() + "]";
74-
}
75-
76-
public Collection<Path> getSkippedChildren() {
77-
return skippedChildren;
72+
return "SkippedChildrenEntry[dir: " + dir.getFileName() + "]";
7873
}
7974

8075
}

src/test/java/io/github/computerdaddyguy/jfiletreeprettyprinter/ChildLimitDynamicTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void nominal() {
5959
targetPath/
6060
├─ limit_1/
6161
│ ├─ file1
62-
│ └─ ... (4 files skipped)
62+
│ └─ ...
6363
├─ limit_3/
6464
│ ├─ file1
6565
│ ├─ file2
6666
│ ├─ file3
67-
│ └─ ... (2 files skipped)
67+
│ └─ ...
6868
└─ simpleDir/
6969
├─ file1
7070
├─ file2
@@ -91,7 +91,7 @@ void limited_dir_1() {
9191
targetPath/
9292
└─ limit_1/
9393
├─ file1
94-
└─ ... (4 files skipped)""";
94+
└─ ...""";
9595
assertThat(result).isEqualTo(expected);
9696
}
9797

@@ -114,7 +114,7 @@ void limited_dir_3() {
114114
├─ file1
115115
├─ file2
116116
├─ file3
117-
└─ ... (2 files skipped)""";
117+
└─ ...""";
118118
assertThat(result).isEqualTo(expected);
119119
}
120120

src/test/java/io/github/computerdaddyguy/jfiletreeprettyprinter/ChildLimitStaticTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void dirWith_1_extra_file() {
6666
├─ file1
6767
├─ file2
6868
├─ file3
69-
└─ ... (1 file skipped)""";
69+
└─ ...""";
7070
assertThat(result).isEqualTo(expected);
7171
}
7272

@@ -79,7 +79,7 @@ void dirWith_2_extra_files() {
7979
├─ file1
8080
├─ file2
8181
├─ file3
82-
└─ ... (2 files skipped)""";
82+
└─ ...""";
8383
assertThat(result).isEqualTo(expected);
8484
}
8585

@@ -92,7 +92,7 @@ void dirWith_2_extra_files_and_1_extra_folder() {
9292
├─ file1
9393
├─ file2
9494
├─ file3
95-
└─ ... (2 files and 1 directory skipped)""";
95+
└─ ...""";
9696
assertThat(result).isEqualTo(expected);
9797
}
9898

@@ -105,7 +105,7 @@ void dirWith_2_extra_files_and_2_extra_folders() {
105105
├─ file1
106106
├─ file2
107107
├─ file3
108-
└─ ... (2 files and 2 directories skipped)""";
108+
└─ ...""";
109109
assertThat(result).isEqualTo(expected);
110110
}
111111

src/test/java/io/github/computerdaddyguy/jfiletreeprettyprinter/FileTreePrettyPrinterBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void withOptions_overrides() {
2626
targetPath/
2727
├─ file1
2828
├─ file2
29-
└─ ... (1 file and 3 directories skipped)""";
29+
└─ ...""";
3030
assertThat(result).isEqualTo(expected);
3131
}
3232

src/test/java/io/github/computerdaddyguy/jfiletreeprettyprinter/FilteringTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ void example_childLimit_1() {
9393
filtering/
9494
├─ dir_with_java_files/
9595
│ ├─ file_B.java
96-
│ └─ ... (1 file skipped)
97-
└─ ... (1 file and 2 directories skipped)""";
96+
│ └─ ...
97+
└─ ...""";
9898
assertThat(result).isEqualTo(expected);
9999
}
100100

@@ -118,7 +118,7 @@ void example_childLimit_2() {
118118
│ │ ├─ file_G.java
119119
│ │ └─ file_J.java
120120
│ └─ nested_dir_with_no_java_file/
121-
└─ ... (1 file and 1 directory skipped)""";
121+
└─ ...""";
122122
assertThat(result).isEqualTo(expected);
123123
}
124124

@@ -143,7 +143,7 @@ void example_childLimit_3() {
143143
│ │ └─ file_J.java
144144
│ └─ nested_dir_with_no_java_file/
145145
├─ dir_with_no_java_file/
146-
└─ ... (1 file skipped)""";
146+
└─ ...""";
147147
assertThat(result).isEqualTo(expected);
148148
}
149149

0 commit comments

Comments
 (0)