Use method reference when possible

Change-Id: I9bf98b91fbd09c68588b23f116f694f58de0dedc
This commit is contained in:
Maxime Guerreiro 2018-04-26 11:43:02 +00:00
parent a8bae8376d
commit f2c79185f5
10 changed files with 14 additions and 97 deletions

View File

@ -166,13 +166,7 @@ public class AcceptanceTestRequestScope {
public Context disableDb() {
Context old = current.get();
SchemaFactory<ReviewDb> sf =
new SchemaFactory<ReviewDb>() {
@Override
public ReviewDb open() {
return new DisabledReviewDb();
}
};
SchemaFactory<ReviewDb> sf = DisabledReviewDb::new;
Context ctx = new Context(sf, old.session, old.user, old.created);
current.set(ctx);

View File

@ -202,13 +202,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
return null;
}
plugin.add(
new RegistrationHandle() {
@Override
public void remove() {
filter.destroy();
}
});
plugin.add(filter::destroy);
return filter;
}
return null;

View File

@ -151,13 +151,7 @@ public class LfsPluginServlet extends HttpServlet
return null;
}
plugin.add(
new RegistrationHandle() {
@Override
public void remove() {
guiceFilter.destroy();
}
});
plugin.add(guiceFilter::destroy);
return guiceFilter;
}
return null;

View File

@ -14,7 +14,6 @@
package com.google.gerrit.metrics.proc;
import com.google.common.base.Supplier;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.Description.Units;
import com.google.gerrit.metrics.MetricMaker;
@ -29,22 +28,12 @@ public class JGitMetricModule extends MetricModule {
new Description("Bytes of memory retained in JGit block cache.")
.setGauge()
.setUnit(Units.BYTES),
new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStats.getOpenBytes();
}
});
WindowCacheStats::getOpenBytes);
metrics.newCallbackMetric(
"jgit/block_cache/open_files",
Integer.class,
new Description("File handles held open by JGit block cache.").setGauge().setUnit("fds"),
new Supplier<Integer>() {
@Override
public Integer get() {
return WindowCacheStats.getOpenFiles();
}
});
WindowCacheStats::getOpenFiles);
}
}

View File

@ -60,12 +60,7 @@ public class ProcMetricModule extends MetricModule {
"proc/uptime",
Long.class,
new Description("Uptime of this process").setUnit(Units.MILLISECONDS),
new Supplier<Long>() {
@Override
public Long get() {
return ManagementFactory.getRuntimeMXBean().getUptime();
}
});
ManagementFactory.getRuntimeMXBean()::getUptime);
}
private void procCpuUsage(MetricMaker metrics) {
@ -93,12 +88,7 @@ public class ProcMetricModule extends MetricModule {
"proc/num_open_fds",
Long.class,
new Description("Number of open file descriptors").setGauge().setUnit("fds"),
new Supplier<Long>() {
@Override
public Long get() {
return provider.getOpenFileDescriptorCount();
}
});
provider::getOpenFileDescriptorCount);
}
}

View File

@ -2984,13 +2984,7 @@ class ReceiveCommits {
id,
mergedByPushOpFactory
.create(requestScopePropagator, req.psId, refName)
.setPatchSetProvider(
new Provider<PatchSet>() {
@Override
public PatchSet get() {
return req.replaceOp.getPatchSet();
}
}));
.setPatchSetProvider(req.replaceOp::getPatchSet));
bu.addOp(id, new ChangeProgressOp(closeProgress));
}

View File

@ -20,7 +20,6 @@ import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.ConfigResource;
import com.google.gerrit.server.git.TaskInfoFactory;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.git.WorkQueue.ProjectTask;
import com.google.gerrit.server.git.WorkQueue.Task;
@ -107,14 +106,7 @@ public class ListTasks implements RestReadView<ConfigResource> {
}
private List<TaskInfo> getTasks() {
List<TaskInfo> taskInfos =
workQueue.getTaskInfos(
new TaskInfoFactory<TaskInfo>() {
@Override
public TaskInfo getTaskInfo(Task<?> task) {
return new TaskInfo(task);
}
});
List<TaskInfo> taskInfos = workQueue.getTaskInfos(TaskInfo::new);
Collections.sort(
taskInfos,
new Comparator<TaskInfo>() {

View File

@ -20,7 +20,6 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.sshd.common.channel.ChannelOutputStream.WAIT_FOR_SPACE_TIMEOUT;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.gerrit.common.Version;
import com.google.gerrit.extensions.events.LifecycleListener;
@ -242,12 +241,7 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
"sshd/sessions/connected",
Integer.class,
new Description("Currently connected SSH sessions").setGauge().setUnit("sessions"),
new Supplier<Integer>() {
@Override
public Integer get() {
return connected.get();
}
});
connected::get);
final Counter0 sessionsCreated =
metricMaker.newCounter(

View File

@ -14,6 +14,7 @@
package com.google.gwtexpui.globalkey.client;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
@ -27,13 +28,7 @@ import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
public class GlobalKey {
public static final KeyPressHandler STOP_PROPAGATION =
new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
event.stopPropagation();
}
};
public static final KeyPressHandler STOP_PROPAGATION = DomEvent::stopPropagation;
private static State global;
static State active;

View File

@ -23,7 +23,6 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.Comparator;
import org.junit.Test;
public class PatchListTest {
@ -36,16 +35,7 @@ public class PatchListTest {
Patch.COMMIT_MSG, Patch.MERGE_LIST, "/!xxx", "abc", "def/g", "qrx", "zzz",
};
Arrays.sort(
names,
0,
names.length,
new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return PatchList.comparePaths(o1, o2);
}
});
Arrays.sort(names, 0, names.length, PatchList::comparePaths);
assertThat(names).isEqualTo(want);
}
@ -58,16 +48,7 @@ public class PatchListTest {
Patch.COMMIT_MSG, "/!xxx", "abc", "def/g", "qrx", "zzz",
};
Arrays.sort(
names,
0,
names.length,
new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return PatchList.comparePaths(o1, o2);
}
});
Arrays.sort(names, 0, names.length, PatchList::comparePaths);
assertThat(names).isEqualTo(want);
}