Consistently import utility methods from Collectors as static

Change-Id: I3e52bfb198cb4f0ddc5f683bcc48029fc408f772
This commit is contained in:
David Pursehouse 2017-12-15 17:24:41 +09:00
parent 96bf6870d2
commit 55e74a8c90
13 changed files with 36 additions and 37 deletions

View File

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertAbout;
import static com.google.gerrit.extensions.api.changes.RecipientType.BCC;
import static com.google.gerrit.extensions.api.changes.RecipientType.CC;
import static com.google.gerrit.extensions.api.changes.RecipientType.TO;
import static java.util.stream.Collectors.toList;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@ -48,7 +49,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.eclipse.jgit.junit.TestRepository;
import org.junit.After;
import org.junit.Before;
@ -124,7 +124,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
.stream()
.map(Address::getEmail)
.filter(e -> !recipients.get(TO).contains(e) && !recipients.get(CC).contains(e))
.collect(Collectors.toList()));
.collect(toList()));
this.users = users;
if (!message.headers().containsKey("X-Gerrit-MessageType")) {
fail("a message was sent with X-Gerrit-MessageType header");
@ -165,7 +165,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
}
Truth.assertThat(header).isInstanceOf(AddressList.class);
AddressList addrList = (AddressList) header;
return addrList.getAddressList().stream().map(Address::getEmail).collect(Collectors.toList());
return addrList.getAddressList().stream().map(Address::getEmail).collect(toList());
}
public FakeEmailSenderSubject to(String... emails) {

View File

@ -49,6 +49,7 @@ import static com.google.gerrit.server.project.Util.category;
import static com.google.gerrit.server.project.Util.value;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.junit.Assert.fail;
@ -153,7 +154,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
@ -460,7 +460,7 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(result.reviewers).isNotEmpty();
ChangeInfo info = gApi.changes().id(changeId).get();
Function<Collection<AccountInfo>, Collection<String>> toEmails =
ais -> ais.stream().map(ai -> ai.email).collect(Collectors.toSet());
ais -> ais.stream().map(ai -> ai.email).collect(toSet());
assertThat(toEmails.apply(info.pendingReviewers.get(REVIEWER)))
.containsExactly(
admin.email, user1.email, user2.email, "byemail1@example.com", "byemail2@example.com");
@ -3182,7 +3182,7 @@ public class ChangeIT extends AbstractDaemonTest {
@Test
public void putTopicExceedLimitFails() throws Exception {
String changeId = createChange().getChangeId();
String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
String topic = Stream.generate(() -> "t").limit(2049).collect(joining());
exception.expect(BadRequestException.class);
exception.expectMessage("topic length exceeds the limit");

View File

@ -19,6 +19,8 @@ import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.common.DiffInfoSubject.assertThat;
import static com.google.gerrit.extensions.common.FileInfoSubject.assertThat;
import static com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
@ -44,7 +46,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.imageio.ImageIO;
import org.eclipse.jgit.lib.Config;
@ -64,7 +65,7 @@ public class RevisionDiffIT extends AbstractDaemonTest {
private static final String FILE_CONTENT =
IntStream.rangeClosed(1, 100)
.mapToObj(number -> String.format("Line %d\n", number))
.collect(Collectors.joining());
.collect(joining());
private static final String FILE_CONTENT2 = "1st line\n2nd line\n3rd line\n";
private boolean intraline;
@ -1286,7 +1287,7 @@ public class RevisionDiffIT extends AbstractDaemonTest {
testRepo.reset(parentCommit);
Map<String, String> files =
Arrays.stream(removedFilePaths)
.collect(Collectors.toMap(Function.identity(), path -> "Irrelevant content"));
.collect(toMap(Function.identity(), path -> "Irrelevant content"));
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), testRepo, "Remove files from repo", files);
PushOneCommit.Result result = push.rm("refs/for/master");

View File

@ -90,7 +90,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.junit.TestRepository;
@ -350,14 +349,14 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
@Test
public void pushForMasterWithTopicInRefExceedLimitFails() throws Exception {
String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
String topic = Stream.generate(() -> "t").limit(2049).collect(joining());
PushOneCommit.Result r = pushTo("refs/for/master/" + topic);
r.assertErrorStatus("topic length exceeds the limit (2048)");
}
@Test
public void pushForMasterWithTopicAsOptionExceedLimitFails() throws Exception {
String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
String topic = Stream.generate(() -> "t").limit(2049).collect(joining());
PushOneCommit.Result r = pushTo("refs/for/master%topic=" + topic);
r.assertErrorStatus("topic length exceeds the limit (2048)");
}

View File

@ -18,6 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import static com.google.gerrit.acceptance.PushOneCommit.SUBJECT;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
@ -68,7 +70,6 @@ import java.util.Optional;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@ -962,7 +963,7 @@ public class CommentsIT extends AbstractDaemonTest {
.values()
.stream()
.flatMap(List::stream)
.collect(Collectors.toList());
.collect(toList());
}
private CommentInput addComment(String changeId, String message) throws Exception {
@ -976,7 +977,7 @@ public class CommentsIT extends AbstractDaemonTest {
private void addComments(String changeId, String revision, CommentInput... commentInputs)
throws Exception {
ReviewInput input = new ReviewInput();
input.comments = Arrays.stream(commentInputs).collect(Collectors.groupingBy(c -> c.path));
input.comments = Arrays.stream(commentInputs).collect(groupingBy(c -> c.path));
gApi.changes().id(changeId).revision(revision).review(input);
}

View File

@ -14,6 +14,8 @@
package com.google.gerrit.client.api;
import static java.util.stream.Collectors.toList;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.VoidResult;
@ -28,7 +30,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwtexpui.progress.client.ProgressBar;
import java.util.List;
import java.util.stream.Collectors;
/** Loads JavaScript plugins with a progress meter visible. */
public class PluginLoader extends DialogBox {
@ -39,7 +40,7 @@ public class PluginLoader extends DialogBox {
if (plugins == null || plugins.isEmpty()) {
callback.onSuccess(VoidResult.create());
} else {
plugins = plugins.stream().filter(p -> p.endsWith(".js")).collect(Collectors.toList());
plugins = plugins.stream().filter(p -> p.endsWith(".js")).collect(toList());
if (plugins.isEmpty()) {
callback.onSuccess(VoidResult.create());
} else {

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.fixes;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.stream.Collectors.groupingBy;
import com.google.gerrit.common.RawInputUtil;
import com.google.gerrit.extensions.restapi.BinaryResult;
@ -33,7 +34,6 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@ -73,9 +73,7 @@ public class FixReplacementInterpreter {
checkNotNull(fixReplacements, "Fix replacements must not be null");
Map<String, List<FixReplacement>> fixReplacementsPerFilePath =
fixReplacements
.stream()
.collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
fixReplacements.stream().collect(groupingBy(fixReplacement -> fixReplacement.path));
List<TreeModification> treeModifications = new ArrayList<>();
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server.git.strategy;
import static java.util.stream.Collectors.toSet;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.gerrit.extensions.client.SubmitType;
@ -31,7 +33,6 @@ import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@ -68,7 +69,7 @@ public class SubmitDryRun {
repo.getRefDatabase().getRefs(Constants.R_TAGS).values().stream())
.map(Ref::getObjectId)
.filter(o -> o != null)
.collect(Collectors.toSet());
.collect(toSet());
}
public static Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw) throws IOException {

View File

@ -17,6 +17,7 @@ package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gerrit.reviewdb.client.PatchLineComment.Status.PUBLISHED;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.annotations.VisibleForTesting;
@ -31,7 +32,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.ObjectId;
@ -139,7 +139,7 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
.values()
.stream()
.flatMap(n -> n.getComments().stream())
.collect(Collectors.toMap(c -> c.key.uuid, c -> c));
.collect(toMap(c -> c.key.uuid, c -> c));
}
/**

View File

@ -18,6 +18,7 @@ import static com.google.gerrit.server.ioutil.BasicSerialization.readEnum;
import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeEnum;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.reviewdb.client.CodedEnum;
@ -30,7 +31,6 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.ReplaceEdit;
@ -109,7 +109,7 @@ public class IntraLineDiff implements Serializable {
for (int j = 0; j < innerCount; j++) {
inner[j] = readEdit(in);
}
editArray[i] = new ReplaceEdit(editArray[i], toList(inner));
editArray[i] = new ReplaceEdit(editArray[i], asList(inner));
}
}
edits = ImmutableList.copyOf(editArray);
@ -128,7 +128,7 @@ public class IntraLineDiff implements Serializable {
private static ReplaceEdit copy(ReplaceEdit edit) {
List<Edit> internalEdits =
edit.getInternalEdits().stream().map(IntraLineDiff::copy).collect(Collectors.toList());
edit.getInternalEdits().stream().map(IntraLineDiff::copy).collect(toList());
return new ReplaceEdit(
edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB(), internalEdits);
}
@ -148,7 +148,7 @@ public class IntraLineDiff implements Serializable {
return new Edit(beginA, endA, beginB, endB);
}
private static List<Edit> toList(Edit[] l) {
private static List<Edit> asList(Edit[] l) {
return Collections.unmodifiableList(Arrays.asList(l));
}
}

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.plugins;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toMap;
import com.google.common.collect.Streams;
import com.google.gerrit.common.data.GlobalCapability;
@ -30,7 +31,6 @@ import java.util.Locale;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.kohsuke.args4j.Option;
@ -137,7 +137,7 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
if (limit > 0) {
s = s.limit(limit);
}
return new TreeMap<>(s.collect(Collectors.toMap(p -> p.getName(), p -> toPluginInfo(p))));
return new TreeMap<>(s.collect(toMap(p -> p.getName(), p -> toPluginInfo(p))));
}
private void checkMatchOptions(boolean cond) throws BadRequestException {

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server.project;
import static java.util.stream.Collectors.toMap;
import com.google.common.base.Strings;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelValue;
@ -28,7 +30,6 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@Singleton
public class ProjectJson {
@ -48,9 +49,7 @@ public class ProjectJson {
for (LabelType t : projectState.getLabelTypes().getLabelTypes()) {
LabelTypeInfo labelInfo = new LabelTypeInfo();
labelInfo.values =
t.getValues()
.stream()
.collect(Collectors.toMap(LabelValue::formatValue, LabelValue::getText));
t.getValues().stream().collect(toMap(LabelValue::formatValue, LabelValue::getText));
labelInfo.defaultValue = t.getDefaultValue();
info.labels.put(t.getName(), labelInfo);
}

View File

@ -90,7 +90,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Config;
@ -1250,7 +1249,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
}
List<Predicate<ChangeData>> predicates =
parts.stream().map(fullPredicateFunc).collect(Collectors.toList());
parts.stream().map(fullPredicateFunc).collect(toList());
return Predicate.and(predicates);
}