Run automatic Java 8 conversion over codebase

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171174380
This commit is contained in:
mcilwain 2017-10-05 10:48:38 -07:00 committed by Ben McIlwain
parent 44df5da771
commit 5edb7935ed
190 changed files with 2312 additions and 3096 deletions

View file

@ -153,9 +153,7 @@ public class EventMetric extends AbstractMetric<Distribution> {
lock.lock();
try {
if (!values.containsKey(labelValues)) {
values.put(labelValues, new MutableDistribution(distributionFitter));
}
values.computeIfAbsent(labelValues, k -> new MutableDistribution(distributionFitter));
values.get(labelValues).add(sample, count);
valueStartTimestamps.putIfAbsent(labelValues, startTimestamp);

View file

@ -14,7 +14,6 @@
package google.registry.monitoring.metrics;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -57,27 +56,24 @@ final class MetricMetrics {
"Count of Timeseries being pushed to Monitoring API",
"Timeseries Count",
LABELS,
new Supplier<ImmutableMap<ImmutableList<String>, Long>>() {
@Override
public ImmutableMap<ImmutableList<String>, Long> get() {
HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>();
() -> {
HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>();
for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) {
ImmutableList<String> key =
ImmutableList.of(
metric.getMetricSchema().kind().toString(),
metric.getValueClass().toString());
for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) {
ImmutableList<String> key =
ImmutableList.of(
metric.getMetricSchema().kind().toString(),
metric.getValueClass().toString());
int cardinality = metric.getCardinality();
if (!timeseriesCount.containsKey(key)) {
timeseriesCount.put(key, (long) cardinality);
} else {
timeseriesCount.put(key, timeseriesCount.get(key) + cardinality);
}
int cardinality = metric.getCardinality();
if (!timeseriesCount.containsKey(key)) {
timeseriesCount.put(key, (long) cardinality);
} else {
timeseriesCount.put(key, timeseriesCount.get(key) + cardinality);
}
return ImmutableMap.copyOf(timeseriesCount);
}
return ImmutableMap.copyOf(timeseriesCount);
},
Long.class);

View file

@ -67,15 +67,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
* Function to convert a metric point to a nice string representation for use in error messages.
*/
protected final Function<MetricPoint<T>, String> metricPointConverter =
new Function<MetricPoint<T>, String>() {
@Override
public String apply(MetricPoint<T> metricPoint) {
return String.format(
metricPoint ->
String.format(
"%s => %s",
Joiner.on(':').join(metricPoint.labelValues()),
getMessageRepresentation(metricPoint.value()));
}
};
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
super(metadata, checkNotNull(actual));

View file

@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertAbout;
import com.google.common.collect.BoundType;
import com.google.common.collect.Range;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import google.registry.monitoring.metrics.Distribution;
import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint;
@ -48,15 +47,9 @@ public final class DistributionMetricSubject
extends AbstractMetricSubject<Distribution, DistributionMetricSubject> {
/** {@link Subject.Factory} for assertions about {@link Metric<Distribution>} objects. */
private static final Subject.Factory<DistributionMetricSubject, Metric<Distribution>>
SUBJECT_FACTORY =
// The Truth extensibility documentation indicates that the target should be nullable.
(FailureMetadata failureMetadata, @Nullable Metric<Distribution> target) ->
new DistributionMetricSubject(failureMetadata, target);
/** Static assertThat({@link Metric<Distribution>}) shortcut method. */
public static DistributionMetricSubject assertThat(@Nullable Metric<Distribution> metric) {
return assertAbout(SUBJECT_FACTORY).that(metric);
return assertAbout(DistributionMetricSubject::new).that(metric);
}
private DistributionMetricSubject(FailureMetadata metadata, Metric<Distribution> actual) {

View file

@ -17,7 +17,6 @@ package google.registry.monitoring.metrics.contrib;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint;
import javax.annotation.Nullable;
@ -45,14 +44,9 @@ import javax.annotation.Nullable;
public final class LongMetricSubject extends AbstractMetricSubject<Long, LongMetricSubject> {
/** {@link Subject.Factory} for assertions about {@link Metric<Long>} objects. */
private static final Subject.Factory<LongMetricSubject, Metric<Long>> SUBJECT_FACTORY =
// The Truth extensibility documentation indicates that the target should be nullable.
(FailureMetadata failureMetadata, @Nullable Metric<Long> target) ->
new LongMetricSubject(failureMetadata, target);
/** Static assertThat({@link Metric<Long>}) shortcut method. */
public static LongMetricSubject assertThat(@Nullable Metric<Long> metric) {
return assertAbout(SUBJECT_FACTORY).that(metric);
return assertAbout(LongMetricSubject::new).that(metric);
}
private LongMetricSubject(FailureMetadata metadata, Metric<Long> actual) {