1919
2020import java .io .IOException ;
2121import java .nio .file .FileVisitResult ;
22+ import java .nio .file .Files ;
2223import java .nio .file .Path ;
2324import java .nio .file .attribute .BasicFileAttributes ;
2425import java .util .ArrayList ;
@@ -69,10 +70,6 @@ public AccumulatorPathVisitor(final PathCounters pathCounter) {
6970 super (pathCounter );
7071 }
7172
72- private void add (final List <Path > list , final Path dir ) {
73- list .add (dir .normalize ());
74- }
75-
7673 @ Override
7774 public boolean equals (final Object obj ) {
7875 if (this == obj ) {
@@ -114,12 +111,6 @@ public int hashCode() {
114111 return result ;
115112 }
116113
117- @ Override
118- public FileVisitResult postVisitDirectory (final Path dir , final IOException exc ) throws IOException {
119- add (dirList , dir );
120- return super .postVisitDirectory (dir , exc );
121- }
122-
123114 /**
124115 * Relativizes each directory path with {@link Path#relativize(Path)} against the given {@code parent}, optionally
125116 * sorting the result.
@@ -129,8 +120,7 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
129120 * @param comparator How to sort, null uses default sorting.
130121 * @return A new list
131122 */
132- public List <Path > relativizeDirectories (final Path parent , final boolean sort ,
133- final Comparator <? super Path > comparator ) {
123+ public List <Path > relativizeDirectories (final Path parent , final boolean sort , final Comparator <? super Path > comparator ) {
134124 return PathUtils .relativize (getDirList (), parent , sort , comparator );
135125 }
136126
@@ -143,14 +133,13 @@ public List<Path> relativizeDirectories(final Path parent, final boolean sort,
143133 * @param comparator How to sort, null uses default sorting.
144134 * @return A new list
145135 */
146- public List <Path > relativizeFiles (final Path parent , final boolean sort ,
147- final Comparator <? super Path > comparator ) {
136+ public List <Path > relativizeFiles (final Path parent , final boolean sort , final Comparator <? super Path > comparator ) {
148137 return PathUtils .relativize (getFileList (), parent , sort , comparator );
149138 }
150139
151140 @ Override
152141 public FileVisitResult visitFile (final Path file , final BasicFileAttributes attributes ) throws IOException {
153- add ( fileList , file );
142+ (( Files . isDirectory ( file )) ? dirList : fileList ). add ( file . normalize () );
154143 return super .visitFile (file , attributes );
155144 }
156145
0 commit comments