Skip to content

Commit 985d1fa

Browse files
Fix Sorting to be consistent across systems (local & Github actions
1 parent 70708c8 commit 985d1fa

File tree

18 files changed

+292
-60
lines changed

18 files changed

+292
-60
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A lightweight Java library for printing directory structures in a clean, tree-li
77
- Limit displayed children (fixed value or dynamically)
88
- Compact directory chains
99
- Maximum depth
10-
- File sort
10+
- Sorting
1111

1212
> [!CAUTION]
1313
> This lib was developed just for fun, and has not been thoroughly tested!
@@ -227,28 +227,29 @@ max_depth/
227227
```
228228

229229
## Sorting
230-
Files and directories can be sorted using a custom comparator (default is alphabetical order). Class `PrettyPrintOptions.Sorts` helps you by providing some basic comparators.
230+
Files and directories can be sorted using a custom comparator (default is alphabetical order).
231+
If the provided comparator considers two paths equal (i.e., returns `0`), an alphabetical comparator is applied as a tie-breaker to ensure consistent results across all systems.
232+
233+
The `PrettyPrintOptions.Sorts` class provides a set of basic, ready-to-use comparators.
231234

232235
```java
233236
// Example: Sorting.java
234237
var prettyPrinter = FileTreePrettyPrinter.builder()
235-
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.ALPHABETICAL_ORDER.reversed()))
238+
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.DIRECTORY_FIRST))
236239
.build();
237240
```
238241
```
239-
file_sort/
240-
├─ dir_C/
241-
│ ├─ file_C_3
242-
│ ├─ file_C_2
243-
│ └─ file_C_1
244-
├─ dir_B/
245-
│ ├─ file_B_3
246-
│ ├─ file_B_2
247-
│ └─ file_B_1
248-
└─ dir_A/
249-
├─ file_A_3
250-
├─ file_A_2
251-
└─ file_A_1
242+
sorting/
243+
├─ c_dir/
244+
│ └─ c_file
245+
├─ d_dir/
246+
│ ├─ d_b_dir/
247+
│ │ └─ d_b_file
248+
│ └─ d_a_file
249+
├─ a_file
250+
├─ b_file
251+
├─ x_file
252+
└─ y_file
252253
```
253254

254255
# Changelog

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>io.github.computerdaddyguy</groupId>
77
<artifactId>jfiletreeprettyprinter</artifactId>
8-
<version>0.0.2</version>
8+
<version>0.0.2-SNAPSHOT</version>
99

1010
<packaging>jar</packaging>
1111
<name>JFileTreePrettyPrinter</name>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public class Sorting {
77

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

src/example/resources/file_sort/dir_A/file_A_2

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/example/resources/file_sort/dir_A/file_A_3

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/example/resources/file_sort/dir_B/file_B_2

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/example/resources/file_sort/dir_B/file_B_3

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/example/resources/file_sort/dir_C/file_C_2

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/example/resources/file_sort/dir_C/file_C_3

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123456

0 commit comments

Comments
 (0)