Merge "Use method reference when possible"

This commit is contained in:
Maxime Guerreiro 2018-04-27 11:28:06 +00:00 committed by Gerrit Code Review
commit 54f8947d77
10 changed files with 14 additions and 97 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2984,13 +2984,7 @@ class ReceiveCommits {
id, id,
mergedByPushOpFactory mergedByPushOpFactory
.create(requestScopePropagator, req.psId, refName) .create(requestScopePropagator, req.psId, refName)
.setPatchSetProvider( .setPatchSetProvider(req.replaceOp::getPatchSet));
new Provider<PatchSet>() {
@Override
public PatchSet get() {
return req.replaceOp.getPatchSet();
}
}));
bu.addOp(id, new ChangeProgressOp(closeProgress)); 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.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.ConfigResource; 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;
import com.google.gerrit.server.git.WorkQueue.ProjectTask; import com.google.gerrit.server.git.WorkQueue.ProjectTask;
import com.google.gerrit.server.git.WorkQueue.Task; import com.google.gerrit.server.git.WorkQueue.Task;
@ -107,14 +106,7 @@ public class ListTasks implements RestReadView<ConfigResource> {
} }
private List<TaskInfo> getTasks() { private List<TaskInfo> getTasks() {
List<TaskInfo> taskInfos = List<TaskInfo> taskInfos = workQueue.getTaskInfos(TaskInfo::new);
workQueue.getTaskInfos(
new TaskInfoFactory<TaskInfo>() {
@Override
public TaskInfo getTaskInfo(Task<?> task) {
return new TaskInfo(task);
}
});
Collections.sort( Collections.sort(
taskInfos, taskInfos,
new Comparator<TaskInfo>() { 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 static org.apache.sshd.common.channel.ChannelOutputStream.WAIT_FOR_SPACE_TIMEOUT;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.gerrit.common.Version; import com.google.gerrit.common.Version;
import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.extensions.events.LifecycleListener;
@ -242,12 +241,7 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
"sshd/sessions/connected", "sshd/sessions/connected",
Integer.class, Integer.class,
new Description("Currently connected SSH sessions").setGauge().setUnit("sessions"), new Description("Currently connected SSH sessions").setGauge().setUnit("sessions"),
new Supplier<Integer>() { connected::get);
@Override
public Integer get() {
return connected.get();
}
});
final Counter0 sessionsCreated = final Counter0 sessionsCreated =
metricMaker.newCounter( metricMaker.newCounter(

View File

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

View File

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