Skip to content

Commit 69babec

Browse files
Cleanup sorting
1 parent fe63b15 commit 69babec

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.3] - Unreleased
9+
10+
### Changed
11+
- Sorting: option method `withFileSort` renamed in `sort`
12+
13+
814
## [0.0.2] - 2025-09-16
915

1016
### Added
11-
1217
- Option: sorting files and directories
1318
- 39 new default files & extension mappings for emojis
1419

20+
1521
## [0.0.1] - 2025-09-14
1622

1723
### Added
18-
1924
- Initial release
2025
- Option: tree format Unicode box drawing / classic ASCII
2126
- Option: use emojis

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ The `PrettyPrintOptions.Sorts` class provides a set of basic, ready-to-use compa
235235
```java
236236
// Example: Sorting.java
237237
var prettyPrinter = FileTreePrettyPrinter.builder()
238-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
238+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
239239
.build();
240240
```
241241
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Sorting {
77

88
public static void main(String[] args) {
99
var prettyPrinter = FileTreePrettyPrinter.builder()
10-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.BY_FILE_SIZE))
10+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
1111
.build();
1212
var tree = prettyPrinter.prettyPrint("src/example/resources/sorting");
1313
System.out.println(tree);

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/PrettyPrintOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public Comparator<Path> pathComparator() {
273273
*
274274
* @param pathComparator The custom comparator
275275
*/
276-
public PrettyPrintOptions withFileSort(Comparator<Path> pathComparator) {
276+
public PrettyPrintOptions sort(Comparator<Path> pathComparator) {
277277
this.pathComparator = Objects.requireNonNull(pathComparator, "pathComparator is null").thenComparing(Sorts.BY_NAME);
278278
return this;
279279
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ private TreeEntry handleDirectory(int depth, Path dir) {
7878
}
7979

8080
private Iterator<Path> directoryStreamToIterator(DirectoryStream<Path> childrenStream) {
81-
var comparator = options.pathComparator();
82-
if (comparator != null) {
83-
return StreamSupport.stream(childrenStream.spliterator(), false)
84-
.sorted(comparator)
85-
.iterator();
86-
}
87-
return childrenStream.iterator();
81+
return StreamSupport.stream(childrenStream.spliterator(), false)
82+
.sorted(options.pathComparator())
83+
.iterator();
8884
}
8985

9086
private TreeEntry handleFile(Path file) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Comparator;
55
import java.util.function.ToIntFunction;
66
import org.jspecify.annotations.NullMarked;
7-
import org.jspecify.annotations.Nullable;
87

98
@NullMarked
109
public interface ScanningOptions {
@@ -13,7 +12,6 @@ public interface ScanningOptions {
1312

1413
ToIntFunction<Path> getChildrenLimitFunction();
1514

16-
@Nullable
1715
Comparator<Path> pathComparator();
1816

1917
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SortingTest {
1616
void example() {
1717

1818
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
19-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
19+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
2020
.build();
2121

2222
var result = printer.prettyPrint(Path.of("src/example/resources/sorting"));
@@ -80,7 +80,7 @@ void defaultOrderIsAlphabetical() {
8080
void alphabetical_reversed() {
8181

8282
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
83-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.BY_NAME.reversed()))
83+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.BY_NAME.reversed()))
8484
.build();
8585

8686
var result = printer.prettyPrint(buildDefaultPath());
@@ -107,7 +107,7 @@ void alphabetical_reversed() {
107107
void fileSize() {
108108

109109
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
110-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.BY_FILE_SIZE))
110+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.BY_FILE_SIZE))
111111
.build();
112112

113113
var result = printer.prettyPrint(Path.of("src/example/resources/sorting"));
@@ -151,7 +151,7 @@ private Path build_directoryFirstOrLast_paths() {
151151
void directoriesFirst() {
152152

153153
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
154-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
154+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
155155
.build();
156156

157157
var result = printer.prettyPrint(build_directoryFirstOrLast_paths());
@@ -174,7 +174,7 @@ void directoriesFirst() {
174174
void directoriesLast() {
175175

176176
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
177-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.DIRECTORY_LAST))
177+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.DIRECTORY_LAST))
178178
.build();
179179

180180
var result = printer.prettyPrint(build_directoryFirstOrLast_paths());
@@ -217,7 +217,7 @@ private Path build_extension_paths() {
217217
void byExtension() {
218218

219219
FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
220-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.BY_EXTENSION))
220+
.customizeOptions(options -> options.sort(PrettyPrintOptions.Sorts.BY_EXTENSION))
221221
.build();
222222

223223
var result = printer.prettyPrint(build_extension_paths());

0 commit comments

Comments
 (0)