22
33import io .github .computerdaddyguy .jfiletreeprettyprinter .PrettyPrintOptions ;
44import io .github .computerdaddyguy .jfiletreeprettyprinter .visitor .renderer .LineRenderer ;
5- import java .io .File ;
65import java .io .IOException ;
76import java .nio .file .FileVisitResult ;
87import java .nio .file .Path ;
@@ -17,15 +16,15 @@ class DefaultFileTreePrettyPrintVisitor implements FileTreePrettyPrintVisitor {
1716
1817 private StringBuilder buff ;
1918 private Depth depth ;
20- private ChildVisitCounter counter ;
19+ private ChildVisitRegister register ;
2120
2221 public DefaultFileTreePrettyPrintVisitor (PrettyPrintOptions options , LineRenderer lineRenderer ) {
2322 super ();
2423 this .lineRenderer = lineRenderer ;
2524
2625 this .buff = new StringBuilder ();
2726 this .depth = new Depth ();
28- this .counter = new ChildVisitCounter (options .getChildrenLimitFunction ());
27+ this .register = new ChildVisitRegister (options .getChildrenLimitFunction ());
2928 }
3029
3130 @ Override
@@ -36,7 +35,7 @@ public String getResult() {
3635 @ Override
3736 public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
3837 // COUNTER
39- if (counter .exceedsCurrentLimit ()) {
38+ if (register .exceedsCurrentLimit ()) {
4039 return FileVisitResult .SKIP_SIBLINGS ;
4140 }
4241
@@ -48,19 +47,19 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
4847 depth = depth .append (DepthSymbol .NON_LAST_FILE ); // assume not last until proven otherwise
4948
5049 // COUNTER
51- counter .registerChildVisitInCurrentDir (dir );
52- counter .enterNewDirectory (dir );
50+ register .registerChildVisitInCurrentDir (dir );
51+ register .enterNewDirectory (dir );
5352
5453 return FileVisitResult .CONTINUE ;
5554 }
5655
5756 @ Override
5857 public FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
5958 // COUNTER
60- if (counter .exceedsCurrentLimit ()) {
59+ if (register .exceedsCurrentLimit ()) {
6160 return FileVisitResult .SKIP_SIBLINGS ;
6261 }
63- counter .registerChildVisitInCurrentDir (file );
62+ register .registerChildVisitInCurrentDir (file );
6463
6564 // DEPTH
6665 updateDepth (file );
@@ -95,13 +94,13 @@ public FileVisitResult postVisitDirectory(Path dir, @Nullable IOException exc) t
9594 depth = depth .pop ();
9695
9796 // COUNTER
98- var limitReached = counter .hasSomeNotVisitedChildren ();
97+ var limitReached = register .hasSomeNotVisitedChildren ();
9998 if (limitReached ) {
10099 depth = depth .append (DepthSymbol .LAST_FILE );
101- appendNewLine (lineRenderer .renderLimitReached (depth , counter .notVisitedInCurrentDir ()));
100+ appendNewLine (lineRenderer .renderLimitReached (depth , register .notVisitedInCurrentDir ()));
102101 depth = depth .pop ();
103102 }
104- counter .exitCurrentDirectory ();
103+ register .exitCurrentDirectory ();
105104
106105 if (limitReached ) {
107106 return FileVisitResult .SKIP_SIBLINGS ;
@@ -114,17 +113,11 @@ private void updateDepth(Path path) {
114113 return ;
115114 }
116115
117- var isLast = isLastChild (path );
116+ var isLast = register . isLastChildInCurrentDir (path );
118117 depth = depth .pop ();
119118 depth = depth .append (isLast ? DepthSymbol .LAST_FILE : DepthSymbol .NON_LAST_FILE );
120119 }
121120
122- private boolean isLastChild (Path path ) {
123- Path parent = path .getParent ();
124- File [] siblings = parent .toFile ().listFiles ();
125- return siblings != null && siblings [siblings .length - 1 ].toPath ().equals (path );
126- }
127-
128121 private void appendNewLine (@ Nullable String str ) {
129122 if (str != null ) {
130123 if (buff .length () > 0 ) {
0 commit comments