Skip to content

Commit 784fcf7

Browse files
Line extension: empty string is permitted
1 parent 56d79c4 commit 784fcf7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515
- `PathUtils` removed, `PathPredicates` rework
16+
- Line extension: empty string is permitted
1617

1718
---
1819
## [0.0.4] - 2025-09-27

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/DefaultTreeEntryRenderer.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.ArrayList;
1212
import java.util.List;
1313
import java.util.Objects;
14+
import java.util.Optional;
1415
import org.jspecify.annotations.NullMarked;
1516

1617
@NullMarked
@@ -40,12 +41,13 @@ private String renderTree(TreeEntry entry, Depth depth) {
4041

4142
private String renderDirectory(Depth depth, DirectoryEntry dirEntry, List<Path> compactPaths) {
4243

44+
Optional<String> extension = null;
4345
if (options.areCompactDirectoriesUsed()
4446
&& !depth.isRoot()
4547
&& dirEntry.getEntries().size() == 1
4648
&& dirEntry.getEntries().get(0) instanceof DirectoryEntry childDirEntry) {
4749

48-
var extension = computeLineExtension(dirEntry.getDir());
50+
extension = computeLineExtension(dirEntry.getDir());
4951
if (extension.isEmpty()) {
5052
var newCompactPaths = new ArrayList<>(compactPaths);
5153
newCompactPaths.add(childDirEntry.getDir());
@@ -54,7 +56,10 @@ private String renderDirectory(Depth depth, DirectoryEntry dirEntry, List<Path>
5456
}
5557

5658
var line = lineRenderer.renderDirectoryBegin(depth, dirEntry, compactPaths);
57-
line += computeLineExtension(dirEntry.getDir());
59+
if (extension == null) {
60+
extension = computeLineExtension(dirEntry.getDir());
61+
}
62+
line += extension.orElse("");
5863

5964
var childIt = dirEntry.getEntries().iterator();
6065

@@ -76,17 +81,16 @@ private String renderDirectory(Depth depth, DirectoryEntry dirEntry, List<Path>
7681
return line + childLines.toString();
7782
}
7883

79-
private String computeLineExtension(Path path) {
84+
private Optional<String> computeLineExtension(Path path) {
8085
if (options.getLineExtension() == null) {
81-
return "";
86+
return Optional.empty();
8287
}
83-
var extension = options.getLineExtension().apply(path);
84-
return extension == null ? "" : extension;
88+
return Optional.ofNullable(options.getLineExtension().apply(path));
8589
}
8690

8791
private String renderFile(Depth depth, FileEntry fileEntry) {
8892
var line = lineRenderer.renderFile(depth, fileEntry);
89-
line += computeLineExtension(fileEntry.getFile());
93+
line += computeLineExtension(fileEntry.getFile()).orElse("");
9094
return line;
9195
}
9296

0 commit comments

Comments
 (0)