Convert some Functions/Predicates to streams & lambdas
The conversion is somewhat conservative; there are many places where we use things like Lists.transform and FluentIterable where we could in theory switch entirely to streams, but the win is not obvious. Converting Functions to lambdas is pretty much always a win, though. Change-Id: I771b13bddb768426c8bb2dbf81207664994ee21d
This commit is contained in:
@@ -161,17 +161,10 @@ public class Field<T> {
|
|||||||
private static <T> Function<T, String> initFormatter(Class<T> keyType) {
|
private static <T> Function<T, String> initFormatter(Class<T> keyType) {
|
||||||
if (keyType == String.class) {
|
if (keyType == String.class) {
|
||||||
return (Function<T, String>) Functions.<String> identity();
|
return (Function<T, String>) Functions.<String> identity();
|
||||||
|
|
||||||
} else if (keyType == Integer.class || keyType == Boolean.class) {
|
} else if (keyType == Integer.class || keyType == Boolean.class) {
|
||||||
return (Function<T, String>) Functions.toStringFunction();
|
return (Function<T, String>) Functions.toStringFunction();
|
||||||
|
|
||||||
} else if (Enum.class.isAssignableFrom(keyType)) {
|
} else if (Enum.class.isAssignableFrom(keyType)) {
|
||||||
return new Function<T, String>() {
|
return in -> ((Enum<?>) in).name();
|
||||||
@Override
|
|
||||||
public String apply(T in) {
|
|
||||||
return ((Enum<?>) in).name();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("unsupported type " + keyType.getName());
|
throw new IllegalStateException("unsupported type " + keyType.getName());
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.metrics.dropwizard;
|
package com.google.gerrit.metrics.dropwizard;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gerrit.metrics.Description;
|
import com.google.gerrit.metrics.Description;
|
||||||
@@ -124,14 +123,7 @@ abstract class BucketedCallback<V> implements BucketedMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, Metric> getCells() {
|
public Map<Object, Metric> getCells() {
|
||||||
return Maps.transformValues(
|
return Maps.transformValues(cells, in -> (Metric) in);
|
||||||
cells,
|
|
||||||
new Function<ValueGauge, Metric> () {
|
|
||||||
@Override
|
|
||||||
public Metric apply(ValueGauge in) {
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ValueGauge implements Gauge<V> {
|
final class ValueGauge implements Gauge<V> {
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.metrics.dropwizard;
|
package com.google.gerrit.metrics.dropwizard;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gerrit.metrics.Description;
|
import com.google.gerrit.metrics.Description;
|
||||||
@@ -98,13 +97,6 @@ abstract class BucketedCounter implements BucketedMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, Metric> getCells() {
|
public Map<Object, Metric> getCells() {
|
||||||
return Maps.transformValues(
|
return Maps.transformValues(cells, c -> c.metric);
|
||||||
cells,
|
|
||||||
new Function<CounterImpl, Metric> () {
|
|
||||||
@Override
|
|
||||||
public Metric apply(CounterImpl in) {
|
|
||||||
return in.metric;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.metrics.dropwizard;
|
package com.google.gerrit.metrics.dropwizard;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gerrit.metrics.Description;
|
import com.google.gerrit.metrics.Description;
|
||||||
@@ -96,13 +95,6 @@ abstract class BucketedHistogram implements BucketedMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, Metric> getCells() {
|
public Map<Object, Metric> getCells() {
|
||||||
return Maps.transformValues(
|
return Maps.transformValues(cells, h -> h.metric);
|
||||||
cells,
|
|
||||||
new Function<HistogramImpl, Metric> () {
|
|
||||||
@Override
|
|
||||||
public Metric apply(HistogramImpl in) {
|
|
||||||
return in.metric;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.metrics.dropwizard;
|
package com.google.gerrit.metrics.dropwizard;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gerrit.metrics.Description;
|
import com.google.gerrit.metrics.Description;
|
||||||
@@ -96,13 +95,6 @@ abstract class BucketedTimer implements BucketedMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, Metric> getCells() {
|
public Map<Object, Metric> getCells() {
|
||||||
return Maps.transformValues(
|
return Maps.transformValues(cells, t -> t.metric);
|
||||||
cells,
|
|
||||||
new Function<TimerImpl, Metric> () {
|
|
||||||
@Override
|
|
||||||
public Metric apply(TimerImpl in) {
|
|
||||||
return in.metric;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
import static com.google.gerrit.metrics.dropwizard.MetricResource.METRIC_KIND;
|
import static com.google.gerrit.metrics.dropwizard.MetricResource.METRIC_KIND;
|
||||||
import static com.google.gerrit.server.config.ConfigResource.CONFIG_KIND;
|
import static com.google.gerrit.server.config.ConfigResource.CONFIG_KIND;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -304,14 +303,8 @@ public class DropWizardMetricMaker extends MetricMaker {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized RegistrationHandle newTrigger(
|
public synchronized RegistrationHandle newTrigger(
|
||||||
Set<CallbackMetric<?>> metrics, Runnable trigger) {
|
Set<CallbackMetric<?>> metrics, Runnable trigger) {
|
||||||
final ImmutableSet<CallbackMetricGlue> all = FluentIterable.from(metrics)
|
ImmutableSet<CallbackMetricGlue> all = FluentIterable.from(metrics)
|
||||||
.transform(
|
.transform(m -> (CallbackMetricGlue) m)
|
||||||
new Function<CallbackMetric<?>, CallbackMetricGlue>() {
|
|
||||||
@Override
|
|
||||||
public CallbackMetricGlue apply(CallbackMetric<?> input) {
|
|
||||||
return (CallbackMetricGlue) input;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toSet();
|
.toSet();
|
||||||
|
|
||||||
trigger = new CallbackGroup(trigger, all);
|
trigger = new CallbackGroup(trigger, all);
|
||||||
|
@@ -16,9 +16,9 @@ package com.google.gerrit.server;
|
|||||||
|
|
||||||
import static com.google.gerrit.server.notedb.ReviewerStateInternal.CC;
|
import static com.google.gerrit.server.notedb.ReviewerStateInternal.CC;
|
||||||
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
||||||
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
@@ -52,7 +52,6 @@ import com.google.inject.Singleton;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -81,14 +80,7 @@ public class ApprovalsUtil {
|
|||||||
LoggerFactory.getLogger(ApprovalsUtil.class);
|
LoggerFactory.getLogger(ApprovalsUtil.class);
|
||||||
|
|
||||||
private static final Ordering<PatchSetApproval> SORT_APPROVALS =
|
private static final Ordering<PatchSetApproval> SORT_APPROVALS =
|
||||||
Ordering.natural()
|
Ordering.from(comparing(PatchSetApproval::getGranted));
|
||||||
.onResultOf(
|
|
||||||
new Function<PatchSetApproval, Timestamp>() {
|
|
||||||
@Override
|
|
||||||
public Timestamp apply(PatchSetApproval a) {
|
|
||||||
return a.getGranted();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
public static List<PatchSetApproval> sortApprovals(
|
public static List<PatchSetApproval> sortApprovals(
|
||||||
Iterable<PatchSetApproval> approvals) {
|
Iterable<PatchSetApproval> approvals) {
|
||||||
|
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toSet;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@@ -191,14 +191,9 @@ public class AccountResolver {
|
|||||||
|
|
||||||
// At this point we have no clue. Just perform a whole bunch of suggestions
|
// At this point we have no clue. Just perform a whole bunch of suggestions
|
||||||
// and pray we come up with a reasonable result list.
|
// and pray we come up with a reasonable result list.
|
||||||
return FluentIterable
|
return accountQueryProvider.get().byDefault(nameOrEmail).stream()
|
||||||
.from(accountQueryProvider.get().byDefault(nameOrEmail))
|
.map(a -> a.getAccount().getId())
|
||||||
.transform(new Function<AccountState, Account.Id>() {
|
.collect(toSet());
|
||||||
@Override
|
|
||||||
public Account.Id apply(AccountState accountState) {
|
|
||||||
return accountState.getAccount().getId();
|
|
||||||
}
|
|
||||||
}).toSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Account> m = db.accounts().byFullName(nameOrEmail).toList();
|
List<Account> m = db.accounts().byFullName(nameOrEmail).toList();
|
||||||
|
@@ -36,12 +36,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class AccountState {
|
public class AccountState {
|
||||||
public static final Function<AccountState, Account.Id> ACCOUNT_ID_FUNCTION =
|
public static final Function<AccountState, Account.Id> ACCOUNT_ID_FUNCTION =
|
||||||
new Function<AccountState, Account.Id>() {
|
a -> a.getAccount().getId();
|
||||||
@Override
|
|
||||||
public Account.Id apply(AccountState in) {
|
|
||||||
return in.getAccount().getId();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Account account;
|
private final Account account;
|
||||||
private final Set<AccountGroup.UUID> internalGroups;
|
private final Set<AccountGroup.UUID> internalGroups;
|
||||||
|
@@ -14,15 +14,14 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static com.google.common.base.Predicates.not;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.gerrit.common.data.GlobalCapability;
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
import com.google.gerrit.common.data.PermissionRange;
|
import com.google.gerrit.common.data.PermissionRange;
|
||||||
import com.google.gerrit.common.data.PermissionRule;
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
import com.google.gerrit.common.data.PermissionRule.Action;
|
import com.google.gerrit.common.data.PermissionRule.Action;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.PeerDaemonUser;
|
import com.google.gerrit.server.PeerDaemonUser;
|
||||||
import com.google.gerrit.server.git.QueueProvider;
|
import com.google.gerrit.server.git.QueueProvider;
|
||||||
@@ -32,6 +31,7 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -98,7 +98,7 @@ public class CapabilityControl {
|
|||||||
if (canEmailReviewers == null) {
|
if (canEmailReviewers == null) {
|
||||||
canEmailReviewers =
|
canEmailReviewers =
|
||||||
matchAny(capabilities.emailReviewers, ALLOWED_RULE)
|
matchAny(capabilities.emailReviewers, ALLOWED_RULE)
|
||||||
|| !matchAny(capabilities.emailReviewers, Predicates.not(ALLOWED_RULE));
|
|| !matchAny(capabilities.emailReviewers, not(ALLOWED_RULE));
|
||||||
|
|
||||||
}
|
}
|
||||||
return canEmailReviewers;
|
return canEmailReviewers;
|
||||||
@@ -279,23 +279,16 @@ public class CapabilityControl {
|
|||||||
return mine;
|
return mine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Predicate<PermissionRule> ALLOWED_RULE = new Predicate<PermissionRule>() {
|
private static final Predicate<PermissionRule> ALLOWED_RULE =
|
||||||
@Override
|
r -> r.getAction() == Action.ALLOW;
|
||||||
public boolean apply(PermissionRule rule) {
|
|
||||||
return rule.getAction() == Action.ALLOW;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private boolean matchAny(Iterable<PermissionRule> rules, Predicate<PermissionRule> predicate) {
|
private boolean matchAny(Collection<PermissionRule> rules,
|
||||||
Iterable<AccountGroup.UUID> ids = Iterables.transform(
|
Predicate<PermissionRule> predicate) {
|
||||||
Iterables.filter(rules, predicate),
|
return user.getEffectiveGroups()
|
||||||
new Function<PermissionRule, AccountGroup.UUID>() {
|
.containsAnyOf(
|
||||||
@Override
|
FluentIterable.from(rules)
|
||||||
public AccountGroup.UUID apply(PermissionRule rule) {
|
.filter(predicate)
|
||||||
return rule.getGroup().getUUID();
|
.transform(r -> r.getGroup().getUUID()));
|
||||||
}
|
|
||||||
});
|
|
||||||
return user.getEffectiveGroups().containsAnyOf(ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean match(GroupMembership groups,
|
private static boolean match(GroupMembership groups,
|
||||||
|
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toList;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
@@ -105,13 +105,10 @@ public class DeleteWatchedProjects
|
|||||||
|
|
||||||
private void deleteFromGit(Account.Id accountId, List<ProjectWatchInfo> input)
|
private void deleteFromGit(Account.Id accountId, List<ProjectWatchInfo> input)
|
||||||
throws IOException, ConfigInvalidException {
|
throws IOException, ConfigInvalidException {
|
||||||
watchConfig.deleteProjectWatches(accountId, Lists.transform(input,
|
watchConfig.deleteProjectWatches(
|
||||||
new Function<ProjectWatchInfo, ProjectWatchKey>() {
|
accountId,
|
||||||
@Override
|
input.stream().map(w -> ProjectWatchKey.create(
|
||||||
public ProjectWatchKey apply(ProjectWatchInfo info) {
|
new Project.NameKey(w.project), w.filter))
|
||||||
return ProjectWatchKey.create(new Project.NameKey(info.project),
|
.collect(toList()));
|
||||||
info.filter);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||||
@@ -60,13 +59,9 @@ public class GetSshKeys implements RestReadView<AccountResource> {
|
|||||||
|
|
||||||
public List<SshKeyInfo> apply(IdentifiedUser user)
|
public List<SshKeyInfo> apply(IdentifiedUser user)
|
||||||
throws RepositoryNotFoundException, IOException, ConfigInvalidException {
|
throws RepositoryNotFoundException, IOException, ConfigInvalidException {
|
||||||
return Lists.transform(authorizedKeys.getKeys(user.getAccountId()),
|
return Lists.transform(
|
||||||
new Function<AccountSshKey, SshKeyInfo>() {
|
authorizedKeys.getKeys(user.getAccountId()),
|
||||||
@Override
|
GetSshKeys::newSshKeyInfo);
|
||||||
public SshKeyInfo apply(AccountSshKey key) {
|
|
||||||
return newSshKeyInfo(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SshKeyInfo newSshKeyInfo(AccountSshKey sshKey) {
|
public static SshKeyInfo newSshKeyInfo(AccountSshKey sshKey) {
|
||||||
|
@@ -14,10 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toList;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.common.data.GroupDescription;
|
import com.google.gerrit.common.data.GroupDescription;
|
||||||
import com.google.gerrit.common.data.GroupDescriptions;
|
import com.google.gerrit.common.data.GroupDescriptions;
|
||||||
import com.google.gerrit.common.data.GroupReference;
|
import com.google.gerrit.common.data.GroupReference;
|
||||||
@@ -30,18 +28,11 @@ import com.google.inject.Singleton;
|
|||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
/** Implementation of GroupBackend for the internal group system. */
|
/** Implementation of GroupBackend for the internal group system. */
|
||||||
@Singleton
|
@Singleton
|
||||||
public class InternalGroupBackend implements GroupBackend {
|
public class InternalGroupBackend implements GroupBackend {
|
||||||
private static final Function<AccountGroup, GroupReference> ACT_GROUP_TO_GROUP_REF =
|
|
||||||
new Function<AccountGroup, GroupReference>() {
|
|
||||||
@Override
|
|
||||||
public GroupReference apply(AccountGroup group) {
|
|
||||||
return GroupReference.forGroup(group);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final GroupControl.Factory groupControlFactory;
|
private final GroupControl.Factory groupControlFactory;
|
||||||
private final GroupCache groupCache;
|
private final GroupCache groupCache;
|
||||||
private final IncludingGroupMembership.Factory groupMembershipFactory;
|
private final IncludingGroupMembership.Factory groupMembershipFactory;
|
||||||
@@ -77,16 +68,13 @@ public class InternalGroupBackend implements GroupBackend {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<GroupReference> suggest(final String name,
|
public Collection<GroupReference> suggest(final String name,
|
||||||
final ProjectControl project) {
|
final ProjectControl project) {
|
||||||
Iterable<AccountGroup> filtered = Iterables.filter(groupCache.all(),
|
return StreamSupport.stream(groupCache.all().spliterator(), false)
|
||||||
new Predicate<AccountGroup>() {
|
.filter(group ->
|
||||||
@Override
|
|
||||||
public boolean apply(AccountGroup group) {
|
|
||||||
// startsWithIgnoreCase && isVisible
|
// startsWithIgnoreCase && isVisible
|
||||||
return group.getName().regionMatches(true, 0, name, 0, name.length())
|
group.getName().regionMatches(true, 0, name, 0, name.length())
|
||||||
&& groupControlFactory.controlFor(group).isVisible();
|
&& groupControlFactory.controlFor(group).isVisible())
|
||||||
}
|
.map(GroupReference::forGroup)
|
||||||
});
|
.collect(toList());
|
||||||
return Lists.newArrayList(Iterables.transform(filtered, ACT_GROUP_TO_GROUP_REF));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -278,13 +278,7 @@ public class VersionedAuthorizedKeys extends VersionedMetaData {
|
|||||||
* @param newKeys the new public SSH keys
|
* @param newKeys the new public SSH keys
|
||||||
*/
|
*/
|
||||||
public void setKeys(Collection<AccountSshKey> newKeys) {
|
public void setKeys(Collection<AccountSshKey> newKeys) {
|
||||||
Ordering<AccountSshKey> o =
|
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
|
||||||
Ordering.natural().onResultOf(new Function<AccountSshKey, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(AccountSshKey sshKey) {
|
|
||||||
return sshKey.getKey().get();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(),
|
keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(),
|
||||||
Optional.<AccountSshKey> absent()));
|
Optional.<AccountSshKey> absent()));
|
||||||
for (AccountSshKey key : newKeys) {
|
for (AccountSshKey key : newKeys) {
|
||||||
|
@@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.CharMatcher;
|
import com.google.common.base.CharMatcher;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.data.ContributorAgreement;
|
import com.google.gerrit.common.data.ContributorAgreement;
|
||||||
import com.google.gerrit.extensions.common.AuthInfo;
|
import com.google.gerrit.extensions.common.AuthInfo;
|
||||||
@@ -225,14 +225,8 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
getDownloadSchemeInfo(scheme, downloadCommands, cloneCommands));
|
getDownloadSchemeInfo(scheme, downloadCommands, cloneCommands));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.archives = Lists.newArrayList(Iterables.transform(
|
info.archives = archiveFormats.getAllowed().stream()
|
||||||
archiveFormats.getAllowed(),
|
.map(ArchiveFormat::getShortName).collect(toList());
|
||||||
new Function<ArchiveFormat, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(ArchiveFormat in) {
|
|
||||||
return in.getShortName();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toList;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
||||||
import com.google.gerrit.extensions.api.projects.ConfigValue;
|
import com.google.gerrit.extensions.api.projects.ConfigValue;
|
||||||
import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType;
|
import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType;
|
||||||
@@ -137,14 +137,9 @@ public class ProjectConfigEntry {
|
|||||||
T defaultValue, Class<T> permittedValues, boolean inheritable,
|
T defaultValue, Class<T> permittedValues, boolean inheritable,
|
||||||
String description) {
|
String description) {
|
||||||
this(displayName, defaultValue.name(), ProjectConfigEntryType.LIST,
|
this(displayName, defaultValue.name(), ProjectConfigEntryType.LIST,
|
||||||
Lists.transform(
|
Arrays.stream(permittedValues.getEnumConstants())
|
||||||
Arrays.asList(permittedValues.getEnumConstants()),
|
.map(Enum::name).collect(toList()),
|
||||||
new Function<Enum<?>, String>() {
|
inheritable, description);
|
||||||
@Override
|
|
||||||
public String apply(Enum<?> e) {
|
|
||||||
return e.name();
|
|
||||||
}
|
|
||||||
}), inheritable, description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectConfigEntry(String displayName, String defaultValue,
|
public ProjectConfigEntry(String displayName, String defaultValue,
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.extensions.events;
|
package com.google.gerrit.server.extensions.events;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.common.AccountInfo;
|
import com.google.gerrit.extensions.common.AccountInfo;
|
||||||
@@ -72,18 +71,10 @@ public class ReviewerAdded {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AccountInfo> transformed = Lists.transform(reviewers,
|
|
||||||
new Function<Account.Id, AccountInfo>() {
|
|
||||||
@Override
|
|
||||||
public AccountInfo apply(Account.Id account) {
|
|
||||||
return util.accountInfo(account);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fire(util.changeInfo(change),
|
fire(util.changeInfo(change),
|
||||||
util.revisionInfo(change.getProject(), patchSet),
|
util.revisionInfo(change.getProject(), patchSet),
|
||||||
transformed,
|
Lists.transform(reviewers, util::accountInfo),
|
||||||
util.accountInfo(adder),
|
util.accountInfo(adder),
|
||||||
when);
|
when);
|
||||||
} catch (PatchListNotAvailableException | GpgException | IOException
|
} catch (PatchListNotAvailableException | GpgException | IOException
|
||||||
|
@@ -14,11 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.extensions.webui;
|
package com.google.gerrit.server.extensions.webui;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.gerrit.common.Nullable;
|
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.RestCollection;
|
import com.google.gerrit.extensions.restapi.RestCollection;
|
||||||
@@ -33,16 +30,13 @@ import com.google.inject.Provider;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class UiActions {
|
public class UiActions {
|
||||||
private static final Logger log = LoggerFactory.getLogger(UiActions.class);
|
private static final Logger log = LoggerFactory.getLogger(UiActions.class);
|
||||||
|
|
||||||
public static Predicate<UiAction.Description> enabled() {
|
public static Predicate<UiAction.Description> enabled() {
|
||||||
return new Predicate<UiAction.Description>() {
|
return UiAction.Description::isEnabled;
|
||||||
@Override
|
|
||||||
public boolean apply(UiAction.Description input) {
|
|
||||||
return input.isEnabled();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
||||||
@@ -56,13 +50,8 @@ public class UiActions {
|
|||||||
DynamicMap<RestView<R>> views,
|
DynamicMap<RestView<R>> views,
|
||||||
final R resource,
|
final R resource,
|
||||||
final Provider<CurrentUser> userProvider) {
|
final Provider<CurrentUser> userProvider) {
|
||||||
return Iterables.filter(
|
return FluentIterable.from(views)
|
||||||
Iterables.transform(
|
.transform((DynamicMap.Entry<RestView<R>> e) -> {
|
||||||
views,
|
|
||||||
new Function<DynamicMap.Entry<RestView<R>>, UiAction.Description> () {
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public UiAction.Description apply(DynamicMap.Entry<RestView<R>> e) {
|
|
||||||
int d = e.getExportName().indexOf('.');
|
int d = e.getExportName().indexOf('.');
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -105,9 +94,8 @@ public class UiActions {
|
|||||||
? name
|
? name
|
||||||
: e.getPluginName() + '~' + name);
|
: e.getPluginName() + '~' + name);
|
||||||
return dsc;
|
return dsc;
|
||||||
}
|
})
|
||||||
}),
|
.filter(Objects::nonNull);
|
||||||
Predicates.notNull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private UiActions() {
|
private UiActions() {
|
||||||
|
@@ -345,54 +345,36 @@ public class ChangeBundle {
|
|||||||
|
|
||||||
private Map<PatchSetApproval.Key, PatchSetApproval>
|
private Map<PatchSetApproval.Key, PatchSetApproval>
|
||||||
filterPatchSetApprovals() {
|
filterPatchSetApprovals() {
|
||||||
return limitToValidPatchSets(patchSetApprovals,
|
return limitToValidPatchSets(
|
||||||
new Function<PatchSetApproval.Key, PatchSet.Id>() {
|
patchSetApprovals, PatchSetApproval.Key::getParentKey);
|
||||||
@Override
|
|
||||||
public PatchSet.Id apply(PatchSetApproval.Key in) {
|
|
||||||
return in.getParentKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<PatchLineComment.Key, PatchLineComment>
|
private Map<PatchLineComment.Key, PatchLineComment>
|
||||||
filterPatchLineComments() {
|
filterPatchLineComments() {
|
||||||
return limitToValidPatchSets(patchLineComments,
|
return limitToValidPatchSets(
|
||||||
new Function<PatchLineComment.Key, PatchSet.Id>() {
|
patchLineComments,
|
||||||
@Override
|
k -> k.getParentKey().getParentKey());
|
||||||
public PatchSet.Id apply(PatchLineComment.Key in) {
|
|
||||||
return in.getParentKey().getParentKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private <K, V> Map<K, V> limitToValidPatchSets(Map<K, V> in,
|
private <K, V> Map<K, V> limitToValidPatchSets(Map<K, V> in,
|
||||||
final Function<K, PatchSet.Id> func) {
|
Function<K, PatchSet.Id> func) {
|
||||||
return Maps.filterKeys(
|
return Maps.filterKeys(
|
||||||
in, Predicates.compose(validPatchSetPredicate(), func));
|
in, Predicates.compose(validPatchSetPredicate(), func));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<PatchSet.Id> validPatchSetPredicate() {
|
private Predicate<PatchSet.Id> validPatchSetPredicate() {
|
||||||
final Predicate<PatchSet.Id> upToCurrent = upToCurrentPredicate();
|
Predicate<PatchSet.Id> upToCurrent = upToCurrentPredicate();
|
||||||
return new Predicate<PatchSet.Id>() {
|
return p -> upToCurrent.apply(p) && patchSets.containsKey(p);
|
||||||
@Override
|
|
||||||
public boolean apply(PatchSet.Id in) {
|
|
||||||
return upToCurrent.apply(in) && patchSets.containsKey(in);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<ChangeMessage> filterChangeMessages() {
|
private Collection<ChangeMessage> filterChangeMessages() {
|
||||||
final Predicate<PatchSet.Id> validPatchSet = validPatchSetPredicate();
|
final Predicate<PatchSet.Id> validPatchSet = validPatchSetPredicate();
|
||||||
return Collections2.filter(changeMessages,
|
return Collections2.filter(changeMessages, m -> {
|
||||||
new Predicate<ChangeMessage>() {
|
PatchSet.Id psId = m.getPatchSetId();
|
||||||
@Override
|
|
||||||
public boolean apply(ChangeMessage in) {
|
|
||||||
PatchSet.Id psId = in.getPatchSetId();
|
|
||||||
if (psId == null) {
|
if (psId == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return validPatchSet.apply(psId);
|
return validPatchSet.apply(psId);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,9 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
|
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
|
||||||
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
|
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
|
||||||
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -70,7 +70,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -84,22 +83,10 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(ChangeNotes.class);
|
private static final Logger log = LoggerFactory.getLogger(ChangeNotes.class);
|
||||||
|
|
||||||
static final Ordering<PatchSetApproval> PSA_BY_TIME =
|
static final Ordering<PatchSetApproval> PSA_BY_TIME =
|
||||||
Ordering.natural().onResultOf(
|
Ordering.from(comparing(PatchSetApproval::getGranted));
|
||||||
new Function<PatchSetApproval, Timestamp>() {
|
|
||||||
@Override
|
|
||||||
public Timestamp apply(PatchSetApproval input) {
|
|
||||||
return input.getGranted();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
public static final Ordering<ChangeMessage> MESSAGE_BY_TIME =
|
public static final Ordering<ChangeMessage> MESSAGE_BY_TIME =
|
||||||
Ordering.natural().onResultOf(
|
Ordering.from(comparing(ChangeMessage::getWrittenOn));
|
||||||
new Function<ChangeMessage, Timestamp>() {
|
|
||||||
@Override
|
|
||||||
public Timestamp apply(ChangeMessage input) {
|
|
||||||
return input.getWrittenOn();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
public static ConfigInvalidException parseException(Change.Id changeId,
|
public static ConfigInvalidException parseException(Change.Id changeId,
|
||||||
String fmt, Object... args) {
|
String fmt, Object... args) {
|
||||||
|
@@ -30,11 +30,10 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TAG;
|
|||||||
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
|
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
|
||||||
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
|
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
|
||||||
import static java.util.Comparator.comparing;
|
import static java.util.Comparator.comparing;
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.Enums;
|
import com.google.common.base.Enums;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
@@ -883,13 +882,8 @@ class ChangeNotesParser {
|
|||||||
missing.add(FOOTER_SUBJECT);
|
missing.add(FOOTER_SUBJECT);
|
||||||
}
|
}
|
||||||
if (!missing.isEmpty()) {
|
if (!missing.isEmpty()) {
|
||||||
throw parseException("Missing footers: " + Joiner.on(", ")
|
throw parseException("Missing footers: "
|
||||||
.join(Lists.transform(missing, new Function<FooterKey, String>() {
|
+ missing.stream().map(FooterKey::getName).collect(joining(", ")));
|
||||||
@Override
|
|
||||||
public String apply(FooterKey input) {
|
|
||||||
return input.getName();
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,10 +17,9 @@ package com.google.gerrit.server.notedb;
|
|||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.gerrit.server.PatchLineCommentsUtil.PLC_ORDER;
|
import static com.google.gerrit.server.PatchLineCommentsUtil.PLC_ORDER;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||||
@@ -134,13 +133,10 @@ class RevisionNoteBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RevisionNoteData data = new RevisionNoteData();
|
RevisionNoteData data = new RevisionNoteData();
|
||||||
data.comments = FluentIterable.from(PLC_ORDER.sortedCopy(comments.values()))
|
data.comments = comments.values().stream()
|
||||||
.transform(new Function<PatchLineComment, RevisionNoteData.Comment>() {
|
.sorted(PLC_ORDER)
|
||||||
@Override
|
.map(plc -> new RevisionNoteData.Comment(plc, noteUtil.getServerId()))
|
||||||
public RevisionNoteData.Comment apply(PatchLineComment plc) {
|
.collect(toList());
|
||||||
return new RevisionNoteData.Comment(plc, noteUtil.getServerId());
|
|
||||||
}
|
|
||||||
}).toList();
|
|
||||||
data.pushCert = pushCert;
|
data.pushCert = pushCert;
|
||||||
|
|
||||||
try (OutputStreamWriter osw = new OutputStreamWriter(out)) {
|
try (OutputStreamWriter osw = new OutputStreamWriter(out)) {
|
||||||
|
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.notedb;
|
package com.google.gerrit.server.notedb;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
@@ -134,15 +134,15 @@ class RevisionNoteData {
|
|||||||
List<Comment> comments;
|
List<Comment> comments;
|
||||||
|
|
||||||
ImmutableList<PatchLineComment> exportComments(
|
ImmutableList<PatchLineComment> exportComments(
|
||||||
final PatchLineComment.Status status) {
|
PatchLineComment.Status status) {
|
||||||
return ImmutableList.copyOf(
|
return ImmutableList.copyOf(
|
||||||
Lists.transform(comments, new Function<Comment, PatchLineComment>() {
|
comments.stream()
|
||||||
@Override
|
.map(
|
||||||
public PatchLineComment apply(Comment c) {
|
c -> {
|
||||||
PatchLineComment plc = c.export();
|
PatchLineComment plc = c.export();
|
||||||
plc.setStatus(status);
|
plc.setStatus(status);
|
||||||
return plc;
|
return plc;
|
||||||
}
|
})
|
||||||
}));
|
.collect(toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,12 @@
|
|||||||
package com.google.gerrit.server.patch;
|
package com.google.gerrit.server.patch;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -70,6 +70,7 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class PatchListLoader implements Callable<PatchList> {
|
public class PatchListLoader implements Callable<PatchList> {
|
||||||
static final Logger log = LoggerFactory.getLogger(PatchListLoader.class);
|
static final Logger log = LoggerFactory.getLogger(PatchListLoader.class);
|
||||||
@@ -179,16 +180,11 @@ public class PatchListLoader implements Callable<PatchList> {
|
|||||||
key.getNewId(), key.getWhitespace());
|
key.getNewId(), key.getWhitespace());
|
||||||
PatchListKey oldKey = PatchListKey.againstDefaultBase(
|
PatchListKey oldKey = PatchListKey.againstDefaultBase(
|
||||||
key.getOldId(), key.getWhitespace());
|
key.getOldId(), key.getWhitespace());
|
||||||
paths = FluentIterable
|
paths = Stream.concat(
|
||||||
.from(patchListCache.get(newKey, project).getPatches())
|
patchListCache.get(newKey, project).getPatches().stream(),
|
||||||
.append(patchListCache.get(oldKey, project).getPatches())
|
patchListCache.get(oldKey, project).getPatches().stream())
|
||||||
.transform(new Function<PatchListEntry, String>() {
|
.map(PatchListEntry::getNewName)
|
||||||
@Override
|
.collect(toSet());
|
||||||
public String apply(PatchListEntry entry) {
|
|
||||||
return entry.getNewName();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cnt = diffEntries.size();
|
int cnt = diffEntries.size();
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.project;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.errors.PermissionDeniedException;
|
import com.google.gerrit.common.errors.PermissionDeniedException;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -91,14 +90,7 @@ public class BanCommit implements RestModifyView<ProjectResource, Input> {
|
|||||||
if (commits == null || commits.isEmpty()) {
|
if (commits == null || commits.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return Lists.transform(commits, ObjectId::getName);
|
||||||
return Lists.transform(commits,
|
|
||||||
new Function<ObjectId, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(ObjectId id) {
|
|
||||||
return id.getName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BanResultInfo {
|
public static class BanResultInfo {
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.project;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.common.GitPerson;
|
import com.google.gerrit.extensions.common.GitPerson;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -102,12 +101,7 @@ public class GetReflog implements RestReadView<BranchResource> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Lists.transform(entries, new Function<ReflogEntry, ReflogEntryInfo>() {
|
return Lists.transform(entries, ReflogEntryInfo::new);
|
||||||
@Override
|
|
||||||
public ReflogEntryInfo apply(ReflogEntry e) {
|
|
||||||
return new ReflogEntryInfo(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,6 @@ package com.google.gerrit.server.project;
|
|||||||
import static com.google.gerrit.common.data.PermissionRule.Action.ALLOW;
|
import static com.google.gerrit.common.data.PermissionRule.Action.ALLOW;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -72,6 +71,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/** Cached information on a project. */
|
/** Cached information on a project. */
|
||||||
public class ProjectState {
|
public class ProjectState {
|
||||||
@@ -378,75 +378,35 @@ public class ProjectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseContributorAgreements() {
|
public boolean isUseContributorAgreements() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getUseContributorAgreements);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getUseContributorAgreements();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseContentMerge() {
|
public boolean isUseContentMerge() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getUseContentMerge);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getUseContentMerge();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseSignedOffBy() {
|
public boolean isUseSignedOffBy() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getUseSignedOffBy);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getUseSignedOffBy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRequireChangeID() {
|
public boolean isRequireChangeID() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getRequireChangeID);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getRequireChangeID();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCreateNewChangeForAllNotInTarget() {
|
public boolean isCreateNewChangeForAllNotInTarget() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getCreateNewChangeForAllNotInTarget);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getCreateNewChangeForAllNotInTarget();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnableSignedPush() {
|
public boolean isEnableSignedPush() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getEnableSignedPush);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getEnableSignedPush();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRequireSignedPush() {
|
public boolean isRequireSignedPush() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getRequireSignedPush);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getRequireSignedPush();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRejectImplicitMerges() {
|
public boolean isRejectImplicitMerges() {
|
||||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
return getInheritableBoolean(Project::getRejectImplicitMerges);
|
||||||
@Override
|
|
||||||
public InheritableBoolean apply(Project input) {
|
|
||||||
return input.getRejectImplicitMerges();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelTypes getLabelTypes() {
|
public LabelTypes getLabelTypes() {
|
||||||
@@ -551,7 +511,8 @@ public class ProjectState {
|
|||||||
return Files.exists(p) ? new String(Files.readAllBytes(p), UTF_8) : null;
|
return Files.exists(p) ? new String(Files.readAllBytes(p), UTF_8) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getInheritableBoolean(Function<Project, InheritableBoolean> func) {
|
private boolean getInheritableBoolean(
|
||||||
|
Function<Project, InheritableBoolean> func) {
|
||||||
for (ProjectState s : tree()) {
|
for (ProjectState s : tree()) {
|
||||||
switch (func.apply(s.getProject())) {
|
switch (func.apply(s.getProject())) {
|
||||||
case TRUE:
|
case TRUE:
|
||||||
|
@@ -16,7 +16,6 @@ package com.google.gerrit.server.query;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -157,12 +156,7 @@ public class AndSource<T> extends AndPredicate<T>
|
|||||||
|
|
||||||
private Iterable<T> buffer(ResultSet<T> scanner) {
|
private Iterable<T> buffer(ResultSet<T> scanner) {
|
||||||
return FluentIterable.from(Iterables.partition(scanner, 50))
|
return FluentIterable.from(Iterables.partition(scanner, 50))
|
||||||
.transformAndConcat(new Function<List<T>, List<T>>() {
|
.transformAndConcat(this::transformBuffer);
|
||||||
@Override
|
|
||||||
public List<T> apply(List<T> buffer) {
|
|
||||||
return transformBuffer(buffer);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<T> transformBuffer(List<T> buffer) throws OrmRuntimeException {
|
protected List<T> transformBuffer(List<T> buffer) throws OrmRuntimeException {
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query.account;
|
package com.google.gerrit.server.query.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
@@ -124,13 +123,9 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState> {
|
|||||||
|
|
||||||
public Predicate<AccountState> defaultQuery(String query) {
|
public Predicate<AccountState> defaultQuery(String query) {
|
||||||
return Predicate.and(
|
return Predicate.and(
|
||||||
Lists.transform(Splitter.on(' ').omitEmptyStrings().splitToList(query),
|
Lists.transform(
|
||||||
new Function<String, Predicate<AccountState>>() {
|
Splitter.on(' ').omitEmptyStrings().splitToList(query),
|
||||||
@Override
|
this::defaultField));
|
||||||
public Predicate<AccountState> apply(String s) {
|
|
||||||
return defaultField(s);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,9 +16,9 @@ package com.google.gerrit.server.query.change;
|
|||||||
|
|
||||||
import static com.google.gerrit.reviewdb.client.Change.CHANGE_ID_PATTERN;
|
import static com.google.gerrit.reviewdb.client.Change.CHANGE_ID_PATTERN;
|
||||||
import static com.google.gerrit.server.query.change.ChangeData.asChanges;
|
import static com.google.gerrit.server.query.change.ChangeData.asChanges;
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -26,7 +26,6 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import com.google.gerrit.common.data.GroupReference;
|
import com.google.gerrit.common.data.GroupReference;
|
||||||
import com.google.gerrit.common.errors.NotSignedInException;
|
import com.google.gerrit.common.errors.NotSignedInException;
|
||||||
import com.google.gerrit.extensions.common.AccountInfo;
|
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
@@ -632,14 +631,9 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
// expand a group predicate into multiple user predicates
|
// expand a group predicate into multiple user predicates
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
Set<Account.Id> allMembers =
|
Set<Account.Id> allMembers =
|
||||||
new HashSet<>(Lists.transform(
|
args.listMembers.get().setRecursive(true).apply(group).stream()
|
||||||
args.listMembers.get().setRecursive(true).apply(group),
|
.map(a -> new Account.Id(a._accountId))
|
||||||
new Function<AccountInfo, Account.Id>() {
|
.collect(toSet());
|
||||||
@Override
|
|
||||||
public Account.Id apply(AccountInfo accountInfo) {
|
|
||||||
return new Account.Id(accountInfo._accountId);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
int maxLimit = args.indexConfig.maxLimit();
|
int maxLimit = args.indexConfig.maxLimit();
|
||||||
if (allMembers.size() > maxLimit) {
|
if (allMembers.size() > maxLimit) {
|
||||||
// limit the number of query terms otherwise Gerrit will barf
|
// limit the number of query terms otherwise Gerrit will barf
|
||||||
|
@@ -22,7 +22,6 @@ import static com.google.gerrit.server.query.Predicate.or;
|
|||||||
import static com.google.gerrit.server.query.change.ChangeStatusPredicate.open;
|
import static com.google.gerrit.server.query.change.ChangeStatusPredicate.open;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
@@ -191,20 +190,14 @@ public class InternalChangeQuery extends InternalQuery<ChangeData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Lists.transform(notesFactory.create(db, branch.getParentKey(),
|
List<ChangeNotes> notes = notesFactory.create(
|
||||||
changeIds, new com.google.common.base.Predicate<ChangeNotes>() {
|
db, branch.getParentKey(), changeIds,
|
||||||
@Override
|
cn -> {
|
||||||
public boolean apply(ChangeNotes notes) {
|
Change c = cn.getChange();
|
||||||
Change c = notes.getChange();
|
|
||||||
return c.getDest().equals(branch)
|
return c.getDest().equals(branch)
|
||||||
&& c.getStatus() != Change.Status.MERGED;
|
&& c.getStatus() != Change.Status.MERGED;
|
||||||
}
|
|
||||||
}), new Function<ChangeNotes, ChangeData>() {
|
|
||||||
@Override
|
|
||||||
public ChangeData apply(ChangeNotes notes) {
|
|
||||||
return changeDataFactory.create(db, notes);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
return Lists.transform(notes, n -> changeDataFactory.create(db, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromIndex(
|
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromIndex(
|
||||||
|
@@ -15,9 +15,8 @@
|
|||||||
package com.google.gerrit.server.schema;
|
package com.google.gerrit.server.schema;
|
||||||
|
|
||||||
import static com.google.gerrit.server.git.ProjectConfig.ACCESS;
|
import static com.google.gerrit.server.git.ProjectConfig.ACCESS;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.common.data.PermissionRule;
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||||
@@ -67,18 +66,16 @@ public class ProjectConfigSchemaUpdate extends VersionedMetaData {
|
|||||||
Set<String> names = config.getNames(ACCESS, subsection);
|
Set<String> names = config.getNames(ACCESS, subsection);
|
||||||
if (names.contains(name)) {
|
if (names.contains(name)) {
|
||||||
List<String> values =
|
List<String> values =
|
||||||
Arrays.asList(config.getStringList(ACCESS, subsection, name));
|
Arrays.stream(config.getStringList(ACCESS, subsection, name))
|
||||||
values = Lists.transform(values, new Function<String, String>() {
|
.map(r -> {
|
||||||
@Override
|
PermissionRule rule = PermissionRule.fromString(r, false);
|
||||||
public String apply(String ruleString) {
|
|
||||||
PermissionRule rule = PermissionRule.fromString(ruleString, false);
|
|
||||||
if (rule.getForce()) {
|
if (rule.getForce()) {
|
||||||
rule.setForce(false);
|
rule.setForce(false);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
return rule.asString(false);
|
return rule.asString(false);
|
||||||
}
|
})
|
||||||
});
|
.collect(toList());
|
||||||
config.setStringList(ACCESS, subsection, name, values);
|
config.setStringList(ACCESS, subsection, name, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.schema;
|
package com.google.gerrit.server.schema;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
@@ -124,13 +125,7 @@ public class Schema_124 extends SchemaVersion {
|
|||||||
|
|
||||||
private Collection<AccountSshKey> fixInvalidSequenceNumbers(
|
private Collection<AccountSshKey> fixInvalidSequenceNumbers(
|
||||||
Collection<AccountSshKey> keys) {
|
Collection<AccountSshKey> keys) {
|
||||||
Ordering<AccountSshKey> o =
|
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
|
||||||
Ordering.natural().onResultOf(new Function<AccountSshKey, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(AccountSshKey sshKey) {
|
|
||||||
return sshKey.getKey().get();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
List<AccountSshKey> fixedKeys = new ArrayList<>(keys);
|
List<AccountSshKey> fixedKeys = new ArrayList<>(keys);
|
||||||
AccountSshKey minKey = o.min(keys);
|
AccountSshKey minKey = o.min(keys);
|
||||||
while (minKey.getKey().get() <= 0) {
|
while (minKey.getKey().get() <= 0) {
|
||||||
|
@@ -24,7 +24,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
@@ -34,7 +33,6 @@ import com.google.common.collect.ImmutableTable;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Ordering;
|
|
||||||
import com.google.gerrit.common.TimeUtil;
|
import com.google.gerrit.common.TimeUtil;
|
||||||
import com.google.gerrit.common.data.SubmitRecord;
|
import com.google.gerrit.common.data.SubmitRecord;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
@@ -47,6 +45,7 @@ import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||||
import com.google.gerrit.reviewdb.client.RevId;
|
import com.google.gerrit.reviewdb.client.RevId;
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.ReviewerSet;
|
import com.google.gerrit.server.ReviewerSet;
|
||||||
import com.google.gerrit.server.config.GerritServerId;
|
import com.google.gerrit.server.config.GerritServerId;
|
||||||
@@ -381,13 +380,9 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
|||||||
update.commit();
|
update.commit();
|
||||||
|
|
||||||
ChangeNotes notes = newNotes(c);
|
ChangeNotes notes = newNotes(c);
|
||||||
List<PatchSetApproval> approvals = Ordering.natural().onResultOf(
|
List<PatchSetApproval> approvals = ReviewDbUtil.intKeyOrdering()
|
||||||
new Function<PatchSetApproval, Integer>() {
|
.onResultOf(PatchSetApproval::getAccountId)
|
||||||
@Override
|
.sortedCopy(notes.getApprovals().get(c.currentPatchSetId()));
|
||||||
public Integer apply(PatchSetApproval in) {
|
|
||||||
return in.getAccountId().get();
|
|
||||||
}
|
|
||||||
}).sortedCopy(notes.getApprovals().get(c.currentPatchSetId()));
|
|
||||||
assertThat(approvals).hasSize(2);
|
assertThat(approvals).hasSize(2);
|
||||||
|
|
||||||
assertThat(approvals.get(0).getAccountId())
|
assertThat(approvals.get(0).getAccountId())
|
||||||
|
@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.account;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gerrit.extensions.api.GerritApi;
|
import com.google.gerrit.extensions.api.GerritApi;
|
||||||
@@ -476,22 +475,10 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static Iterable<Integer> ids(AccountInfo... accounts) {
|
protected static Iterable<Integer> ids(AccountInfo... accounts) {
|
||||||
return FluentIterable.from(Arrays.asList(accounts)).transform(
|
return FluentIterable.of(accounts).transform(a -> a._accountId);
|
||||||
new Function<AccountInfo, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(AccountInfo in) {
|
|
||||||
return in._accountId;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Iterable<Integer> ids(Iterable<AccountInfo> accounts) {
|
protected static Iterable<Integer> ids(Iterable<AccountInfo> accounts) {
|
||||||
return FluentIterable.from(accounts).transform(
|
return FluentIterable.from(accounts).transform(a -> a._accountId);
|
||||||
new Function<AccountInfo, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(AccountInfo in) {
|
|
||||||
return in._accountId;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user