diff options
author | 2017-06-30 00:32:04 +0200 | |
---|---|---|
committer | 2017-06-30 13:00:58 +0200 | |
commit | 3d2a68c6da2a50a9e1bcf6615e83a43701cdf95d (patch) | |
tree | 31692a985d316e33733ab6993e529b8a08c206b6 /src/main/java/com/google/devtools/build/lib/actions | |
parent | 2d5eeab381713f99c8c8b7b80f3d447be847b548 (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/actions')
5 files changed, 55 insertions, 129 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporter.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporter.java index a15165bd68..fd3dfd58ba 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporter.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporter.java @@ -13,6 +13,8 @@ // limitations under the License. package com.google.devtools.build.lib.actions; +import static java.util.Comparator.comparing; + import com.google.common.annotations.VisibleForTesting; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -137,7 +139,7 @@ public final class ActionExecutionStatusReporter { if (actions.isEmpty()) { return; } - Collections.sort(actions, Pair.<Long, ActionExecutionMetadata>compareByFirst()); + Collections.sort(actions, comparing(arg -> arg.first)); buffer.append("\n " + status + ":"); diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java b/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java index c4567d8ce4..1a19d281d3 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java @@ -129,19 +129,11 @@ public final class ActionInputHelper { return fromPath(path.getPathString()); } - private static final Function<String, ActionInput> FROM_PATH = - new Function<String, ActionInput>() { - @Override - public ActionInput apply(String path) { - return fromPath(path); - } - }; - /** * Creates a sequence of {@link ActionInput}s from a sequence of string paths. */ public static Collection<ActionInput> fromPaths(Collection<String> paths) { - return Collections2.transform(paths, FROM_PATH); + return Collections2.transform(paths, ActionInputHelper::fromPath); } /** @@ -178,13 +170,8 @@ public final class ActionInputHelper { final Artifact parent, Iterable<? extends PathFragment> parentRelativePaths) { Preconditions.checkState(parent.isTreeArtifact(), "Given parent %s must be a TreeArtifact", parent); - return Iterables.transform(parentRelativePaths, - new Function<PathFragment, TreeFileArtifact>() { - @Override - public TreeFileArtifact apply(PathFragment pathFragment) { - return treeFileArtifact(parent, pathFragment); - } - }); + return Iterables.transform( + parentRelativePaths, pathFragment -> treeFileArtifact(parent, pathFragment)); } /** Returns a Set of TreeFileArtifacts with the given parent and parent-relative paths. */ @@ -224,12 +211,7 @@ public final class ActionInputHelper { /** Formatter for execPath String output. Public because {@link Artifact} uses it directly. */ public static final Function<ActionInput, String> EXEC_PATH_STRING_FORMATTER = - new Function<ActionInput, String>() { - @Override - public String apply(ActionInput input) { - return input.getExecPathString(); - } - }; + ActionInput::getExecPathString; public static Iterable<String> toExecPaths(Iterable<? extends ActionInput> artifacts) { return Iterables.transform(artifacts, EXEC_PATH_STRING_FORMATTER); diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupValue.java b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupValue.java index 9fdbe1ca8b..6b07feec64 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupValue.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.actions; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.collect.ImmutableList; @@ -157,14 +156,7 @@ public class ActionLookupValue implements SkyValue { public static Map<Artifact, ActionAnalysisMetadata> getMapForConsistencyCheck( Map<Artifact, Integer> generatingActionIndex, final List<? extends ActionAnalysisMetadata> actions) { - return Maps.transformValues( - generatingActionIndex, - new Function<Integer, ActionAnalysisMetadata>() { - @Override - public ActionAnalysisMetadata apply(Integer index) { - return actions.get(index); - } - }); + return Maps.transformValues(generatingActionIndex, actions::get); } /** diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java index 4a956db6aa..05d66df2d4 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java @@ -14,6 +14,9 @@ package com.google.devtools.build.lib.actions; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static java.util.Comparator.comparing; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Functions; @@ -21,7 +24,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Ordering; +import com.google.common.collect.Streams; import com.google.devtools.build.lib.actions.ActionAnalysisMetadata.MiddlemanType; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; @@ -104,32 +107,23 @@ import javax.annotation.Nullable; public class Artifact implements FileType.HasFilename, ActionInput, SkylarkValue, Comparable<Object> { - /** - * Compares artifact according to their exec paths. Sorts null values first. - */ - public static final Comparator<Artifact> EXEC_PATH_COMPARATOR = new Comparator<Artifact>() { - @Override - public int compare(Artifact a, Artifact b) { - if (a == b) { - return 0; - } else if (a == null) { - return -1; - } else if (b == null) { - return -1; - } else { - return a.execPath.compareTo(b.execPath); - } - } - }; + /** Compares artifact according to their exec paths. Sorts null values first. */ + public static final Comparator<Artifact> EXEC_PATH_COMPARATOR = + (a, b) -> { + if (a == b) { + return 0; + } else if (a == null) { + return -1; + } else if (b == null) { + return -1; + } else { + return a.execPath.compareTo(b.execPath); + } + }; /** Compares artifacts according to their root relative paths. */ public static final Comparator<Artifact> ROOT_RELATIVE_PATH_COMPARATOR = - new Comparator<Artifact>() { - @Override - public int compare(Artifact lhs, Artifact rhs) { - return lhs.getRootRelativePath().compareTo(rhs.getRootRelativePath()); - } - }; + comparing(Artifact::getRootRelativePath); @Override public int compareTo(Object o) { @@ -154,25 +148,8 @@ public class Artifact public static final ImmutableList<Artifact> NO_ARTIFACTS = ImmutableList.of(); - /** - * A Predicate that evaluates to true if the Artifact is not a middleman artifact. - */ - public static final Predicate<Artifact> MIDDLEMAN_FILTER = new Predicate<Artifact>() { - @Override - public boolean apply(Artifact input) { - return !input.isMiddlemanArtifact(); - } - }; - - /** - * A Predicate that evaluates to true if the Artifact <b>is</b> a tree artifact. - */ - public static final Predicate<Artifact> IS_TREE_ARTIFACT = new Predicate<Artifact>() { - @Override - public boolean apply(Artifact input) { - return input.isTreeArtifact(); - } - }; + /** A Predicate that evaluates to true if the Artifact is not a middleman artifact. */ + public static final Predicate<Artifact> MIDDLEMAN_FILTER = input -> !input.isMiddlemanArtifact(); private final int hashCode; private final Path path; @@ -664,35 +641,12 @@ public class Artifact return result; } - //--------------------------------------------------------------------------- + // --------------------------------------------------------------------------- // Static methods to assist in working with Artifacts - /** - * Formatter for execPath PathFragment output. - */ - private static final Function<Artifact, PathFragment> EXEC_PATH_FORMATTER = - new Function<Artifact, PathFragment>() { - @Override - public PathFragment apply(Artifact input) { - return input.getExecPath(); - } - }; - + /** Formatter for execPath PathFragment output. */ public static final Function<Artifact, String> ROOT_RELATIVE_PATH_STRING = - new Function<Artifact, String>() { - @Override - public String apply(Artifact artifact) { - return artifact.getRootRelativePath().getPathString(); - } - }; - - public static final Function<Artifact, String> ABSOLUTE_PATH_STRING = - new Function<Artifact, String>() { - @Override - public String apply(Artifact artifact) { - return artifact.getPath().getPathString(); - } - }; + artifact -> artifact.getRootRelativePath().getPathString(); /** * Converts a collection of artifacts into execution-time path strings, and @@ -724,7 +678,7 @@ public class Artifact public static Iterable<String> toAbsolutePaths(Iterable<Artifact> artifacts) { return Iterables.transform( Iterables.filter(artifacts, MIDDLEMAN_FILTER), - ABSOLUTE_PATH_STRING); + artifact -> artifact.getPath().getPathString()); } /** @@ -734,7 +688,7 @@ public class Artifact public static Iterable<String> toRootRelativePaths(Iterable<Artifact> artifacts) { return Iterables.transform( Iterables.filter(artifacts, MIDDLEMAN_FILTER), - ROOT_RELATIVE_PATH_STRING); + artifact -> artifact.getRootRelativePath().getPathString()); } /** @@ -800,7 +754,7 @@ public class Artifact */ public static void addExpandedExecPaths(Iterable<Artifact> artifacts, Collection<PathFragment> output, ArtifactExpander artifactExpander) { - addExpandedArtifacts(artifacts, output, EXEC_PATH_FORMATTER, artifactExpander); + addExpandedArtifacts(artifacts, output, Artifact::getExecPath, artifactExpander); } /** @@ -906,15 +860,14 @@ public class Artifact * Converts artifacts into their exec paths. Returns an immutable list. */ public static List<PathFragment> asPathFragments(Iterable<? extends Artifact> artifacts) { - return ImmutableList.copyOf(Iterables.transform(artifacts, EXEC_PATH_FORMATTER)); + return Streams.stream(artifacts).map(Artifact::getExecPath).collect(toImmutableList()); } /** * Returns the exec paths of the input artifacts in alphabetical order. */ public static ImmutableList<PathFragment> asSortedPathFragments(Iterable<Artifact> input) { - return Ordering.natural().immutableSortedCopy(Iterables.transform( - input, EXEC_PATH_FORMATTER)); + return Streams.stream(input).map(Artifact::getExecPath).sorted().collect(toImmutableList()); } diff --git a/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java b/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java index 74e2eae16a..46ff4b0a82 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ExecutionRequirements.java @@ -116,29 +116,26 @@ public class ExecutionRequirements { ParseableRequirement.create( "cpu:<int>", Pattern.compile("cpu:(.+)"), - new Function<String, String>() { - @Override - public String apply(String s) { - Preconditions.checkNotNull(s); - - int value; - try { - value = Integer.parseInt(s); - } catch (NumberFormatException e) { - return "can't be parsed as an integer"; - } - - // De-and-reserialize & compare to only allow canonical integer formats. - if (!Integer.toString(value).equals(s)) { - return "must be in canonical format (e.g. '4' instead of '+04')"; - } - - if (value < 1) { - return "can't be zero or negative"; - } - - return null; + s -> { + Preconditions.checkNotNull(s); + + int value; + try { + value = Integer.parseInt(s); + } catch (NumberFormatException e) { + return "can't be parsed as an integer"; } + + // De-and-reserialize & compare to only allow canonical integer formats. + if (!Integer.toString(value).equals(s)) { + return "must be in canonical format (e.g. '4' instead of '+04')"; + } + + if (value < 1) { + return "can't be zero or negative"; + } + + return null; }); /** If an action supports running in persistent worker mode. */ |