Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
---
## [0.0.6] - Unreleased

### Changed
- Child limit: do not print skipped children count
- Max depth: do not print "max depth reached"

---
## [0.0.5] - 2025-10-04

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var prettyPrinter = FileTreePrettyPrinter.builder()
> *Idea for a future version: option to allow custom emoji mapping*

## Child limit
You can set a fixed limit to the number of children displayed for each directory.
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.

```java
// Example: ChildLimitStatic.java
Expand All @@ -202,13 +202,13 @@ child_limit_static/
│ ├─ file_1_1
│ ├─ file_1_2
│ ├─ file_1_3
│ └─ ... (2 files skipped)
│ └─ ...
├─ folder_2/
│ ├─ file_2_1
│ ├─ file_2_2
│ ├─ file_2_3
│ └─ ... (2 files skipped)
└─ ... (3 directories skipped)
│ └─ ...
└─ ...

```

Expand Down Expand Up @@ -237,7 +237,7 @@ child_limit_dynamic/
│ ├─ file_1_4
│ └─ file_1_5
└─ node_modules/
└─ ... (9 files skipped)
└─ ...
```

## Line extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public static void main(String[] args) {
├─ 📂 src/main/java/
│ └─ 📂 io/github/computerdaddyguy/jfiletreeprettyprinter/
│ ├─ 📂 renderer/
│ │ └─ ... (5 files and 2 directories skipped)
│ │ └─ ...
│ ├─ 📂 scanner/
│ │ └─ ... (4 files skipped)
│ │ └─ ...
│ ├─ ☕ FileTreePrettyPrinter.java // Main entry point
│ └─ ... (10 files skipped)
│ └─ ...
├─ 🗺️ CHANGELOG.md
├─ 📖 CONTRIBUTING.md
├─ 📄 LICENSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -33,51 +32,12 @@ public String formatFile(FileEntry fileEntry) {

@Override
public String formatChildLimitReached(SkippedChildrenEntry skippedChildrenEntry) {
return "... (" + childrenAsString(skippedChildrenEntry.getSkippedChildren()) + " skipped)";
return "...";
}

@Override
public String formatMaxDepthReached(MaxDepthReachEntry maxDepthReachEntry) {
return "... (max depth reached)";
}

private String childrenAsString(Collection<Path> notVisited) {

var dirCount = countDirs(notVisited);
var fileCount = countFiles(notVisited, dirCount);

var dirText = dirText(dirCount);
var fileText = fileText(fileCount);

return fileText + (!fileText.isEmpty() && !dirText.isEmpty() ? " and " : "") + dirText;
}

private long countDirs(Collection<Path> notVisited) {
return notVisited.stream().filter(path -> path.toFile().isDirectory()).count();
}

private String dirText(long dirCount) {
if (dirCount == 0) {
return "";
}
if (dirCount == 1) {
return "1 directory";
}
return dirCount + " directories";
}

private long countFiles(Collection<Path> notVisited, long dirCount) {
return notVisited.size() - dirCount;
}

private String fileText(long fileCount) {
if (fileCount == 0) {
return "";
}
if (fileCount == 1) {
return "1 file";
}
return fileCount + " files";
return "...";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,7 @@ private List<TreeEntry> handleDirectoryChildren(Path root, int depth, Path dir,

// Loop has early exit?
if (pathIterator.hasNext()) {
childEntries.addAll(handleLeftOverChildren(root, depth, pathIterator, filter));
}

return childEntries;
}

private List<TreeEntry> handleLeftOverChildren(Path root, int depth, Iterator<Path> pathIterator, PathMatcher filter) {
var childEntries = new ArrayList<TreeEntry>();

var skippedChildren = new ArrayList<Path>();
while (pathIterator.hasNext()) {
var child = pathIterator.next();
var childEntry = handle(root, depth + 1, child, filter);
if (childEntry != null) { // Is null if no children file is retained by filter
skippedChildren.add(child);
}
}
if (!skippedChildren.isEmpty()) {
var childrenSkippedEntry = new SkippedChildrenEntry(skippedChildren);
childEntries.add(childrenSkippedEntry);
childEntries.add(new SkippedChildrenEntry(dir));
}

return childEntries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -62,19 +61,15 @@ public BasicFileAttributes getAttrs() {

final class SkippedChildrenEntry implements TreeEntry {

final Collection<Path> skippedChildren;
final Path dir;

public SkippedChildrenEntry(List<Path> skippedChildren) {
this.skippedChildren = Objects.requireNonNull(skippedChildren, "skippedChildren is null");
public SkippedChildrenEntry(Path dir) {
this.dir = Objects.requireNonNull(dir, "dir is null");
}

@Override
public String toString() {
return "SkippedChildrenEntry[skippedChildren: " + skippedChildren.stream().map(Path::getFileName).toList() + "]";
}

public Collection<Path> getSkippedChildren() {
return skippedChildren;
return "SkippedChildrenEntry[dir: " + dir.getFileName() + "]";
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ void nominal() {
targetPath/
├─ limit_1/
│ ├─ file1
│ └─ ... (4 files skipped)
│ └─ ...
├─ limit_3/
│ ├─ file1
│ ├─ file2
│ ├─ file3
│ └─ ... (2 files skipped)
│ └─ ...
└─ simpleDir/
├─ file1
├─ file2
Expand All @@ -91,7 +91,7 @@ void limited_dir_1() {
targetPath/
└─ limit_1/
├─ file1
└─ ... (4 files skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -114,7 +114,7 @@ void limited_dir_3() {
├─ file1
├─ file2
├─ file3
└─ ... (2 files skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void dirWith_1_extra_file() {
├─ file1
├─ file2
├─ file3
└─ ... (1 file skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -79,7 +79,7 @@ void dirWith_2_extra_files() {
├─ file1
├─ file2
├─ file3
└─ ... (2 files skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -92,7 +92,7 @@ void dirWith_2_extra_files_and_1_extra_folder() {
├─ file1
├─ file2
├─ file3
└─ ... (2 files and 1 directory skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -105,7 +105,7 @@ void dirWith_2_extra_files_and_2_extra_folders() {
├─ file1
├─ file2
├─ file3
└─ ... (2 files and 2 directories skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void withOptions_overrides() {
targetPath/
├─ file1
├─ file2
└─ ... (1 file and 3 directories skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ void example_childLimit_1() {
filtering/
├─ dir_with_java_files/
│ ├─ file_B.java
│ └─ ... (1 file skipped)
└─ ... (1 file and 2 directories skipped)""";
│ └─ ...
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -118,7 +118,7 @@ void example_childLimit_2() {
│ │ ├─ file_G.java
│ │ └─ file_J.java
│ └─ nested_dir_with_no_java_file/
└─ ... (1 file and 1 directory skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand All @@ -143,7 +143,7 @@ void example_childLimit_3() {
│ │ └─ file_J.java
│ └─ nested_dir_with_no_java_file/
├─ dir_with_no_java_file/
└─ ... (1 file skipped)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void withCompactDirectories() {
var expected = """
targetPath/
└─ level1/level2/
└─ ... (max depth reached)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ void nominal() {
├─ file1#2
├─ file1#3
└─ level2/
└─ ... (max depth reached)""";
└─ ...""";
assertThat(result).isEqualTo(expected);
}

Expand Down
Loading