66
77import com .jcabi .log .Logger ;
88import java .io .File ;
9- import java .nio .file .Files ;
109import java .nio .file .Path ;
1110
1211/**
@@ -18,27 +17,34 @@ final class EmptyDirectoriesIn {
1817 /**
1918 * Root path.
2019 */
21- private final Path root ;
20+ private final File root ;
2221
2322 /**
2423 * Ctor.
2524 * @param root Root directory.
2625 */
2726 EmptyDirectoriesIn (final Path root ) {
27+ this (root .toFile ());
28+ }
29+
30+ /**
31+ * Ctor.
32+ * @param root Root directory
33+ */
34+ EmptyDirectoriesIn (final File root ) {
2835 this .root = root ;
2936 }
3037
3138 /**
3239 * Clear empty directories in {@code this.root}.
3340 */
3441 void clear () {
35- if (Files .isDirectory (this .root )) {
36- this .delete (this .root .toFile ());
37- } else {
42+ if (!this .root .isDirectory ()) {
3843 throw new IllegalStateException (
3944 Logger .format ("Provided path %[file]s is not a directory" , this .root )
4045 );
4146 }
47+ this .delete (this .root );
4248 }
4349
4450 /**
@@ -47,23 +53,20 @@ void clear() {
4753 * @checkstyle NestedIfDepthCheck (20 lines)
4854 */
4955 private void delete (final File dir ) {
50- if (dir .isDirectory ()) {
51- final File [] before = dir .listFiles ();
52- if (before != null ) {
53- for (final File file : before ) {
54- if (file .isDirectory ()) {
55- this .delete (file );
56- }
56+ if (!dir .isDirectory ()) {
57+ return ;
58+ }
59+ final File [] before = dir .listFiles ();
60+ if (before != null ) {
61+ for (final File file : before ) {
62+ if (file .isDirectory ()) {
63+ this .delete (file );
5764 }
5865 }
59- final File [] after = dir .listFiles ();
60- if (after != null
61- && after .length == 0
62- && !dir .equals (this .root .toFile ())
63- && dir .delete ()
64- ) {
65- Logger .debug (EmptyDirectoriesIn .class , "Deleted empty directory %[file]s" , dir );
66- }
66+ }
67+ final File [] after = dir .listFiles ();
68+ if (after != null && after .length == 0 && !dir .equals (this .root ) && dir .delete ()) {
69+ Logger .debug (EmptyDirectoriesIn .class , "Deleted empty directory %[file]s" , dir );
6770 }
6871 }
6972}
0 commit comments