From f2c79185f5742ebe6de92c42b6863ad8c0077acb Mon Sep 17 00:00:00 2001 From: Maxime Guerreiro Date: Thu, 26 Apr 2018 11:43:02 +0000 Subject: [PATCH] Use method reference when possible Change-Id: I9bf98b91fbd09c68588b23f116f694f58de0dedc --- .../AcceptanceTestRequestScope.java | 8 +------ .../httpd/plugins/HttpPluginServlet.java | 8 +------ .../httpd/plugins/LfsPluginServlet.java | 8 +------ .../gerrit/metrics/proc/JGitMetricModule.java | 15 ++---------- .../gerrit/metrics/proc/ProcMetricModule.java | 14 ++--------- .../server/git/receive/ReceiveCommits.java | 8 +------ .../server/restapi/config/ListTasks.java | 10 +------- java/com/google/gerrit/sshd/SshDaemon.java | 8 +------ .../gwtexpui/globalkey/client/GlobalKey.java | 9 ++------ .../gerrit/server/patch/PatchListTest.java | 23 ++----------------- 10 files changed, 14 insertions(+), 97 deletions(-) diff --git a/java/com/google/gerrit/acceptance/AcceptanceTestRequestScope.java b/java/com/google/gerrit/acceptance/AcceptanceTestRequestScope.java index d8dc6058fe..3acee779f0 100644 --- a/java/com/google/gerrit/acceptance/AcceptanceTestRequestScope.java +++ b/java/com/google/gerrit/acceptance/AcceptanceTestRequestScope.java @@ -166,13 +166,7 @@ public class AcceptanceTestRequestScope { public Context disableDb() { Context old = current.get(); - SchemaFactory sf = - new SchemaFactory() { - @Override - public ReviewDb open() { - return new DisabledReviewDb(); - } - }; + SchemaFactory sf = DisabledReviewDb::new; Context ctx = new Context(sf, old.session, old.user, old.created); current.set(ctx); diff --git a/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java b/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java index 969b9ff74e..b49081003d 100644 --- a/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java +++ b/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java @@ -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; diff --git a/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java b/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java index 7e013e6c21..e8f2e33887 100644 --- a/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java +++ b/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java @@ -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; diff --git a/java/com/google/gerrit/metrics/proc/JGitMetricModule.java b/java/com/google/gerrit/metrics/proc/JGitMetricModule.java index 4487ae5882..438f70e9c3 100644 --- a/java/com/google/gerrit/metrics/proc/JGitMetricModule.java +++ b/java/com/google/gerrit/metrics/proc/JGitMetricModule.java @@ -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() { - @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() { - @Override - public Integer get() { - return WindowCacheStats.getOpenFiles(); - } - }); + WindowCacheStats::getOpenFiles); } } diff --git a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java index 8978e99d69..5b9b2aec8c 100644 --- a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java +++ b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java @@ -60,12 +60,7 @@ public class ProcMetricModule extends MetricModule { "proc/uptime", Long.class, new Description("Uptime of this process").setUnit(Units.MILLISECONDS), - new Supplier() { - @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() { - @Override - public Long get() { - return provider.getOpenFileDescriptorCount(); - } - }); + provider::getOpenFileDescriptorCount); } } diff --git a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java index 17e804fb75..5f6581475e 100644 --- a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java +++ b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java @@ -2984,13 +2984,7 @@ class ReceiveCommits { id, mergedByPushOpFactory .create(requestScopePropagator, req.psId, refName) - .setPatchSetProvider( - new Provider() { - @Override - public PatchSet get() { - return req.replaceOp.getPatchSet(); - } - })); + .setPatchSetProvider(req.replaceOp::getPatchSet)); bu.addOp(id, new ChangeProgressOp(closeProgress)); } diff --git a/java/com/google/gerrit/server/restapi/config/ListTasks.java b/java/com/google/gerrit/server/restapi/config/ListTasks.java index fb2819c28d..d700028116 100644 --- a/java/com/google/gerrit/server/restapi/config/ListTasks.java +++ b/java/com/google/gerrit/server/restapi/config/ListTasks.java @@ -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 { } private List getTasks() { - List taskInfos = - workQueue.getTaskInfos( - new TaskInfoFactory() { - @Override - public TaskInfo getTaskInfo(Task task) { - return new TaskInfo(task); - } - }); + List taskInfos = workQueue.getTaskInfos(TaskInfo::new); Collections.sort( taskInfos, new Comparator() { diff --git a/java/com/google/gerrit/sshd/SshDaemon.java b/java/com/google/gerrit/sshd/SshDaemon.java index 8f50601a0e..e61919a113 100644 --- a/java/com/google/gerrit/sshd/SshDaemon.java +++ b/java/com/google/gerrit/sshd/SshDaemon.java @@ -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() { - @Override - public Integer get() { - return connected.get(); - } - }); + connected::get); final Counter0 sessionsCreated = metricMaker.newCounter( diff --git a/java/com/google/gwtexpui/globalkey/client/GlobalKey.java b/java/com/google/gwtexpui/globalkey/client/GlobalKey.java index 3eac7897a1..cbaca61658 100644 --- a/java/com/google/gwtexpui/globalkey/client/GlobalKey.java +++ b/java/com/google/gwtexpui/globalkey/client/GlobalKey.java @@ -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; diff --git a/javatests/com/google/gerrit/server/patch/PatchListTest.java b/javatests/com/google/gerrit/server/patch/PatchListTest.java index 0a7b97ccf9..6fbafb673d 100644 --- a/javatests/com/google/gerrit/server/patch/PatchListTest.java +++ b/javatests/com/google/gerrit/server/patch/PatchListTest.java @@ -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() { - @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() { - @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); }