Skip to content

Commit

Permalink
Refactor file tree children logic to separate method just like in Mor…
Browse files Browse the repository at this point in the history
…eFiles.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175700154
  • Loading branch information
nymanjens authored and cpovirk committed Nov 14, 2017
1 parent 6220cea commit 086f67c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 14 additions & 10 deletions android/guava/src/com/google/common/io/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,7 @@ public static TreeTraverser<File> fileTreeTraverser() {
new TreeTraverser<File>() {
@Override
public Iterable<File> children(File file) {
// check isDirectory() just because it may be faster than listFiles() on a non-directory
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
return Collections.unmodifiableList(Arrays.asList(files));
}
}

return Collections.emptyList();
return fileTreeChildren(file);
}

@Override
Expand Down Expand Up @@ -872,10 +864,22 @@ public static Traverser<File> fileTraverser() {
new SuccessorsFunction<File>() {
@Override
public Iterable<File> successors(File file) {
return FILE_TREE_TRAVERSER.children(file);
return fileTreeChildren(file);
}
};

private static Iterable<File> fileTreeChildren(File file) {
// check isDirectory() just because it may be faster than listFiles() on a non-directory
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
return Collections.unmodifiableList(Arrays.asList(files));
}
}

return Collections.emptyList();
}

/**
* Returns a predicate that returns the result of {@link File#isDirectory} on input files.
*
Expand Down
24 changes: 14 additions & 10 deletions guava/src/com/google/common/io/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,7 @@ public static TreeTraverser<File> fileTreeTraverser() {
new TreeTraverser<File>() {
@Override
public Iterable<File> children(File file) {
// check isDirectory() just because it may be faster than listFiles() on a non-directory
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
return Collections.unmodifiableList(Arrays.asList(files));
}
}

return Collections.emptyList();
return fileTreeChildren(file);
}

@Override
Expand Down Expand Up @@ -872,10 +864,22 @@ public static Traverser<File> fileTraverser() {
new SuccessorsFunction<File>() {
@Override
public Iterable<File> successors(File file) {
return FILE_TREE_TRAVERSER.children(file);
return fileTreeChildren(file);
}
};

private static Iterable<File> fileTreeChildren(File file) {
// check isDirectory() just because it may be faster than listFiles() on a non-directory
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
return Collections.unmodifiableList(Arrays.asList(files));
}
}

return Collections.emptyList();
}

/**
* Returns a predicate that returns the result of {@link File#isDirectory} on input files.
*
Expand Down

0 comments on commit 086f67c

Please sign in to comment.