aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-06-30 00:32:04 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-30 13:00:58 +0200
commit3d2a68c6da2a50a9e1bcf6615e83a43701cdf95d (patch)
tree31692a985d316e33733ab6993e529b8a08c206b6 /src/main/java/com/google/devtools/build/lib/vfs
parent2d5eeab381713f99c8c8b7b80f3d447be847b548 (diff)
Automated conversion to Java 8
With a few manual fixes for readability. RELNOTES: None. PiperOrigin-RevId: 160582556
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/Path.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java48
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java11
6 files changed, 36 insertions, 75 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
index 5b3bc1e717..698b671d04 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
@@ -981,15 +981,13 @@ public class FileSystemUtils {
// (a) name the function, (b) put it in a box and (c) use List not array
// because of the generic type. *sigh*.
final List<Predicate<Path>> dumpFunction = new ArrayList<>();
- dumpFunction.add(new Predicate<Path>() {
- @Override
- public boolean apply(Path child) {
+ dumpFunction.add(
+ child -> {
Path path = child;
out.println(" " + path + " (" + path.toDebugString() + ")");
path.applyToChildren(dumpFunction.get(0));
return false;
- }
- });
+ });
fs.getRootDirectory().applyToChildren(dumpFunction.get(0));
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index d5aa5eef85..b41589caae 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -13,9 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.vfs;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.util.StringCanonicalizer;
@@ -505,7 +505,7 @@ public class Path implements Comparable<Path>, Serializable {
*/
public Collection<Path> getDirectoryEntries(Predicate<? super Path> predicate)
throws IOException, FileNotFoundException {
- return ImmutableList.<Path>copyOf(Iterables.filter(getDirectoryEntries(), predicate));
+ return getDirectoryEntries().stream().filter(predicate).collect(toImmutableList());
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
index caad724f83..3f5ba0ef1b 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
@@ -13,8 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.vfs;
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
+
import com.google.common.base.Function;
-import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -58,29 +59,8 @@ public abstract class PathFragment implements Comparable<PathFragment>, Serializ
/** An empty path fragment. */
public static final PathFragment EMPTY_FRAGMENT = create("");
- public static final Function<String, PathFragment> TO_PATH_FRAGMENT =
- new Function<String, PathFragment>() {
- @Override
- public PathFragment apply(String str) {
- return create(str);
- }
- };
-
- public static final Predicate<PathFragment> IS_ABSOLUTE =
- new Predicate<PathFragment>() {
- @Override
- public boolean apply(PathFragment input) {
- return input.isAbsolute();
- }
- };
-
- private static final Function<PathFragment, String> TO_SAFE_PATH_STRING =
- new Function<PathFragment, String>() {
- @Override
- public String apply(PathFragment path) {
- return path.getSafePathString();
- }
- };
+ // TODO(laurentlb): Inline this
+ public static final Function<String, PathFragment> TO_PATH_FRAGMENT = PathFragment::create;
/**
* A helper object for manipulating the various internal {@link PathFragment} implementations.
@@ -332,22 +312,16 @@ public abstract class PathFragment implements Comparable<PathFragment>, Serializ
* {@code fragments}.
*/
public static Iterable<String> safePathStrings(Iterable<PathFragment> fragments) {
- return Iterables.transform(fragments, TO_SAFE_PATH_STRING);
+ return Iterables.transform(fragments, PathFragment::getSafePathString);
}
/** Returns the subset of {@code paths} that start with {@code startingWithPath}. */
- public static ImmutableSet<PathFragment> filterPathsStartingWith(Set<PathFragment> paths,
- PathFragment startingWithPath) {
- return ImmutableSet.copyOf(Iterables.filter(paths, startsWithPredicate(startingWithPath)));
- }
-
- public static Predicate<PathFragment> startsWithPredicate(final PathFragment prefix) {
- return new Predicate<PathFragment>() {
- @Override
- public boolean apply(PathFragment pathFragment) {
- return pathFragment.startsWith(prefix);
- }
- };
+ public static ImmutableSet<PathFragment> filterPathsStartingWith(
+ Set<PathFragment> paths, PathFragment startingWithPath) {
+ return paths
+ .stream()
+ .filter(pathFragment -> pathFragment.startsWith(startingWithPath))
+ .collect(toImmutableSet());
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
index 771b11a925..378f7275a3 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
@@ -615,18 +615,16 @@ public final class UnixGlob {
totalOps.incrementAndGet();
pendingOps.incrementAndGet();
- Runnable wrapped = new Runnable() {
- @Override
- public void run() {
- try {
- if (!canceled && failure.get() == null) {
- r.run();
+ Runnable wrapped =
+ () -> {
+ try {
+ if (!canceled && failure.get() == null) {
+ r.run();
+ }
+ } finally {
+ decrementAndCheckDone();
}
- } finally {
- decrementAndCheckDone();
- }
- }
- };
+ };
if (executor == null) {
wrapped.run();
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
index 353a684a82..5419f7a1f8 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/ZipFileSystem.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.google.devtools.build.lib.vfs;
-import com.google.common.base.Predicate;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.Path.PathFactory;
@@ -205,15 +204,14 @@ public class ZipFileSystem extends ReadonlyFileSystem implements Closeable {
Preconditions.checkState(open);
zipEntryNonNull(path);
final Collection<Path> result = new ArrayList<>();
- ((ZipPath) path).applyToChildren(new Predicate<Path>() {
- @Override
- public boolean apply(Path child) {
- if (zipEntry(child) != null) {
- result.add(child);
- }
- return true;
- }
- });
+ ((ZipPath) path)
+ .applyToChildren(
+ child -> {
+ if (zipEntry(child) != null) {
+ result.add(child);
+ }
+ return true;
+ });
return result;
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
index 35a745a7b9..f47eb72a3c 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryDirectoryInfo.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.google.devtools.build.lib.vfs.inmemoryfs;
-import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.devtools.build.lib.concurrent.ThreadSafety;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
@@ -29,13 +28,6 @@ import java.util.concurrent.ConcurrentMap;
*/
@ThreadSafe
class InMemoryDirectoryInfo extends InMemoryContentInfo {
- private static final Function<InMemoryFileName, String> FILENAME_TO_STRING =
- new Function<InMemoryFileName, String>() {
- @Override
- public String apply(InMemoryFileName inMemoryFileName) {
- return inMemoryFileName.value;
- }
- };
private final ConcurrentMap<InMemoryFileName, InMemoryContentInfo> directoryContent =
new ConcurrentHashMap<>();
@@ -88,7 +80,8 @@ class InMemoryDirectoryInfo extends InMemoryContentInfo {
* changed later.
*/
Collection<String> getAllChildren() {
- return Collections2.transform(directoryContent.keySet(), FILENAME_TO_STRING);
+ return Collections2.transform(
+ directoryContent.keySet(), inMemoryFileName -> inMemoryFileName.value);
}
@Override