Skip to content

Commit aef14b2

Browse files
Fix Sonar issues
1 parent 1d46b07 commit aef14b2

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,32 @@ private List<TreeEntry> handleDirectoryChildren(int depth, Path dir, Predicate<P
9090

9191
// Loop has early exit?
9292
if (pathIterator.hasNext()) {
93-
if (filter == null) {
94-
var skippedChildren = new ArrayList<Path>();
95-
pathIterator.forEachRemaining(skippedChildren::add);
93+
childEntries.addAll(handleLeftOverChildren(depth, filter, pathIterator));
94+
}
95+
96+
return childEntries;
97+
}
98+
99+
private List<TreeEntry> handleLeftOverChildren(int depth, Predicate<Path> filter, Iterator<Path> pathIterator) {
100+
var childEntries = new ArrayList<TreeEntry>();
101+
102+
if (filter == null) {
103+
var skippedChildren = new ArrayList<Path>();
104+
pathIterator.forEachRemaining(skippedChildren::add);
105+
var childrenSkippedEntry = new SkippedChildrenEntry(skippedChildren);
106+
childEntries.add(childrenSkippedEntry);
107+
} else {
108+
var skippedChildren = new ArrayList<Path>();
109+
while (pathIterator.hasNext()) {
110+
var child = pathIterator.next();
111+
var childEntry = handle(depth + 1, child, filter);
112+
if (childEntry != null) { // Is null if no children file is retained by filter
113+
skippedChildren.add(child);
114+
}
115+
}
116+
if (!skippedChildren.isEmpty()) {
96117
var childrenSkippedEntry = new SkippedChildrenEntry(skippedChildren);
97118
childEntries.add(childrenSkippedEntry);
98-
} else {
99-
var skippedChildren = new ArrayList<Path>();
100-
while (pathIterator.hasNext()) {
101-
var child = pathIterator.next();
102-
var childEntry = handle(depth + 1, child, filter);
103-
if (childEntry != null) { // Is null if no children file is retained by filter
104-
skippedChildren.add(child);
105-
}
106-
}
107-
if (!skippedChildren.isEmpty()) {
108-
var childrenSkippedEntry = new SkippedChildrenEntry(skippedChildren);
109-
childEntries.add(childrenSkippedEntry);
110-
}
111119
}
112120
}
113121

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import io.github.computerdaddyguy.jfiletreeprettyprinter.PrettyPrintOptions.Sorts;
6-
import java.nio.file.Path;
76
import org.junit.jupiter.api.Test;
8-
import org.junit.jupiter.api.io.TempDir;
97

108
class FilteringTest {
119

12-
@TempDir
13-
private Path root;
14-
1510
@Test
1611
void example() {
1712

0 commit comments

Comments
 (0)