Runnable: replace anonymous class with lambda

In Java 8 Runnable is functional interface and can be replaced with
lambda expressions or method references.

Change-Id: I2896b39c27b2e5a91a60149155a8c00a8eb48e39
This commit is contained in:
David Ostrovsky
2017-03-26 13:03:21 +02:00
committed by Shawn Pearce
parent 8f0528f3b5
commit 8785d73fa5
30 changed files with 493 additions and 799 deletions

View File

@@ -79,19 +79,16 @@ public abstract class MetricMaker {
* @param value only value of the metric.
* @param desc description of the metric.
*/
public <V> void newConstantMetric(String name, final V value, Description desc) {
public <V> void newConstantMetric(String name, V value, Description desc) {
desc.setConstant();
@SuppressWarnings("unchecked")
Class<V> type = (Class<V>) value.getClass();
final CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
newTrigger(
metric,
new Runnable() {
@Override
public void run() {
metric.set(value);
}
() -> {
metric.set(value);
});
}
@@ -116,15 +113,12 @@ public abstract class MetricMaker {
* @param trigger function to compute the value of the metric.
*/
public <V> void newCallbackMetric(
String name, Class<V> valueClass, Description desc, final Supplier<V> trigger) {
final CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
String name, Class<V> valueClass, Description desc, Supplier<V> trigger) {
CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
newTrigger(
metric,
new Runnable() {
@Override
public void run() {
metric.set(trigger.get());
}
() -> {
metric.set(trigger.get());
});
}