Convert some Functions/Predicates to streams & lambdas (5)
Change-Id: I4eca94928d77a15a81678dcd91b8d6174b4f6ec3
This commit is contained in:
@@ -20,7 +20,6 @@ import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.N
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -887,13 +886,7 @@ public abstract class AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private static Iterable<String> changeIds(Iterable<ChangeInfo> changes) {
|
||||
return Iterables.transform(changes,
|
||||
new Function<ChangeInfo, String>() {
|
||||
@Override
|
||||
public String apply(ChangeInfo input) {
|
||||
return input.changeId;
|
||||
}
|
||||
});
|
||||
return Iterables.transform(changes, i -> i.changeId);
|
||||
}
|
||||
|
||||
protected void assertSubmittedTogether(String chId, String... expected)
|
||||
|
||||
@@ -24,7 +24,6 @@ import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
@@ -585,17 +584,12 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
cd.setStars(stars);
|
||||
}
|
||||
|
||||
private void decodeReviewers(Multimap<String, IndexableField> doc, ChangeData cd) {
|
||||
private void decodeReviewers(Multimap<String, IndexableField> doc,
|
||||
ChangeData cd) {
|
||||
cd.setReviewers(
|
||||
ChangeField.parseReviewerFieldValues(
|
||||
FluentIterable.from(doc.get(REVIEWER_FIELD))
|
||||
.transform(
|
||||
new Function<IndexableField, String>() {
|
||||
@Override
|
||||
public String apply(IndexableField in) {
|
||||
return in.stringValue();
|
||||
}
|
||||
})));
|
||||
.transform(IndexableField::stringValue)));
|
||||
}
|
||||
|
||||
private static <T> List<T> decodeProtos(Multimap<String, IndexableField> doc,
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import static com.google.gerrit.common.data.PermissionRule.Action.ALLOW;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -365,8 +366,8 @@ public class ProjectState {
|
||||
* from the immediate parent of this project and progresses up the
|
||||
* hierarchy to All-Projects.
|
||||
*/
|
||||
public Iterable<ProjectState> parents() {
|
||||
return Iterables.skip(tree(), 1);
|
||||
public FluentIterable<ProjectState> parents() {
|
||||
return FluentIterable.from(tree()).skip(1);
|
||||
}
|
||||
|
||||
public boolean isAllProjects() {
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
@@ -200,15 +197,11 @@ final class AdminSetParent extends SshCommand {
|
||||
return childProjects;
|
||||
}
|
||||
|
||||
private Set<Project.NameKey> getAllParents(final Project.NameKey projectName) {
|
||||
private Set<Project.NameKey> getAllParents(Project.NameKey projectName) {
|
||||
ProjectState ps = projectCache.get(projectName);
|
||||
return ImmutableSet.copyOf(Iterables.transform(
|
||||
ps != null ? ps.parents() : Collections.<ProjectState> emptySet(),
|
||||
new Function<ProjectState, Project.NameKey> () {
|
||||
@Override
|
||||
public Project.NameKey apply(ProjectState in) {
|
||||
return in.getProject().getNameKey();
|
||||
if (ps == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}));
|
||||
return ps.parents().transform(s -> s.getProject().getNameKey()).toSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -56,14 +55,8 @@ public class BanCommitCommand extends SshCommand {
|
||||
@Override
|
||||
protected void run() throws Failure {
|
||||
try {
|
||||
BanCommit.Input input =
|
||||
BanCommit.Input.fromCommits(Lists.transform(commitsToBan,
|
||||
new Function<ObjectId, String>() {
|
||||
@Override
|
||||
public String apply(ObjectId oid) {
|
||||
return oid.getName();
|
||||
}
|
||||
}));
|
||||
BanCommit.Input input = BanCommit.Input.fromCommits(
|
||||
Lists.transform(commitsToBan, ObjectId::getName));
|
||||
input.reason = reason;
|
||||
|
||||
BanResultInfo r = banCommit.apply(new ProjectResource(projectControl), input);
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
@@ -74,12 +73,7 @@ final class CreateAccountCommand extends SshCommand {
|
||||
input.name = fullName;
|
||||
input.sshKey = readSshKey();
|
||||
input.httpPassword = httpPassword;
|
||||
input.groups = Lists.transform(groups, new Function<AccountGroup.Id, String>() {
|
||||
@Override
|
||||
public String apply(AccountGroup.Id id) {
|
||||
return id.toString();
|
||||
}
|
||||
});
|
||||
input.groups = Lists.transform(groups, AccountGroup.Id::toString);
|
||||
try {
|
||||
createAccountFactory.create(username).apply(TopLevelResource.INSTANCE, input);
|
||||
} catch (RestApiException e) {
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.groups.GroupInput;
|
||||
@@ -123,30 +123,15 @@ final class CreateGroupCommand extends SshCommand {
|
||||
|
||||
private void addMembers(GroupResource rsrc) throws RestApiException,
|
||||
OrmException, IOException {
|
||||
AddMembers.Input input =
|
||||
AddMembers.Input.fromMembers(FluentIterable
|
||||
.from(initialMembers)
|
||||
.transform(new Function<Account.Id, String>() {
|
||||
@Override
|
||||
public String apply(Account.Id id) {
|
||||
return String.valueOf(id.get());
|
||||
}
|
||||
})
|
||||
.toList());
|
||||
AddMembers.Input input = AddMembers.Input.fromMembers(
|
||||
initialMembers.stream().map(Object::toString).collect(toList()));
|
||||
addMembers.apply(rsrc, input);
|
||||
}
|
||||
|
||||
private void addIncludedGroups(GroupResource rsrc) throws RestApiException,
|
||||
OrmException {
|
||||
AddIncludedGroups.Input input =
|
||||
AddIncludedGroups.Input.fromGroups(FluentIterable.from(initialGroups)
|
||||
.transform(new Function<AccountGroup.UUID, String>() {
|
||||
@Override
|
||||
public String apply(AccountGroup.UUID id) {
|
||||
return id.get();
|
||||
}
|
||||
}).toList());
|
||||
|
||||
AddIncludedGroups.Input input = AddIncludedGroups.Input.fromGroups(
|
||||
initialGroups.stream().map(AccountGroup.UUID::get).collect(toList()));
|
||||
addIncludedGroups.apply(rsrc, input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
@@ -140,13 +139,7 @@ final class CreateProjectCommand extends SshCommand {
|
||||
ProjectInput input = new ProjectInput();
|
||||
input.name = projectName;
|
||||
if (ownerIds != null) {
|
||||
input.owners = Lists.transform(ownerIds,
|
||||
new Function<AccountGroup.UUID, String>() {
|
||||
@Override
|
||||
public String apply(AccountGroup.UUID uuid) {
|
||||
return uuid.get();
|
||||
}
|
||||
});
|
||||
input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
|
||||
}
|
||||
if (newParent != null) {
|
||||
input.parent = newParent.getProject().getName();
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -110,55 +109,37 @@ public class SetMembersCommand extends SshCommand {
|
||||
private void reportMembersAction(String action, GroupResource group,
|
||||
List<Account.Id> accountIdList) throws UnsupportedEncodingException,
|
||||
IOException {
|
||||
out.write(String.format(
|
||||
"Members %s group %s: %s\n",
|
||||
action,
|
||||
group.getName(),
|
||||
Joiner.on(", ").join(
|
||||
Iterables.transform(accountIdList,
|
||||
new Function<Account.Id, String>() {
|
||||
@Override
|
||||
public String apply(Account.Id accountId) {
|
||||
return MoreObjects.firstNonNull(accountCache.get(accountId)
|
||||
.getAccount().getPreferredEmail(), "n/a");
|
||||
}
|
||||
}))).getBytes(ENC));
|
||||
String names = accountIdList.stream()
|
||||
.map(accountId ->
|
||||
MoreObjects.firstNonNull(
|
||||
accountCache.get(accountId).getAccount().getPreferredEmail(),
|
||||
"n/a"))
|
||||
.collect(joining(", "));
|
||||
out.write(
|
||||
String.format(
|
||||
"Members %s group %s: %s\n", action, group.getName(), names)
|
||||
.getBytes(ENC));
|
||||
}
|
||||
|
||||
private void reportGroupsAction(String action, GroupResource group,
|
||||
List<AccountGroup.UUID> groupUuidList)
|
||||
throws UnsupportedEncodingException, IOException {
|
||||
out.write(String.format(
|
||||
"Groups %s group %s: %s\n",
|
||||
action,
|
||||
group.getName(),
|
||||
Joiner.on(", ").join(
|
||||
Iterables.transform(groupUuidList,
|
||||
new Function<AccountGroup.UUID, String>() {
|
||||
@Override
|
||||
public String apply(AccountGroup.UUID uuid) {
|
||||
return groupCache.get(uuid).getName();
|
||||
}
|
||||
}))).getBytes(ENC));
|
||||
String names = groupUuidList.stream()
|
||||
.map(uuid -> groupCache.get(uuid).getName())
|
||||
.collect(joining(", "));
|
||||
out.write(
|
||||
String.format(
|
||||
"Groups %s group %s: %s\n", action, group.getName(), names)
|
||||
.getBytes(ENC));
|
||||
}
|
||||
|
||||
private AddIncludedGroups.Input fromGroups(List<AccountGroup.UUID> accounts) {
|
||||
return AddIncludedGroups.Input.fromGroups(Lists.newArrayList(Iterables
|
||||
.transform(accounts, new Function<AccountGroup.UUID, String>() {
|
||||
@Override
|
||||
public String apply(AccountGroup.UUID uuid) {
|
||||
return uuid.toString();
|
||||
}
|
||||
})));
|
||||
return AddIncludedGroups.Input.fromGroups(
|
||||
accounts.stream().map(Object::toString).collect(toList()));
|
||||
}
|
||||
|
||||
private AddMembers.Input fromMembers(List<Account.Id> accounts) {
|
||||
return AddMembers.Input.fromMembers(Lists.newArrayList(Iterables.transform(
|
||||
accounts, new Function<Account.Id, String>() {
|
||||
@Override
|
||||
public String apply(Account.Id id) {
|
||||
return id.toString();
|
||||
}
|
||||
})));
|
||||
return AddMembers.Input.fromMembers(
|
||||
accounts.stream().map(Object::toString).collect(toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
@@ -143,18 +142,12 @@ public class FakeHttpServletRequest implements HttpServletRequest {
|
||||
return Iterables.getFirst(parameters.get(name), null);
|
||||
}
|
||||
|
||||
private static final Function<Collection<String>, String[]> STRING_COLLECTION_TO_ARRAY =
|
||||
new Function<Collection<String>, String[]>() {
|
||||
@Override
|
||||
public String[] apply(Collection<String> values) {
|
||||
return values.toArray(new String[0]);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
return Collections.unmodifiableMap(
|
||||
Maps.transformValues(parameters.asMap(), STRING_COLLECTION_TO_ARRAY));
|
||||
Maps.transformValues(
|
||||
parameters.asMap(),
|
||||
vs -> vs.toArray(new String[0])));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +157,7 @@ public class FakeHttpServletRequest implements HttpServletRequest {
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
return STRING_COLLECTION_TO_ARRAY.apply(parameters.get(name));
|
||||
return parameters.get(name).toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void setQueryString(String qs) {
|
||||
|
||||
Reference in New Issue
Block a user