Convert some Functions/Predicates to streams & lambdas (5)
Change-Id: I4eca94928d77a15a81678dcd91b8d6174b4f6ec3
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user