Merge changes from topic 'lambdas-3'
* changes: Convert some Functions/Predicates to streams & lambdas (5) Convert some Functions/Predicates to streams & lambdas (4)
This commit is contained in:
commit
29cf834d7e
@ -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)
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
@ -29,13 +28,7 @@ import java.util.Arrays;
|
||||
public class TestAccount {
|
||||
public static FluentIterable<Account.Id> ids(
|
||||
Iterable<TestAccount> accounts) {
|
||||
return FluentIterable.from(accounts)
|
||||
.transform(new Function<TestAccount, Account.Id>() {
|
||||
@Override
|
||||
public Account.Id apply(TestAccount in) {
|
||||
return in.id;
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(accounts).transform(a -> a.id);
|
||||
}
|
||||
|
||||
public static FluentIterable<Account.Id> ids(TestAccount... accounts) {
|
||||
@ -43,13 +36,7 @@ public class TestAccount {
|
||||
}
|
||||
|
||||
public static FluentIterable<String> names(Iterable<TestAccount> accounts) {
|
||||
return FluentIterable.from(accounts)
|
||||
.transform(new Function<TestAccount, String>() {
|
||||
@Override
|
||||
public String apply(TestAccount in) {
|
||||
return in.fullName;
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(accounts).transform(a -> a.fullName);
|
||||
}
|
||||
|
||||
public static FluentIterable<String> names(TestAccount... accounts) {
|
||||
|
@ -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,
|
||||
|
@ -14,9 +14,8 @@
|
||||
|
||||
package com.google.gerrit.pgm;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.IoUtil;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.PluginData;
|
||||
@ -42,6 +41,7 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/** Initialize a new Gerrit installation. */
|
||||
public class Init extends BaseInit {
|
||||
@ -237,16 +237,10 @@ public class Init extends BaseInit {
|
||||
if (nullOrEmpty(installPlugins) || nullOrEmpty(plugins)) {
|
||||
return;
|
||||
}
|
||||
ArrayList<String> copy = Lists.newArrayList(installPlugins);
|
||||
List<String> pluginNames = Lists.transform(plugins, new Function<PluginData, String>() {
|
||||
@Override
|
||||
public String apply(PluginData input) {
|
||||
return input.name;
|
||||
}
|
||||
});
|
||||
copy.removeAll(pluginNames);
|
||||
if (!copy.isEmpty()) {
|
||||
ui.message("Cannot find plugin(s): %s\n", Joiner.on(", ").join(copy));
|
||||
Set<String> missing = Sets.newHashSet(installPlugins);
|
||||
plugins.stream().forEach(p -> missing.remove(p.name));
|
||||
if (!missing.isEmpty()) {
|
||||
ui.message("Cannot find plugin(s): %s\n", Joiner.on(", ").join(missing));
|
||||
listPlugins = true;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package com.google.gerrit.pgm;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.unwrapDb;
|
||||
import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_USER;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@ -234,13 +233,8 @@ public class RebuildNoteDb extends SiteProgram {
|
||||
ArrayListMultimap.create();
|
||||
try (ReviewDb db = schemaFactory.open()) {
|
||||
if (projects.isEmpty() && !changes.isEmpty()) {
|
||||
Iterable<Change> todo = unwrapDb(db).changes().get(
|
||||
Iterables.transform(changes, new Function<Integer, Change.Id>() {
|
||||
@Override
|
||||
public Change.Id apply(Integer in) {
|
||||
return new Change.Id(in);
|
||||
}
|
||||
}));
|
||||
Iterable<Change> todo = unwrapDb(db).changes()
|
||||
.get(Iterables.transform(changes, Change.Id::new));
|
||||
for (Change c : todo) {
|
||||
changesByProject.put(c.getProject(), c.getId());
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ package com.google.gerrit.pgm;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_USER;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.Die;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
@ -134,14 +132,8 @@ public class Reindex extends SiteProgram {
|
||||
}
|
||||
|
||||
checkNotNull(indexDefs, "Called this method before injectMembers?");
|
||||
Set<String> valid = FluentIterable.from(indexDefs).transform(
|
||||
new Function<IndexDefinition<?, ?, ?>, String>() {
|
||||
@Override
|
||||
public String apply(IndexDefinition<?, ?, ?> input) {
|
||||
return input.getName();
|
||||
}
|
||||
}).toSortedSet(Ordering.natural());
|
||||
|
||||
Set<String> valid = indexDefs.stream()
|
||||
.map(IndexDefinition::getName).sorted().collect(toSet());
|
||||
Set<String> invalid = Sets.difference(Sets.newHashSet(indices), valid);
|
||||
if (invalid.isEmpty()) {
|
||||
return;
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import static java.util.Comparator.comparingInt;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -40,16 +41,8 @@ public class ChangeUtil {
|
||||
private static final String SUBJECT_CROP_APPENDIX = "...";
|
||||
private static final int SUBJECT_CROP_RANGE = 10;
|
||||
|
||||
public static final Function<PatchSet, Integer> TO_PS_ID =
|
||||
new Function<PatchSet, Integer>() {
|
||||
@Override
|
||||
public Integer apply(PatchSet in) {
|
||||
return in.getId().get();
|
||||
}
|
||||
};
|
||||
|
||||
public static final Ordering<PatchSet> PS_ID_ORDER = Ordering.natural()
|
||||
.onResultOf(TO_PS_ID);
|
||||
public static final Ordering<PatchSet> PS_ID_ORDER =
|
||||
Ordering.from(comparingInt(PatchSet::getPatchSetId));
|
||||
|
||||
/**
|
||||
* Generate a new unique identifier for change message entities.
|
||||
|
@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@ -24,16 +23,10 @@ public class OptionUtil {
|
||||
private static final Splitter COMMA_OR_SPACE =
|
||||
Splitter.on(CharMatcher.anyOf(", ")).omitEmptyStrings().trimResults();
|
||||
|
||||
private static final Function<String, String> TO_LOWER_CASE =
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
return input.toLowerCase();
|
||||
}
|
||||
};
|
||||
|
||||
public static Iterable<String> splitOptionValue(String value) {
|
||||
return Iterables.transform(COMMA_OR_SPACE.split(value), TO_LOWER_CASE);
|
||||
return Iterables.transform(
|
||||
COMMA_OR_SPACE.split(value),
|
||||
String::toLowerCase);
|
||||
}
|
||||
|
||||
private OptionUtil() {
|
||||
|
@ -14,14 +14,14 @@
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
@ -68,19 +68,17 @@ import java.util.Set;
|
||||
public class ReviewersUtil {
|
||||
private static final String MAX_SUFFIX = "\u9fa5";
|
||||
private static final Ordering<SuggestedReviewerInfo> ORDERING =
|
||||
Ordering.natural().onResultOf(new Function<SuggestedReviewerInfo, String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable SuggestedReviewerInfo suggestedReviewerInfo) {
|
||||
if (suggestedReviewerInfo == null) {
|
||||
return null;
|
||||
}
|
||||
return suggestedReviewerInfo.account != null
|
||||
? MoreObjects.firstNonNull(suggestedReviewerInfo.account.email,
|
||||
Strings.nullToEmpty(suggestedReviewerInfo.account.name))
|
||||
: Strings.nullToEmpty(suggestedReviewerInfo.group.name);
|
||||
}
|
||||
});
|
||||
Ordering.from(comparing(
|
||||
suggestedReviewerInfo -> {
|
||||
if (suggestedReviewerInfo == null) {
|
||||
return null;
|
||||
}
|
||||
return suggestedReviewerInfo.account != null
|
||||
? MoreObjects.firstNonNull(suggestedReviewerInfo.account.email,
|
||||
Strings.nullToEmpty(suggestedReviewerInfo.account.name))
|
||||
: Strings.nullToEmpty(suggestedReviewerInfo.group.name);
|
||||
}));
|
||||
|
||||
private final AccountLoader accountLoader;
|
||||
private final AccountCache accountCache;
|
||||
private final AccountIndexCollection indexes;
|
||||
|
@ -14,8 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.server.config.DownloadConfig;
|
||||
import com.google.inject.Inject;
|
||||
@ -28,7 +29,7 @@ import java.util.Set;
|
||||
@Singleton
|
||||
public class AllowedFormats {
|
||||
final ImmutableMap<String, ArchiveFormat> extensions;
|
||||
final Set<ArchiveFormat> allowed;
|
||||
final ImmutableSet<ArchiveFormat> allowed;
|
||||
|
||||
@Inject
|
||||
AllowedFormats(DownloadConfig cfg) {
|
||||
@ -43,14 +44,8 @@ public class AllowedFormats {
|
||||
|
||||
// Zip is not supported because it may be interpreted by a Java plugin as a
|
||||
// valid JAR file, whose code would have access to cookies on the domain.
|
||||
allowed = Sets.filter(
|
||||
cfg.getArchiveFormats(),
|
||||
new Predicate<ArchiveFormat>() {
|
||||
@Override
|
||||
public boolean apply(ArchiveFormat format) {
|
||||
return (format != ArchiveFormat.ZIP);
|
||||
}
|
||||
});
|
||||
allowed = Sets.immutableEnumSet(
|
||||
Iterables.filter(cfg.getArchiveFormats(), f -> f != ArchiveFormat.ZIP));
|
||||
}
|
||||
|
||||
public Set<ArchiveFormat> getAllowed() {
|
||||
@ -60,4 +55,4 @@ public class AllowedFormats {
|
||||
public ImmutableMap<String, ArchiveFormat> getExtensions() {
|
||||
return extensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.reviewdb.client.Change.INITIAL_PATCH_SET_ID;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
@ -377,21 +377,23 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
|
||||
private Set<Account.Id> filterOnChangeVisibility(final ReviewDb db,
|
||||
final ChangeNotes notes, Set<Account.Id> accounts) {
|
||||
return Sets.filter(accounts, new Predicate<Account.Id>() {
|
||||
@Override
|
||||
public boolean apply(Account.Id accountId) {
|
||||
try {
|
||||
IdentifiedUser user = userFactory.create(accountId);
|
||||
return changeControlFactory.controlFor(notes, user).isVisible(db);
|
||||
} catch (OrmException | NoSuchChangeException e) {
|
||||
log.warn(
|
||||
String.format("Failed to check if account %d can see change %d",
|
||||
accountId.get(), notes.getChangeId().get()),
|
||||
e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
return accounts.stream()
|
||||
.filter(
|
||||
accountId -> {
|
||||
try {
|
||||
IdentifiedUser user = userFactory.create(accountId);
|
||||
return changeControlFactory.controlFor(notes, user)
|
||||
.isVisible(db);
|
||||
} catch (OrmException | NoSuchChangeException e) {
|
||||
log.warn(
|
||||
String.format(
|
||||
"Failed to check if account %d can see change %d",
|
||||
accountId.get(), notes.getChangeId().get()),
|
||||
e);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,8 +35,9 @@ import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWER_UPD
|
||||
import static com.google.gerrit.extensions.client.ListChangesOption.WEB_LINKS;
|
||||
import static com.google.gerrit.server.CommonConverters.toGitPerson;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Optional;
|
||||
@ -298,13 +299,8 @@ public class ChangeJson {
|
||||
public List<List<ChangeInfo>> formatQueryResults(
|
||||
List<QueryResult<ChangeData>> in) throws OrmException {
|
||||
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
|
||||
ensureLoaded(FluentIterable.from(in).transformAndConcat(
|
||||
new Function<QueryResult<ChangeData>, List<ChangeData>>() {
|
||||
@Override
|
||||
public List<ChangeData> apply(QueryResult<ChangeData> in) {
|
||||
return in.entities();
|
||||
}
|
||||
}));
|
||||
ensureLoaded(
|
||||
FluentIterable.from(in).transformAndConcat(QueryResult::entities));
|
||||
|
||||
List<List<ChangeInfo>> res = Lists.newArrayListWithCapacity(in.size());
|
||||
Map<Change.Id, ChangeInfo> out = new HashMap<>();
|
||||
@ -599,7 +595,7 @@ public class ChangeJson {
|
||||
? labelsForOpenChange(ctl, cd, labelTypes, standard, detailed)
|
||||
: labelsForClosedChange(cd, labelTypes, standard, detailed);
|
||||
return ImmutableMap.copyOf(
|
||||
Maps.transformValues(withStatus, LabelWithStatus.TO_LABEL_INFO));
|
||||
Maps.transformValues(withStatus, LabelWithStatus::label));
|
||||
}
|
||||
|
||||
private Map<String, LabelWithStatus> labelsForOpenChange(ChangeControl ctl,
|
||||
@ -952,14 +948,10 @@ public class ChangeJson {
|
||||
|
||||
private Collection<AccountInfo> toAccountInfo(
|
||||
Collection<Account.Id> accounts) {
|
||||
return FluentIterable.from(accounts)
|
||||
.transform(new Function<Account.Id, AccountInfo>() {
|
||||
@Override
|
||||
public AccountInfo apply(Account.Id id) {
|
||||
return accountLoader.get(id);
|
||||
}
|
||||
})
|
||||
.toSortedList(AccountInfoComparator.ORDER_NULLS_FIRST);
|
||||
return accounts.stream()
|
||||
.map(accountLoader::get)
|
||||
.sorted(AccountInfoComparator.ORDER_NULLS_FIRST)
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -1185,14 +1177,6 @@ public class ChangeJson {
|
||||
|
||||
@AutoValue
|
||||
abstract static class LabelWithStatus {
|
||||
private static final Function<LabelWithStatus, LabelInfo> TO_LABEL_INFO =
|
||||
new Function<LabelWithStatus, LabelInfo>() {
|
||||
@Override
|
||||
public LabelInfo apply(LabelWithStatus in) {
|
||||
return in.label();
|
||||
}
|
||||
};
|
||||
|
||||
private static LabelWithStatus create(LabelInfo label,
|
||||
SubmitRecord.Label.Status status) {
|
||||
return new AutoValue_ChangeJson_LabelWithStatus(label, status);
|
||||
|
@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.gerrit.server.PatchLineCommentsUtil.COMMENT_INFO_ORDER;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.extensions.client.Comment.Range;
|
||||
@ -100,17 +99,13 @@ class CommentJson {
|
||||
|
||||
List<CommentInfo> formatAsList(Iterable<PatchLineComment> l)
|
||||
throws OrmException {
|
||||
final AccountLoader accountLoader = fillAccounts
|
||||
AccountLoader accountLoader = fillAccounts
|
||||
? accountLoaderFactory.create(true)
|
||||
: null;
|
||||
List<CommentInfo> out = FluentIterable
|
||||
.from(l)
|
||||
.transform(new Function<PatchLineComment, CommentInfo>() {
|
||||
@Override
|
||||
public CommentInfo apply(PatchLineComment c) {
|
||||
return toCommentInfo(c, accountLoader);
|
||||
}
|
||||
}).toSortedList(COMMENT_INFO_ORDER);
|
||||
.transform(c -> toCommentInfo(c, accountLoader))
|
||||
.toSortedList(COMMENT_INFO_ORDER);
|
||||
|
||||
if (accountLoader != null) {
|
||||
accountLoader.fill();
|
||||
|
@ -19,13 +19,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.intKeyOrdering;
|
||||
import static com.google.gerrit.server.ChangeUtil.PS_ID_ORDER;
|
||||
import static com.google.gerrit.server.ChangeUtil.TO_PS_ID;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
@ -255,13 +252,10 @@ public class ConsistencyChecker {
|
||||
|
||||
Map<String, Ref> refs;
|
||||
try {
|
||||
refs = repo.getRefDatabase().exactRef(
|
||||
Lists.transform(all, new Function<PatchSet, String>() {
|
||||
@Override
|
||||
public String apply(PatchSet ps) {
|
||||
return ps.getId().toRefName();
|
||||
}
|
||||
}).toArray(new String[all.size()]));
|
||||
refs = repo.getRefDatabase().exactRef(
|
||||
all.stream()
|
||||
.map(ps -> ps.getId().toRefName())
|
||||
.toArray(String[]::new));
|
||||
} catch (IOException e) {
|
||||
error("error reading refs", e);
|
||||
refs = Collections.emptyMap();
|
||||
@ -319,7 +313,7 @@ public class ConsistencyChecker {
|
||||
if (e.getValue().size() > 1) {
|
||||
problem(String.format("Multiple patch sets pointing to %s: %s",
|
||||
e.getKey().name(),
|
||||
Collections2.transform(e.getValue(), TO_PS_ID)));
|
||||
Collections2.transform(e.getValue(), PatchSet::getPatchSetId)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
@ -210,7 +209,7 @@ public class DeleteReviewer
|
||||
}
|
||||
|
||||
private Iterable<PatchSetApproval> approvals(ChangeContext ctx,
|
||||
final Account.Id accountId) throws OrmException {
|
||||
Account.Id accountId) throws OrmException {
|
||||
Change.Id changeId = ctx.getNotes().getChangeId();
|
||||
Iterable<PatchSetApproval> approvals;
|
||||
|
||||
@ -229,14 +228,7 @@ public class DeleteReviewer
|
||||
approvalsUtil.byChange(ctx.getDb(), ctx.getNotes()).values();
|
||||
}
|
||||
|
||||
return Iterables.filter(
|
||||
approvals,
|
||||
new Predicate<PatchSetApproval>() {
|
||||
@Override
|
||||
public boolean apply(PatchSetApproval input) {
|
||||
return accountId.equals(input.getAccountId());
|
||||
}
|
||||
});
|
||||
return Iterables.filter(approvals, accountId::equals);
|
||||
}
|
||||
|
||||
private String formatLabelValue(short value) {
|
||||
|
@ -17,7 +17,6 @@ package com.google.gerrit.server.change;
|
||||
import static com.google.gerrit.extensions.client.ReviewerState.CC;
|
||||
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -357,13 +356,8 @@ public class PostReviewers
|
||||
}
|
||||
emailReviewers(rsrc.getChange(), addedReviewers, addedCCs);
|
||||
if (!addedReviewers.isEmpty()) {
|
||||
List<Account.Id> reviewers = Lists.transform(addedReviewers,
|
||||
new Function<PatchSetApproval, Account.Id>() {
|
||||
@Override
|
||||
public Account.Id apply(PatchSetApproval psa) {
|
||||
return psa.getAccountId();
|
||||
}
|
||||
});
|
||||
List<Account.Id> reviewers =
|
||||
Lists.transform(addedReviewers, PatchSetApproval::getAccountId);
|
||||
reviewerAdded.fire(rsrc.getChange(), patchSet, reviewers,
|
||||
ctx.getAccount(), ctx.getWhen());
|
||||
}
|
||||
|
@ -14,15 +14,13 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.data.ParameterizedString;
|
||||
@ -282,14 +280,10 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
return CHANGE_UNMERGEABLE;
|
||||
}
|
||||
}
|
||||
return CHANGES_NOT_MERGEABLE + Joiner.on(", ").join(
|
||||
Iterables.transform(unmergeable,
|
||||
new Function<ChangeData, String>() {
|
||||
@Override
|
||||
public String apply(ChangeData cd) {
|
||||
return String.valueOf(cd.getId().get());
|
||||
}
|
||||
}));
|
||||
return CHANGES_NOT_MERGEABLE +
|
||||
unmergeable.stream()
|
||||
.map(c -> c.getId().toString())
|
||||
.collect(joining(", "));
|
||||
}
|
||||
} catch (ResourceConflictException e) {
|
||||
return BLOCKED_SUBMIT_TOOLTIP;
|
||||
@ -405,14 +399,10 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
*/
|
||||
public ChangeMessage getConflictMessage(RevisionResource rsrc)
|
||||
throws OrmException {
|
||||
return FluentIterable.from(cmUtil.byPatchSet(dbProvider.get(), rsrc.getNotes(),
|
||||
rsrc.getPatchSet().getId()))
|
||||
.filter(new Predicate<ChangeMessage>() {
|
||||
@Override
|
||||
public boolean apply(ChangeMessage input) {
|
||||
return input.getAuthor() == null;
|
||||
}
|
||||
})
|
||||
return FluentIterable.from(
|
||||
cmUtil.byPatchSet(
|
||||
dbProvider.get(), rsrc.getNotes(), rsrc.getPatchSet().getId()))
|
||||
.filter(cm -> cm.getAuthor() == null)
|
||||
.last()
|
||||
.orNull();
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -72,21 +71,17 @@ class WalkSorter {
|
||||
LoggerFactory.getLogger(WalkSorter.class);
|
||||
|
||||
private static final Ordering<List<PatchSetData>> PROJECT_LIST_SORTER =
|
||||
Ordering.natural().nullsFirst()
|
||||
.onResultOf(
|
||||
new Function<List<PatchSetData>, Project.NameKey>() {
|
||||
@Override
|
||||
public Project.NameKey apply(List<PatchSetData> in) {
|
||||
if (in == null || in.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return in.get(0).data().change().getProject();
|
||||
} catch (OrmException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
Ordering.natural().nullsFirst().onResultOf(
|
||||
(List<PatchSetData> in) -> {
|
||||
if (in == null || in.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return in.get(0).data().change().getProject();
|
||||
} catch (OrmException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
});
|
||||
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final Set<PatchSet.Id> includePatchSets;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user