Merge changes from topic 'lambdas-1'
* changes: Convert some Functions/Predicates to streams & lambdas Java-8ify ReviewDbUtil Use some Java 8 features
This commit is contained in:
commit
789088c402
@ -504,8 +504,7 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
assertThat(ps2List.get(2).message).isEqualTo("join lines");
|
||||
assertThat(ps2List.get(3).message).isEqualTo("typo: content");
|
||||
|
||||
ImmutableList<Message> messages =
|
||||
email.getMessages(r2.getChangeId(), "comment");
|
||||
List<Message> messages = email.getMessages(r2.getChangeId(), "comment");
|
||||
assertThat(messages).hasSize(1);
|
||||
String url = canonicalWebUrl.get();
|
||||
int c = r1.getChange().getId().get();
|
||||
|
@ -119,19 +119,8 @@ class H2CacheFactory implements PersistentCacheFactory, LifecycleListener {
|
||||
public void start() {
|
||||
if (executor != null) {
|
||||
for (final H2CacheImpl<?, ?> cache : caches) {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cache.start();
|
||||
}
|
||||
});
|
||||
|
||||
cleanup.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cache.prune(cleanup);
|
||||
}
|
||||
}, 30, TimeUnit.SECONDS);
|
||||
executor.execute(cache::start);
|
||||
cleanup.schedule(() -> cache.prune(cleanup), 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,24 +144,14 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> implements
|
||||
final ValueHolder<V> h = new ValueHolder<>(val);
|
||||
h.created = TimeUtil.nowMs();
|
||||
mem.put(key, h);
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
store.put(key, h);
|
||||
}
|
||||
});
|
||||
executor.execute(() -> store.put(key, h));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void invalidate(final Object key) {
|
||||
if (keyType.getRawType().isInstance(key) && store.mightContain((K) key)) {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
store.invalidate((K) key);
|
||||
}
|
||||
});
|
||||
executor.execute(() -> store.invalidate((K) key));
|
||||
}
|
||||
mem.invalidate(key);
|
||||
}
|
||||
@ -212,12 +202,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> implements
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
long delay = cal.getTimeInMillis() - TimeUtil.nowMs();
|
||||
service.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
prune(service);
|
||||
}
|
||||
}, delay, TimeUnit.MILLISECONDS);
|
||||
service.schedule(() -> prune(service), delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
static class ValueHolder<V> {
|
||||
@ -252,12 +237,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> implements
|
||||
|
||||
final ValueHolder<V> h = new ValueHolder<>(loader.load(key));
|
||||
h.created = TimeUtil.nowMs();
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
store.put(key, h);
|
||||
}
|
||||
});
|
||||
executor.execute(() -> store.put(key, h));
|
||||
return h;
|
||||
}
|
||||
}
|
||||
@ -282,12 +262,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> implements
|
||||
|
||||
final ValueHolder<V> h = new ValueHolder<>(loader.call());
|
||||
h.created = TimeUtil.nowMs();
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
store.put(key, h);
|
||||
}
|
||||
});
|
||||
executor.execute(() -> store.put(key, h));
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,8 @@ import static com.google.gerrit.reviewdb.client.AccountExternalId.SCHEME_GPGKEY;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||
@ -274,9 +272,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
||||
private static String missingUserIds(Set<String> allowedUserIds) {
|
||||
StringBuilder sb = new StringBuilder("Key must contain a valid"
|
||||
+ " certification for one of the following identities:\n");
|
||||
Iterator<String> sorted = FluentIterable.from(allowedUserIds)
|
||||
.toSortedList(Ordering.natural())
|
||||
.iterator();
|
||||
Iterator<String> sorted = allowedUserIds.stream().sorted().iterator();
|
||||
while (sorted.hasNext()) {
|
||||
sb.append(" ").append(sorted.next());
|
||||
if (sorted.hasNext()) {
|
||||
|
@ -19,7 +19,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
@ -211,14 +210,8 @@ public class GpgKeys implements
|
||||
@VisibleForTesting
|
||||
public static FluentIterable<AccountExternalId> getGpgExtIds(ReviewDb db,
|
||||
Account.Id accountId) throws OrmException {
|
||||
return FluentIterable
|
||||
.from(db.accountExternalIds().byAccount(accountId))
|
||||
.filter(new Predicate<AccountExternalId>() {
|
||||
@Override
|
||||
public boolean apply(AccountExternalId in) {
|
||||
return in.isScheme(SCHEME_GPGKEY);
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(db.accountExternalIds().byAccount(accountId))
|
||||
.filter(in -> in.isScheme(SCHEME_GPGKEY));
|
||||
}
|
||||
|
||||
private Iterable<AccountExternalId> getGpgExtIds(AccountResource rsrc)
|
||||
|
@ -18,7 +18,6 @@ import static com.google.gerrit.gpg.PublicKeyStore.keyIdToString;
|
||||
import static com.google.gerrit.gpg.PublicKeyStore.keyToString;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -161,13 +160,8 @@ public class PostGpgKeys implements RestModifyView<AccountResource, Input> {
|
||||
if (!newExtIds.isEmpty()) {
|
||||
db.get().accountExternalIds().insert(newExtIds);
|
||||
}
|
||||
db.get().accountExternalIds().deleteKeys(Iterables.transform(toRemove,
|
||||
new Function<Fingerprint, AccountExternalId.Key>() {
|
||||
@Override
|
||||
public AccountExternalId.Key apply(Fingerprint fp) {
|
||||
return toExtIdKey(fp.get());
|
||||
}
|
||||
}));
|
||||
db.get().accountExternalIds().deleteKeys(
|
||||
Iterables.transform(toRemove, fp -> toExtIdKey(fp.get())));
|
||||
accountCache.evict(rsrc.getUser().getAccountId());
|
||||
return toJson(newKeys, toRemove, store, rsrc.getUser());
|
||||
}
|
||||
|
@ -609,9 +609,7 @@ class GitwebServlet extends HttpServlet {
|
||||
final OutputStream dst) throws IOException {
|
||||
final int contentLength = req.getContentLength();
|
||||
final InputStream src = req.getInputStream();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
final byte[] buf = new byte[bufferSize];
|
||||
@ -631,14 +629,11 @@ class GitwebServlet extends HttpServlet {
|
||||
} catch (IOException e) {
|
||||
log.debug("Unexpected error copying input to CGI", e);
|
||||
}
|
||||
}
|
||||
}, "Gitweb-InputFeeder").start();
|
||||
}
|
||||
|
||||
private void copyStderrToLog(final InputStream in) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
try (BufferedReader br =
|
||||
new BufferedReader(new InputStreamReader(in, ISO_8859_1.name()))) {
|
||||
String line;
|
||||
@ -648,7 +643,6 @@ class GitwebServlet extends HttpServlet {
|
||||
} catch (IOException e) {
|
||||
log.debug("Unexpected error copying stderr from CGI", e);
|
||||
}
|
||||
}
|
||||
}, "Gitweb-ErrorLogger").start();
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,13 @@ import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
import static com.google.gerrit.server.plugins.PluginEntry.ATTR_CHARACTER_ENCODING;
|
||||
import static com.google.gerrit.server.plugins.PluginEntry.ATTR_CONTENT_TYPE;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@ -74,6 +73,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -378,9 +378,8 @@ class HttpPluginServlet extends HttpServlet
|
||||
List<PluginEntry> docs = new ArrayList<>();
|
||||
PluginEntry about = null;
|
||||
|
||||
Predicate<PluginEntry> filter = new Predicate<PluginEntry>() {
|
||||
@Override
|
||||
public boolean apply(PluginEntry entry) {
|
||||
Predicate<PluginEntry> filter =
|
||||
entry -> {
|
||||
String name = entry.getName();
|
||||
Optional<Long> size = entry.getSize();
|
||||
if (name.startsWith(prefix)
|
||||
@ -399,13 +398,10 @@ class HttpPluginServlet extends HttpServlet
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
List<PluginEntry> entries = FluentIterable
|
||||
.from(Collections.list(scanner.entries()))
|
||||
.filter(filter)
|
||||
.toList();
|
||||
List<PluginEntry> entries = Collections.list(scanner.entries()).stream()
|
||||
.filter(filter).collect(toList());
|
||||
for (PluginEntry entry: entries) {
|
||||
String name = entry.getName().substring(prefix.length());
|
||||
if (name.startsWith("cmd-")) {
|
||||
|
@ -294,9 +294,7 @@ public abstract class ResourceServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
private Callable<Resource> newLoader(final Path p) {
|
||||
return new Callable<Resource>() {
|
||||
@Override
|
||||
public Resource call() throws IOException {
|
||||
return () -> {
|
||||
try {
|
||||
return new Resource(
|
||||
getLastModifiedTime(p),
|
||||
@ -305,7 +303,6 @@ public abstract class ResourceServlet extends HttpServlet {
|
||||
} catch (NoSuchFileException e) {
|
||||
return Resource.NOT_FOUND;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import static com.google.common.net.HttpHeaders.VARY;
|
||||
import static java.math.RoundingMode.CEILING;
|
||||
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
|
||||
@ -41,9 +42,7 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -145,6 +144,7 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.StreamSupport;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@ -497,11 +497,13 @@ public class RestApiServlet extends HttpServlet {
|
||||
String headers = req.getHeader(ACCESS_CONTROL_REQUEST_HEADERS);
|
||||
if (headers != null) {
|
||||
res.addHeader(VARY, ACCESS_CONTROL_REQUEST_HEADERS);
|
||||
String badHeader = Iterables.getFirst(
|
||||
Iterables.filter(
|
||||
Splitter.on(',').trimResults().split(headers),
|
||||
Predicates.not(Predicates.in(ALLOWED_CORS_REQUEST_HEADERS))),
|
||||
null);
|
||||
String badHeader =
|
||||
StreamSupport.stream(
|
||||
Splitter.on(',').trimResults().split(headers).spliterator(),
|
||||
false)
|
||||
.filter(h -> !ALLOWED_CORS_REQUEST_HEADERS.contains(h))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (badHeader != null) {
|
||||
throw new BadRequestException(badHeader + " not allowed in CORS");
|
||||
}
|
||||
@ -1034,16 +1036,12 @@ public class RestApiServlet extends HttpServlet {
|
||||
} else if (r.isEmpty()) {
|
||||
throw new ResourceNotFoundException(projection);
|
||||
} else {
|
||||
throw new AmbiguousViewException(String.format(
|
||||
throw new AmbiguousViewException(
|
||||
String.format(
|
||||
"Projection %s is ambiguous: %s",
|
||||
name,
|
||||
Joiner.on(", ").join(
|
||||
Iterables.transform(r.keySet(), new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String in) {
|
||||
return in + "~" + projection;
|
||||
}
|
||||
}))));
|
||||
r.keySet().stream().map(in -> in + "~" + projection)
|
||||
.collect(joining(", "))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.httpd.rpc.project;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
@ -238,14 +237,7 @@ class ProjectAccessFactory extends Handler<ProjectAccess> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Maps.filterEntries(
|
||||
infos,
|
||||
new Predicate<Map.Entry<AccountGroup.UUID, GroupInfo>>() {
|
||||
@Override
|
||||
public boolean apply(Map.Entry<AccountGroup.UUID, GroupInfo> in) {
|
||||
return in.getValue() != null;
|
||||
}
|
||||
});
|
||||
return Maps.filterEntries(infos, in -> in.getValue() != null);
|
||||
}
|
||||
|
||||
private ProjectControl open() throws NoSuchProjectException {
|
||||
|
@ -14,41 +14,37 @@
|
||||
|
||||
package com.google.gerrit.reviewdb.server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwtorm.client.IntKey;
|
||||
|
||||
/** Static utilities for ReviewDb types. */
|
||||
public class ReviewDbUtil {
|
||||
public static final Function<IntKey<?>, Integer> INT_KEY_FUNCTION =
|
||||
new Function<IntKey<?>, Integer>() {
|
||||
@Override
|
||||
public Integer apply(IntKey<?> in) {
|
||||
return in.get();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function<Change, Change.Id> CHANGE_ID_FUNCTION =
|
||||
new Function<Change, Change.Id>() {
|
||||
@Override
|
||||
public Change.Id apply(Change in) {
|
||||
return in.getId();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Ordering<? extends IntKey<?>> INT_KEY_ORDERING =
|
||||
Ordering.natural().nullsFirst().onResultOf(INT_KEY_FUNCTION).nullsFirst();
|
||||
Ordering.natural()
|
||||
.nullsFirst()
|
||||
.<IntKey<?>>onResultOf(IntKey::get)
|
||||
.nullsFirst();
|
||||
|
||||
/**
|
||||
* Null-safe ordering over arbitrary subclass of {@code IntKey}.
|
||||
* <p>
|
||||
* In some cases, {@code Comparator.comparing(Change.Id::get)} may be shorter
|
||||
* and cleaner. However, this method may be preferable in some cases:
|
||||
* <ul>
|
||||
* <li>This ordering is null-safe over both input and the result of {@link
|
||||
* IntKey#get()}; {@code comparing} is only a good idea if all inputs are
|
||||
* obviously non-null.</li>
|
||||
* <li>{@code intKeyOrdering().sortedCopy(iterable)} is shorter than the
|
||||
* stream equivalent.</li>
|
||||
* <li>Creating derived comparators may be more readable with {@link Ordering}
|
||||
* method chaining rather than static {@code Comparator} methods.
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K extends IntKey<?>> Ordering<K> intKeyOrdering() {
|
||||
return (Ordering<K>) INT_KEY_ORDERING;
|
||||
}
|
||||
|
||||
public static Function<Change, Change.Id> changeIdFunction() {
|
||||
return CHANGE_ID_FUNCTION;
|
||||
}
|
||||
|
||||
public static ReviewDb unwrapDb(ReviewDb db) {
|
||||
if (db instanceof DisabledChangesReviewDbWrapper) {
|
||||
return ((DisabledChangesReviewDbWrapper) db).unsafeGetDelegate();
|
||||
|
@ -161,17 +161,10 @@ public class Field<T> {
|
||||
private static <T> Function<T, String> initFormatter(Class<T> keyType) {
|
||||
if (keyType == String.class) {
|
||||
return (Function<T, String>) Functions.<String> identity();
|
||||
|
||||
} else if (keyType == Integer.class || keyType == Boolean.class) {
|
||||
return (Function<T, String>) Functions.toStringFunction();
|
||||
|
||||
} else if (Enum.class.isAssignableFrom(keyType)) {
|
||||
return new Function<T, String>() {
|
||||
@Override
|
||||
public String apply(T in) {
|
||||
return ((Enum<?>) in).name();
|
||||
}
|
||||
};
|
||||
return in -> ((Enum<?>) in).name();
|
||||
}
|
||||
throw new IllegalStateException("unsupported type " + keyType.getName());
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@ -124,14 +123,7 @@ abstract class BucketedCallback<V> implements BucketedMetric {
|
||||
|
||||
@Override
|
||||
public Map<Object, Metric> getCells() {
|
||||
return Maps.transformValues(
|
||||
cells,
|
||||
new Function<ValueGauge, Metric> () {
|
||||
@Override
|
||||
public Metric apply(ValueGauge in) {
|
||||
return in;
|
||||
}
|
||||
});
|
||||
return Maps.transformValues(cells, in -> (Metric) in);
|
||||
}
|
||||
|
||||
final class ValueGauge implements Gauge<V> {
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@ -98,13 +97,6 @@ abstract class BucketedCounter implements BucketedMetric {
|
||||
|
||||
@Override
|
||||
public Map<Object, Metric> getCells() {
|
||||
return Maps.transformValues(
|
||||
cells,
|
||||
new Function<CounterImpl, Metric> () {
|
||||
@Override
|
||||
public Metric apply(CounterImpl in) {
|
||||
return in.metric;
|
||||
}
|
||||
});
|
||||
return Maps.transformValues(cells, c -> c.metric);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@ -96,13 +95,6 @@ abstract class BucketedHistogram implements BucketedMetric {
|
||||
|
||||
@Override
|
||||
public Map<Object, Metric> getCells() {
|
||||
return Maps.transformValues(
|
||||
cells,
|
||||
new Function<HistogramImpl, Metric> () {
|
||||
@Override
|
||||
public Metric apply(HistogramImpl in) {
|
||||
return in.metric;
|
||||
}
|
||||
});
|
||||
return Maps.transformValues(cells, h -> h.metric);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@ -96,13 +95,6 @@ abstract class BucketedTimer implements BucketedMetric {
|
||||
|
||||
@Override
|
||||
public Map<Object, Metric> getCells() {
|
||||
return Maps.transformValues(
|
||||
cells,
|
||||
new Function<TimerImpl, Metric> () {
|
||||
@Override
|
||||
public Metric apply(TimerImpl in) {
|
||||
return in.metric;
|
||||
}
|
||||
});
|
||||
return Maps.transformValues(cells, t -> t.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.server.config.ConfigResource.CONFIG_KIND;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -304,14 +303,8 @@ public class DropWizardMetricMaker extends MetricMaker {
|
||||
@Override
|
||||
public synchronized RegistrationHandle newTrigger(
|
||||
Set<CallbackMetric<?>> metrics, Runnable trigger) {
|
||||
final ImmutableSet<CallbackMetricGlue> all = FluentIterable.from(metrics)
|
||||
.transform(
|
||||
new Function<CallbackMetric<?>, CallbackMetricGlue>() {
|
||||
@Override
|
||||
public CallbackMetricGlue apply(CallbackMetric<?> input) {
|
||||
return (CallbackMetricGlue) input;
|
||||
}
|
||||
})
|
||||
ImmutableSet<CallbackMetricGlue> all = FluentIterable.from(metrics)
|
||||
.transform(m -> (CallbackMetricGlue) m)
|
||||
.toSet();
|
||||
|
||||
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.REVIEWER;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
@ -52,7 +52,6 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -81,14 +80,7 @@ public class ApprovalsUtil {
|
||||
LoggerFactory.getLogger(ApprovalsUtil.class);
|
||||
|
||||
private static final Ordering<PatchSetApproval> SORT_APPROVALS =
|
||||
Ordering.natural()
|
||||
.onResultOf(
|
||||
new Function<PatchSetApproval, Timestamp>() {
|
||||
@Override
|
||||
public Timestamp apply(PatchSetApproval a) {
|
||||
return a.getGranted();
|
||||
}
|
||||
});
|
||||
Ordering.from(comparing(PatchSetApproval::getGranted));
|
||||
|
||||
public static List<PatchSetApproval> sortApprovals(
|
||||
Iterable<PatchSetApproval> approvals) {
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||
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
|
||||
// and pray we come up with a reasonable result list.
|
||||
return FluentIterable
|
||||
.from(accountQueryProvider.get().byDefault(nameOrEmail))
|
||||
.transform(new Function<AccountState, Account.Id>() {
|
||||
@Override
|
||||
public Account.Id apply(AccountState accountState) {
|
||||
return accountState.getAccount().getId();
|
||||
}
|
||||
}).toSet();
|
||||
return accountQueryProvider.get().byDefault(nameOrEmail).stream()
|
||||
.map(a -> a.getAccount().getId())
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
List<Account> m = db.accounts().byFullName(nameOrEmail).toList();
|
||||
|
@ -36,12 +36,7 @@ import java.util.Set;
|
||||
|
||||
public class AccountState {
|
||||
public static final Function<AccountState, Account.Id> ACCOUNT_ID_FUNCTION =
|
||||
new Function<AccountState, Account.Id>() {
|
||||
@Override
|
||||
public Account.Id apply(AccountState in) {
|
||||
return in.getAccount().getId();
|
||||
}
|
||||
};
|
||||
a -> a.getAccount().getId();
|
||||
|
||||
private final Account account;
|
||||
private final Set<AccountGroup.UUID> internalGroups;
|
||||
|
@ -14,15 +14,14 @@
|
||||
|
||||
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.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
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.PeerDaemonUser;
|
||||
import com.google.gerrit.server.git.QueueProvider;
|
||||
@ -32,6 +31,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -98,7 +98,7 @@ public class CapabilityControl {
|
||||
if (canEmailReviewers == null) {
|
||||
canEmailReviewers =
|
||||
matchAny(capabilities.emailReviewers, ALLOWED_RULE)
|
||||
|| !matchAny(capabilities.emailReviewers, Predicates.not(ALLOWED_RULE));
|
||||
|| !matchAny(capabilities.emailReviewers, not(ALLOWED_RULE));
|
||||
|
||||
}
|
||||
return canEmailReviewers;
|
||||
@ -279,23 +279,16 @@ public class CapabilityControl {
|
||||
return mine;
|
||||
}
|
||||
|
||||
private static final Predicate<PermissionRule> ALLOWED_RULE = new Predicate<PermissionRule>() {
|
||||
@Override
|
||||
public boolean apply(PermissionRule rule) {
|
||||
return rule.getAction() == Action.ALLOW;
|
||||
}
|
||||
};
|
||||
private static final Predicate<PermissionRule> ALLOWED_RULE =
|
||||
r -> r.getAction() == Action.ALLOW;
|
||||
|
||||
private boolean matchAny(Iterable<PermissionRule> rules, Predicate<PermissionRule> predicate) {
|
||||
Iterable<AccountGroup.UUID> ids = Iterables.transform(
|
||||
Iterables.filter(rules, predicate),
|
||||
new Function<PermissionRule, AccountGroup.UUID>() {
|
||||
@Override
|
||||
public AccountGroup.UUID apply(PermissionRule rule) {
|
||||
return rule.getGroup().getUUID();
|
||||
}
|
||||
});
|
||||
return user.getEffectiveGroups().containsAnyOf(ids);
|
||||
private boolean matchAny(Collection<PermissionRule> rules,
|
||||
Predicate<PermissionRule> predicate) {
|
||||
return user.getEffectiveGroups()
|
||||
.containsAnyOf(
|
||||
FluentIterable.from(rules)
|
||||
.filter(predicate)
|
||||
.transform(r -> r.getGroup().getUUID()));
|
||||
}
|
||||
|
||||
private static boolean match(GroupMembership groups,
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
@ -105,13 +105,10 @@ public class DeleteWatchedProjects
|
||||
|
||||
private void deleteFromGit(Account.Id accountId, List<ProjectWatchInfo> input)
|
||||
throws IOException, ConfigInvalidException {
|
||||
watchConfig.deleteProjectWatches(accountId, Lists.transform(input,
|
||||
new Function<ProjectWatchInfo, ProjectWatchKey>() {
|
||||
@Override
|
||||
public ProjectWatchKey apply(ProjectWatchInfo info) {
|
||||
return ProjectWatchKey.create(new Project.NameKey(info.project),
|
||||
info.filter);
|
||||
}
|
||||
}));
|
||||
watchConfig.deleteProjectWatches(
|
||||
accountId,
|
||||
input.stream().map(w -> ProjectWatchKey.create(
|
||||
new Project.NameKey(w.project), w.filter))
|
||||
.collect(toList()));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
@ -60,13 +59,9 @@ public class GetSshKeys implements RestReadView<AccountResource> {
|
||||
|
||||
public List<SshKeyInfo> apply(IdentifiedUser user)
|
||||
throws RepositoryNotFoundException, IOException, ConfigInvalidException {
|
||||
return Lists.transform(authorizedKeys.getKeys(user.getAccountId()),
|
||||
new Function<AccountSshKey, SshKeyInfo>() {
|
||||
@Override
|
||||
public SshKeyInfo apply(AccountSshKey key) {
|
||||
return newSshKeyInfo(key);
|
||||
}
|
||||
});
|
||||
return Lists.transform(
|
||||
authorizedKeys.getKeys(user.getAccountId()),
|
||||
GetSshKeys::newSshKeyInfo);
|
||||
}
|
||||
|
||||
public static SshKeyInfo newSshKeyInfo(AccountSshKey sshKey) {
|
||||
|
@ -14,10 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
@ -30,18 +28,11 @@ import com.google.inject.Singleton;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/** Implementation of GroupBackend for the internal group system. */
|
||||
@Singleton
|
||||
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 GroupCache groupCache;
|
||||
private final IncludingGroupMembership.Factory groupMembershipFactory;
|
||||
@ -77,16 +68,13 @@ public class InternalGroupBackend implements GroupBackend {
|
||||
@Override
|
||||
public Collection<GroupReference> suggest(final String name,
|
||||
final ProjectControl project) {
|
||||
Iterable<AccountGroup> filtered = Iterables.filter(groupCache.all(),
|
||||
new Predicate<AccountGroup>() {
|
||||
@Override
|
||||
public boolean apply(AccountGroup group) {
|
||||
return StreamSupport.stream(groupCache.all().spliterator(), false)
|
||||
.filter(group ->
|
||||
// startsWithIgnoreCase && isVisible
|
||||
return group.getName().regionMatches(true, 0, name, 0, name.length())
|
||||
&& groupControlFactory.controlFor(group).isVisible();
|
||||
}
|
||||
});
|
||||
return Lists.newArrayList(Iterables.transform(filtered, ACT_GROUP_TO_GROUP_REF));
|
||||
group.getName().regionMatches(true, 0, name, 0, name.length())
|
||||
&& groupControlFactory.controlFor(group).isVisible())
|
||||
.map(GroupReference::forGroup)
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,8 +15,8 @@
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
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.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -278,13 +278,7 @@ public class VersionedAuthorizedKeys extends VersionedMetaData {
|
||||
* @param newKeys the new public SSH keys
|
||||
*/
|
||||
public void setKeys(Collection<AccountSshKey> newKeys) {
|
||||
Ordering<AccountSshKey> o =
|
||||
Ordering.natural().onResultOf(new Function<AccountSshKey, Integer>() {
|
||||
@Override
|
||||
public Integer apply(AccountSshKey sshKey) {
|
||||
return sshKey.getKey().get();
|
||||
}
|
||||
});
|
||||
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
|
||||
keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(),
|
||||
Optional.<AccountSshKey> absent()));
|
||||
for (AccountSshKey key : newKeys) {
|
||||
|
@ -14,11 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.extensions.client.UiType;
|
||||
@ -230,14 +230,8 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
getDownloadSchemeInfo(scheme, downloadCommands, cloneCommands));
|
||||
}
|
||||
}
|
||||
info.archives = Lists.newArrayList(Iterables.transform(
|
||||
archiveFormats.getAllowed(),
|
||||
new Function<ArchiveFormat, String>() {
|
||||
@Override
|
||||
public String apply(ArchiveFormat in) {
|
||||
return in.getShortName();
|
||||
}
|
||||
}));
|
||||
info.archives = archiveFormats.getAllowed().stream()
|
||||
.map(ArchiveFormat::getShortName).collect(toList());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigValue;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType;
|
||||
@ -137,14 +137,9 @@ public class ProjectConfigEntry {
|
||||
T defaultValue, Class<T> permittedValues, boolean inheritable,
|
||||
String description) {
|
||||
this(displayName, defaultValue.name(), ProjectConfigEntryType.LIST,
|
||||
Lists.transform(
|
||||
Arrays.asList(permittedValues.getEnumConstants()),
|
||||
new Function<Enum<?>, String>() {
|
||||
@Override
|
||||
public String apply(Enum<?> e) {
|
||||
return e.name();
|
||||
}
|
||||
}), inheritable, description);
|
||||
Arrays.stream(permittedValues.getEnumConstants())
|
||||
.map(Enum::name).collect(toList()),
|
||||
inheritable, description);
|
||||
}
|
||||
|
||||
public ProjectConfigEntry(String displayName, String defaultValue,
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.extensions.events;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
@ -72,18 +71,10 @@ public class ReviewerAdded {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AccountInfo> transformed = Lists.transform(reviewers,
|
||||
new Function<Account.Id, AccountInfo>() {
|
||||
@Override
|
||||
public AccountInfo apply(Account.Id account) {
|
||||
return util.accountInfo(account);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
fire(util.changeInfo(change),
|
||||
util.revisionInfo(change.getProject(), patchSet),
|
||||
transformed,
|
||||
Lists.transform(reviewers, util::accountInfo),
|
||||
util.accountInfo(adder),
|
||||
when);
|
||||
} catch (PatchListNotAvailableException | GpgException | IOException
|
||||
|
@ -14,11 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.extensions.webui;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.RestCollection;
|
||||
@ -33,16 +30,13 @@ import com.google.inject.Provider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class UiActions {
|
||||
private static final Logger log = LoggerFactory.getLogger(UiActions.class);
|
||||
|
||||
public static Predicate<UiAction.Description> enabled() {
|
||||
return new Predicate<UiAction.Description>() {
|
||||
@Override
|
||||
public boolean apply(UiAction.Description input) {
|
||||
return input.isEnabled();
|
||||
}
|
||||
};
|
||||
return UiAction.Description::isEnabled;
|
||||
}
|
||||
|
||||
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
||||
@ -56,13 +50,8 @@ public class UiActions {
|
||||
DynamicMap<RestView<R>> views,
|
||||
final R resource,
|
||||
final Provider<CurrentUser> userProvider) {
|
||||
return Iterables.filter(
|
||||
Iterables.transform(
|
||||
views,
|
||||
new Function<DynamicMap.Entry<RestView<R>>, UiAction.Description> () {
|
||||
@Override
|
||||
@Nullable
|
||||
public UiAction.Description apply(DynamicMap.Entry<RestView<R>> e) {
|
||||
return FluentIterable.from(views)
|
||||
.transform((DynamicMap.Entry<RestView<R>> e) -> {
|
||||
int d = e.getExportName().indexOf('.');
|
||||
if (d < 0) {
|
||||
return null;
|
||||
@ -105,9 +94,8 @@ public class UiActions {
|
||||
? name
|
||||
: e.getPluginName() + '~' + name);
|
||||
return dsc;
|
||||
}
|
||||
}),
|
||||
Predicates.notNull());
|
||||
})
|
||||
.filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
private UiActions() {
|
||||
|
@ -17,6 +17,7 @@ package com.google.gerrit.server.git;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
@ -226,7 +227,7 @@ public class BatchUpdate implements AutoCloseable {
|
||||
this.dbWrapper = dbWrapper;
|
||||
this.threadLocalRepo = repo;
|
||||
this.threadLocalRevWalk = rw;
|
||||
updates = new TreeMap<>(ReviewDbUtil.intKeyOrdering());
|
||||
updates = new TreeMap<>(comparing(PatchSet.Id::get));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,13 +182,7 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
|
||||
}
|
||||
}
|
||||
Collections.sort(commits, ReviewDbUtil.intKeyOrdering().reverse()
|
||||
.onResultOf(
|
||||
new Function<CodeReviewCommit, PatchSet.Id>() {
|
||||
@Override
|
||||
public PatchSet.Id apply(CodeReviewCommit in) {
|
||||
return in.getPatchsetId();
|
||||
}
|
||||
}));
|
||||
.onResultOf(c -> c.getPatchsetId()));
|
||||
CodeReviewCommit result = MergeUtil.findAnyMergedInto(rw, commits, tip);
|
||||
if (result == null) {
|
||||
return null;
|
||||
|
@ -34,7 +34,6 @@ import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.StarredChangesUtil;
|
||||
import com.google.gerrit.server.index.FieldDef;
|
||||
@ -694,8 +693,7 @@ public class ChangeField {
|
||||
@Override
|
||||
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
||||
throws OrmException {
|
||||
return Iterables.transform(input.stars().keySet(),
|
||||
ReviewDbUtil.INT_KEY_FUNCTION);
|
||||
return Iterables.transform(input.stars().keySet(), Account.Id::get);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -345,54 +345,36 @@ public class ChangeBundle {
|
||||
|
||||
private Map<PatchSetApproval.Key, PatchSetApproval>
|
||||
filterPatchSetApprovals() {
|
||||
return limitToValidPatchSets(patchSetApprovals,
|
||||
new Function<PatchSetApproval.Key, PatchSet.Id>() {
|
||||
@Override
|
||||
public PatchSet.Id apply(PatchSetApproval.Key in) {
|
||||
return in.getParentKey();
|
||||
}
|
||||
});
|
||||
return limitToValidPatchSets(
|
||||
patchSetApprovals, PatchSetApproval.Key::getParentKey);
|
||||
}
|
||||
|
||||
private Map<PatchLineComment.Key, PatchLineComment>
|
||||
filterPatchLineComments() {
|
||||
return limitToValidPatchSets(patchLineComments,
|
||||
new Function<PatchLineComment.Key, PatchSet.Id>() {
|
||||
@Override
|
||||
public PatchSet.Id apply(PatchLineComment.Key in) {
|
||||
return in.getParentKey().getParentKey();
|
||||
}
|
||||
});
|
||||
return limitToValidPatchSets(
|
||||
patchLineComments,
|
||||
k -> k.getParentKey().getParentKey());
|
||||
}
|
||||
|
||||
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(
|
||||
in, Predicates.compose(validPatchSetPredicate(), func));
|
||||
}
|
||||
|
||||
private Predicate<PatchSet.Id> validPatchSetPredicate() {
|
||||
final Predicate<PatchSet.Id> upToCurrent = upToCurrentPredicate();
|
||||
return new Predicate<PatchSet.Id>() {
|
||||
@Override
|
||||
public boolean apply(PatchSet.Id in) {
|
||||
return upToCurrent.apply(in) && patchSets.containsKey(in);
|
||||
}
|
||||
};
|
||||
Predicate<PatchSet.Id> upToCurrent = upToCurrentPredicate();
|
||||
return p -> upToCurrent.apply(p) && patchSets.containsKey(p);
|
||||
}
|
||||
|
||||
private Collection<ChangeMessage> filterChangeMessages() {
|
||||
final Predicate<PatchSet.Id> validPatchSet = validPatchSetPredicate();
|
||||
return Collections2.filter(changeMessages,
|
||||
new Predicate<ChangeMessage>() {
|
||||
@Override
|
||||
public boolean apply(ChangeMessage in) {
|
||||
PatchSet.Id psId = in.getPatchSetId();
|
||||
return Collections2.filter(changeMessages, m -> {
|
||||
PatchSet.Id psId = m.getPatchSetId();
|
||||
if (psId == null) {
|
||||
return true;
|
||||
}
|
||||
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.gerrit.reviewdb.client.RefNames.changeMetaRef;
|
||||
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.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -70,7 +70,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -84,22 +83,10 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ChangeNotes.class);
|
||||
|
||||
static final Ordering<PatchSetApproval> PSA_BY_TIME =
|
||||
Ordering.natural().onResultOf(
|
||||
new Function<PatchSetApproval, Timestamp>() {
|
||||
@Override
|
||||
public Timestamp apply(PatchSetApproval input) {
|
||||
return input.getGranted();
|
||||
}
|
||||
});
|
||||
Ordering.from(comparing(PatchSetApproval::getGranted));
|
||||
|
||||
public static final Ordering<ChangeMessage> MESSAGE_BY_TIME =
|
||||
Ordering.natural().onResultOf(
|
||||
new Function<ChangeMessage, Timestamp>() {
|
||||
@Override
|
||||
public Timestamp apply(ChangeMessage input) {
|
||||
return input.getWrittenOn();
|
||||
}
|
||||
});
|
||||
Ordering.from(comparing(ChangeMessage::getWrittenOn));
|
||||
|
||||
public static ConfigInvalidException parseException(Change.Id changeId,
|
||||
String fmt, Object... args) {
|
||||
|
@ -29,11 +29,11 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMITTED_WI
|
||||
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.NoteDbTable.CHANGES;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
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.Splitter;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@ -60,7 +60,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.ReviewerStatusUpdate;
|
||||
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||
@ -165,7 +164,7 @@ class ChangeNotesParser {
|
||||
allChangeMessages = new ArrayList<>();
|
||||
changeMessagesByPatchSet = LinkedListMultimap.create();
|
||||
comments = ArrayListMultimap.create();
|
||||
patchSets = Maps.newTreeMap(ReviewDbUtil.intKeyOrdering());
|
||||
patchSets = Maps.newTreeMap(comparing(PatchSet.Id::get));
|
||||
deletedPatchSets = new HashSet<>();
|
||||
patchSetStates = new HashMap<>();
|
||||
}
|
||||
@ -883,13 +882,8 @@ class ChangeNotesParser {
|
||||
missing.add(FOOTER_SUBJECT);
|
||||
}
|
||||
if (!missing.isEmpty()) {
|
||||
throw parseException("Missing footers: " + Joiner.on(", ")
|
||||
.join(Lists.transform(missing, new Function<FooterKey, String>() {
|
||||
@Override
|
||||
public String apply(FooterKey input) {
|
||||
return input.getName();
|
||||
}
|
||||
})));
|
||||
throw parseException("Missing footers: "
|
||||
+ missing.stream().map(FooterKey::getName).collect(joining(", ")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.notedb;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Strings;
|
||||
@ -33,7 +34,6 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.ReviewerStatusUpdate;
|
||||
|
||||
@ -115,7 +115,7 @@ public abstract class ChangeNotesState {
|
||||
status),
|
||||
assignee,
|
||||
ImmutableSet.copyOf(hashtags),
|
||||
ImmutableSortedMap.copyOf(patchSets, ReviewDbUtil.intKeyOrdering()),
|
||||
ImmutableSortedMap.copyOf(patchSets, comparing(PatchSet.Id::get)),
|
||||
ImmutableListMultimap.copyOf(approvals),
|
||||
reviewers,
|
||||
ImmutableList.copyOf(allPastReviewers),
|
||||
|
@ -33,6 +33,7 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMISSION_I
|
||||
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMITTED_WITH;
|
||||
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TAG;
|
||||
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@ -49,7 +50,6 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
@ -57,6 +57,7 @@ import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.util.LabelVote;
|
||||
import com.google.gerrit.server.util.RequestId;
|
||||
import com.google.gwtorm.client.IntKey;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
@ -175,7 +176,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
|
||||
private static Table<String, Account.Id, Optional<Short>> approvals(
|
||||
Comparator<String> nameComparator) {
|
||||
return TreeBasedTable.create(nameComparator, ReviewDbUtil.intKeyOrdering());
|
||||
return TreeBasedTable.create(nameComparator, comparing(IntKey::get));
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
|
@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.refsDraftComments;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@ -30,7 +31,6 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.git.RefCache;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@ -163,7 +163,7 @@ public class NoteDbChangeState {
|
||||
public static String toString(ObjectId changeMetaId,
|
||||
Map<Account.Id, ObjectId> draftIds) {
|
||||
List<Account.Id> accountIds = Lists.newArrayList(draftIds.keySet());
|
||||
Collections.sort(accountIds, ReviewDbUtil.intKeyOrdering());
|
||||
Collections.sort(accountIds, comparing(Account.Id::get));
|
||||
StringBuilder sb = new StringBuilder(changeMetaId.name());
|
||||
for (Account.Id id : accountIds) {
|
||||
sb.append(',')
|
||||
|
@ -17,10 +17,9 @@ package com.google.gerrit.server.notedb;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.gerrit.server.PatchLineCommentsUtil.PLC_ORDER;
|
||||
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.FluentIterable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
@ -134,13 +133,10 @@ class RevisionNoteBuilder {
|
||||
}
|
||||
|
||||
RevisionNoteData data = new RevisionNoteData();
|
||||
data.comments = FluentIterable.from(PLC_ORDER.sortedCopy(comments.values()))
|
||||
.transform(new Function<PatchLineComment, RevisionNoteData.Comment>() {
|
||||
@Override
|
||||
public RevisionNoteData.Comment apply(PatchLineComment plc) {
|
||||
return new RevisionNoteData.Comment(plc, noteUtil.getServerId());
|
||||
}
|
||||
}).toList();
|
||||
data.comments = comments.values().stream()
|
||||
.sorted(PLC_ORDER)
|
||||
.map(plc -> new RevisionNoteData.Comment(plc, noteUtil.getServerId()))
|
||||
.collect(toList());
|
||||
data.pushCert = pushCert;
|
||||
|
||||
try (OutputStreamWriter osw = new OutputStreamWriter(out)) {
|
||||
|
@ -14,9 +14,9 @@
|
||||
|
||||
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.Lists;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
@ -134,15 +134,15 @@ class RevisionNoteData {
|
||||
List<Comment> comments;
|
||||
|
||||
ImmutableList<PatchLineComment> exportComments(
|
||||
final PatchLineComment.Status status) {
|
||||
PatchLineComment.Status status) {
|
||||
return ImmutableList.copyOf(
|
||||
Lists.transform(comments, new Function<Comment, PatchLineComment>() {
|
||||
@Override
|
||||
public PatchLineComment apply(Comment c) {
|
||||
comments.stream()
|
||||
.map(
|
||||
c -> {
|
||||
PatchLineComment plc = c.export();
|
||||
plc.setStatus(status);
|
||||
return plc;
|
||||
}
|
||||
}));
|
||||
})
|
||||
.collect(toList()));
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,12 @@
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
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 com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
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.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PatchListLoader implements Callable<PatchList> {
|
||||
static final Logger log = LoggerFactory.getLogger(PatchListLoader.class);
|
||||
@ -179,16 +180,11 @@ public class PatchListLoader implements Callable<PatchList> {
|
||||
key.getNewId(), key.getWhitespace());
|
||||
PatchListKey oldKey = PatchListKey.againstDefaultBase(
|
||||
key.getOldId(), key.getWhitespace());
|
||||
paths = FluentIterable
|
||||
.from(patchListCache.get(newKey, project).getPatches())
|
||||
.append(patchListCache.get(oldKey, project).getPatches())
|
||||
.transform(new Function<PatchListEntry, String>() {
|
||||
@Override
|
||||
public String apply(PatchListEntry entry) {
|
||||
return entry.getNewName();
|
||||
}
|
||||
})
|
||||
.toSet();
|
||||
paths = Stream.concat(
|
||||
patchListCache.get(newKey, project).getPatches().stream(),
|
||||
patchListCache.get(oldKey, project).getPatches().stream())
|
||||
.map(PatchListEntry::getNewName)
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
int cnt = diffEntries.size();
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.errors.PermissionDeniedException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
@ -91,14 +90,7 @@ public class BanCommit implements RestModifyView<ProjectResource, Input> {
|
||||
if (commits == null || commits.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Lists.transform(commits,
|
||||
new Function<ObjectId, String>() {
|
||||
@Override
|
||||
public String apply(ObjectId id) {
|
||||
return id.getName();
|
||||
}
|
||||
});
|
||||
return Lists.transform(commits, ObjectId::getName);
|
||||
}
|
||||
|
||||
public static class BanResultInfo {
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
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>() {
|
||||
@Override
|
||||
public ReflogEntryInfo apply(ReflogEntry e) {
|
||||
return new ReflogEntryInfo(e);
|
||||
}
|
||||
});
|
||||
return Lists.transform(entries, ReflogEntryInfo::new);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ 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.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -72,6 +71,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** Cached information on a project. */
|
||||
public class ProjectState {
|
||||
@ -378,75 +378,35 @@ public class ProjectState {
|
||||
}
|
||||
|
||||
public boolean isUseContributorAgreements() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getUseContributorAgreements();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getUseContributorAgreements);
|
||||
}
|
||||
|
||||
public boolean isUseContentMerge() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getUseContentMerge();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getUseContentMerge);
|
||||
}
|
||||
|
||||
public boolean isUseSignedOffBy() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getUseSignedOffBy();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getUseSignedOffBy);
|
||||
}
|
||||
|
||||
public boolean isRequireChangeID() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getRequireChangeID();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getRequireChangeID);
|
||||
}
|
||||
|
||||
public boolean isCreateNewChangeForAllNotInTarget() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getCreateNewChangeForAllNotInTarget();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getCreateNewChangeForAllNotInTarget);
|
||||
}
|
||||
|
||||
public boolean isEnableSignedPush() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getEnableSignedPush();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getEnableSignedPush);
|
||||
}
|
||||
|
||||
public boolean isRequireSignedPush() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getRequireSignedPush();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getRequireSignedPush);
|
||||
}
|
||||
|
||||
public boolean isRejectImplicitMerges() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
public InheritableBoolean apply(Project input) {
|
||||
return input.getRejectImplicitMerges();
|
||||
}
|
||||
});
|
||||
return getInheritableBoolean(Project::getRejectImplicitMerges);
|
||||
}
|
||||
|
||||
public LabelTypes getLabelTypes() {
|
||||
@ -551,7 +511,8 @@ public class ProjectState {
|
||||
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()) {
|
||||
switch (func.apply(s.getProject())) {
|
||||
case TRUE:
|
||||
|
@ -16,7 +16,6 @@ package com.google.gerrit.server.query;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -157,12 +156,7 @@ public class AndSource<T> extends AndPredicate<T>
|
||||
|
||||
private Iterable<T> buffer(ResultSet<T> scanner) {
|
||||
return FluentIterable.from(Iterables.partition(scanner, 50))
|
||||
.transformAndConcat(new Function<List<T>, List<T>>() {
|
||||
@Override
|
||||
public List<T> apply(List<T> buffer) {
|
||||
return transformBuffer(buffer);
|
||||
}
|
||||
});
|
||||
.transformAndConcat(this::transformBuffer);
|
||||
}
|
||||
|
||||
protected List<T> transformBuffer(List<T> buffer) throws OrmRuntimeException {
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.query.account;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
@ -124,13 +123,9 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState> {
|
||||
|
||||
public Predicate<AccountState> defaultQuery(String query) {
|
||||
return Predicate.and(
|
||||
Lists.transform(Splitter.on(' ').omitEmptyStrings().splitToList(query),
|
||||
new Function<String, Predicate<AccountState>>() {
|
||||
@Override
|
||||
public Predicate<AccountState> apply(String s) {
|
||||
return defaultField(s);
|
||||
}
|
||||
}));
|
||||
Lists.transform(
|
||||
Splitter.on(' ').omitEmptyStrings().splitToList(query),
|
||||
this::defaultField));
|
||||
}
|
||||
|
||||
@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.server.query.change.ChangeData.asChanges;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
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.gerrit.common.data.GroupReference;
|
||||
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.reviewdb.client.Account;
|
||||
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
|
||||
if (group != null) {
|
||||
Set<Account.Id> allMembers =
|
||||
new HashSet<>(Lists.transform(
|
||||
args.listMembers.get().setRecursive(true).apply(group),
|
||||
new Function<AccountInfo, Account.Id>() {
|
||||
@Override
|
||||
public Account.Id apply(AccountInfo accountInfo) {
|
||||
return new Account.Id(accountInfo._accountId);
|
||||
}
|
||||
}));
|
||||
args.listMembers.get().setRecursive(true).apply(group).stream()
|
||||
.map(a -> new Account.Id(a._accountId))
|
||||
.collect(toSet());
|
||||
int maxLimit = args.indexConfig.maxLimit();
|
||||
if (allMembers.size() > maxLimit) {
|
||||
// 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 com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
@ -191,20 +190,14 @@ public class InternalChangeQuery extends InternalQuery<ChangeData> {
|
||||
}
|
||||
}
|
||||
|
||||
return Lists.transform(notesFactory.create(db, branch.getParentKey(),
|
||||
changeIds, new com.google.common.base.Predicate<ChangeNotes>() {
|
||||
@Override
|
||||
public boolean apply(ChangeNotes notes) {
|
||||
Change c = notes.getChange();
|
||||
List<ChangeNotes> notes = notesFactory.create(
|
||||
db, branch.getParentKey(), changeIds,
|
||||
cn -> {
|
||||
Change c = cn.getChange();
|
||||
return c.getDest().equals(branch)
|
||||
&& 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(
|
||||
|
@ -15,9 +15,8 @@
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
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.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
@ -67,18 +66,16 @@ public class ProjectConfigSchemaUpdate extends VersionedMetaData {
|
||||
Set<String> names = config.getNames(ACCESS, subsection);
|
||||
if (names.contains(name)) {
|
||||
List<String> values =
|
||||
Arrays.asList(config.getStringList(ACCESS, subsection, name));
|
||||
values = Lists.transform(values, new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String ruleString) {
|
||||
PermissionRule rule = PermissionRule.fromString(ruleString, false);
|
||||
Arrays.stream(config.getStringList(ACCESS, subsection, name))
|
||||
.map(r -> {
|
||||
PermissionRule rule = PermissionRule.fromString(r, false);
|
||||
if (rule.getForce()) {
|
||||
rule.setForce(false);
|
||||
updated = true;
|
||||
}
|
||||
return rule.asString(false);
|
||||
}
|
||||
});
|
||||
})
|
||||
.collect(toList());
|
||||
config.setStringList(ACCESS, subsection, name, values);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
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.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
@ -124,13 +125,7 @@ public class Schema_124 extends SchemaVersion {
|
||||
|
||||
private Collection<AccountSshKey> fixInvalidSequenceNumbers(
|
||||
Collection<AccountSshKey> keys) {
|
||||
Ordering<AccountSshKey> o =
|
||||
Ordering.natural().onResultOf(new Function<AccountSshKey, Integer>() {
|
||||
@Override
|
||||
public Integer apply(AccountSshKey sshKey) {
|
||||
return sshKey.getKey().get();
|
||||
}
|
||||
});
|
||||
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
|
||||
List<AccountSshKey> fixedKeys = new ArrayList<>(keys);
|
||||
AccountSshKey minKey = o.min(keys);
|
||||
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.junit.Assert.fail;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.ListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
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.PatchSetApproval;
|
||||
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.ReviewerSet;
|
||||
import com.google.gerrit.server.config.GerritServerId;
|
||||
@ -381,13 +380,9 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<PatchSetApproval> approvals = Ordering.natural().onResultOf(
|
||||
new Function<PatchSetApproval, Integer>() {
|
||||
@Override
|
||||
public Integer apply(PatchSetApproval in) {
|
||||
return in.getAccountId().get();
|
||||
}
|
||||
}).sortedCopy(notes.getApprovals().get(c.currentPatchSetId()));
|
||||
List<PatchSetApproval> approvals = ReviewDbUtil.intKeyOrdering()
|
||||
.onResultOf(PatchSetApproval::getAccountId)
|
||||
.sortedCopy(notes.getApprovals().get(c.currentPatchSetId()));
|
||||
assertThat(approvals).hasSize(2);
|
||||
|
||||
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 org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
@ -476,22 +475,10 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(AccountInfo... accounts) {
|
||||
return FluentIterable.from(Arrays.asList(accounts)).transform(
|
||||
new Function<AccountInfo, Integer>() {
|
||||
@Override
|
||||
public Integer apply(AccountInfo in) {
|
||||
return in._accountId;
|
||||
}
|
||||
});
|
||||
return FluentIterable.of(accounts).transform(a -> a._accountId);
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(Iterable<AccountInfo> accounts) {
|
||||
return FluentIterable.from(accounts).transform(
|
||||
new Function<AccountInfo, Integer>() {
|
||||
@Override
|
||||
public Integer apply(AccountInfo in) {
|
||||
return in._accountId;
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(accounts).transform(a -> a._accountId);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -1437,13 +1436,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
for (int i = 1; i <= 11; i++) {
|
||||
Iterable<ChangeData> cds = internalChangeQuery.byCommitsOnBranchNotMerged(
|
||||
repo.getRepository(), db, dest, shas, i);
|
||||
Iterable<Integer> ids = FluentIterable.from(cds).transform(
|
||||
new Function<ChangeData, Integer>() {
|
||||
@Override
|
||||
public Integer apply(ChangeData in) {
|
||||
return in.getId().get();
|
||||
}
|
||||
});
|
||||
Iterable<Integer> ids = FluentIterable.from(cds)
|
||||
.transform(in -> in.getId().get());
|
||||
String name = "limit " + i;
|
||||
assertThat(ids).named(name).hasSize(n);
|
||||
assertThat(ids).named(name)
|
||||
@ -1640,24 +1634,22 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("query '").append(query.getQuery())
|
||||
.append("' with expected changes ");
|
||||
b.append(format(Iterables.transform(Arrays.asList(expectedChanges),
|
||||
new Function<Change, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Change change) {
|
||||
return change.getChangeId();
|
||||
}
|
||||
})));
|
||||
b.append(format(
|
||||
Arrays.stream(expectedChanges).map(Change::getChangeId).iterator()));
|
||||
b.append(" and result ");
|
||||
b.append(format(actualIds));
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private String format(Iterable<Integer> changeIds) throws RestApiException {
|
||||
return format(changeIds.iterator());
|
||||
}
|
||||
|
||||
private String format(Iterator<Integer> changeIds) throws RestApiException {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("[");
|
||||
Iterator<Integer> it = changeIds.iterator();
|
||||
while (it.hasNext()) {
|
||||
int id = it.next();
|
||||
while (changeIds.hasNext()) {
|
||||
int id = changeIds.next();
|
||||
ChangeInfo c = gApi.changes().id(id).get();
|
||||
b.append("{").append(id).append(" (").append(c.changeId)
|
||||
.append("), ").append("dest=").append(
|
||||
@ -1666,7 +1658,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
.append("status=").append(c.status).append(", ")
|
||||
.append("lastUpdated=").append(c.updated.getTime())
|
||||
.append("}");
|
||||
if (it.hasNext()) {
|
||||
if (changeIds.hasNext()) {
|
||||
b.append(", ");
|
||||
}
|
||||
}
|
||||
@ -1675,23 +1667,13 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(Change... changes) {
|
||||
return FluentIterable.from(Arrays.asList(changes)).transform(
|
||||
new Function<Change, Integer>() {
|
||||
@Override
|
||||
public Integer apply(Change in) {
|
||||
return in.getId().get();
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(Arrays.asList(changes))
|
||||
.transform(in -> in.getId().get());
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(Iterable<ChangeInfo> changes) {
|
||||
return FluentIterable.from(changes).transform(
|
||||
new Function<ChangeInfo, Integer>() {
|
||||
@Override
|
||||
public Integer apply(ChangeInfo in) {
|
||||
return in._number;
|
||||
}
|
||||
});
|
||||
return FluentIterable.from(changes)
|
||||
.transform(in -> in._number);
|
||||
}
|
||||
|
||||
protected static long lastUpdatedMs(Change c) {
|
||||
|
@ -14,9 +14,9 @@
|
||||
|
||||
package com.google.gerrit.testutil;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
@ -111,17 +111,14 @@ public class FakeEmailSender implements EmailSender {
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableList<Message> getMessages(String changeId, String type) {
|
||||
public List<Message> getMessages(String changeId, String type) {
|
||||
final String idFooter = "\nGerrit-Change-Id: " + changeId + "\n";
|
||||
final String typeFooter = "\nGerrit-MessageType: " + type + "\n";
|
||||
return FluentIterable.from(getMessages())
|
||||
.filter(new Predicate<Message>() {
|
||||
@Override
|
||||
public boolean apply(Message in) {
|
||||
return in.body().contains(idFooter)
|
||||
&& in.body().contains(typeFooter);
|
||||
}
|
||||
}).toList();
|
||||
return getMessages()
|
||||
.stream()
|
||||
.filter(in -> in.body().contains(idFooter)
|
||||
&& in.body().contains(typeFooter))
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
private void waitForEmails() {
|
||||
|
@ -15,9 +15,10 @@
|
||||
package com.google.gerrit.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@ -29,6 +30,9 @@ import com.google.gerrit.server.notedb.ChangeBundle;
|
||||
import com.google.gerrit.server.notedb.ChangeBundleReader;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilder;
|
||||
import com.google.gwtorm.client.IntKey;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.OrmRuntimeException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@ -41,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Singleton
|
||||
public class NoteDbChecker {
|
||||
@ -73,16 +78,14 @@ public class NoteDbChecker {
|
||||
|
||||
public void rebuildAndCheckAllChanges() throws Exception {
|
||||
rebuildAndCheckChanges(
|
||||
Iterables.transform(
|
||||
getUnwrappedDb().changes().all(),
|
||||
ReviewDbUtil.changeIdFunction()));
|
||||
getUnwrappedDb().changes().all().toList().stream().map(Change::getId));
|
||||
}
|
||||
|
||||
public void rebuildAndCheckChanges(Change.Id... changeIds) throws Exception {
|
||||
rebuildAndCheckChanges(Arrays.asList(changeIds));
|
||||
rebuildAndCheckChanges(Arrays.stream(changeIds));
|
||||
}
|
||||
|
||||
public void rebuildAndCheckChanges(Iterable<Change.Id> changeIds)
|
||||
private void rebuildAndCheckChanges(Stream<Change.Id> changeIds)
|
||||
throws Exception {
|
||||
ReviewDb db = getUnwrappedDb();
|
||||
|
||||
@ -111,11 +114,7 @@ public class NoteDbChecker {
|
||||
}
|
||||
|
||||
public void checkChanges(Change.Id... changeIds) throws Exception {
|
||||
checkChanges(Arrays.asList(changeIds));
|
||||
}
|
||||
|
||||
public void checkChanges(Iterable<Change.Id> changeIds) throws Exception {
|
||||
checkActual(readExpected(changeIds), new ArrayList<String>());
|
||||
checkActual(readExpected(Arrays.stream(changeIds)), new ArrayList<>());
|
||||
}
|
||||
|
||||
public void assertNoChangeRef(Project.NameKey project, Change.Id changeId)
|
||||
@ -125,24 +124,26 @@ public class NoteDbChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private List<ChangeBundle> readExpected(Iterable<Change.Id> changeIds)
|
||||
private List<ChangeBundle> readExpected(Stream<Change.Id> changeIds)
|
||||
throws Exception {
|
||||
ReviewDb db = getUnwrappedDb();
|
||||
boolean old = notesMigration.readChanges();
|
||||
try {
|
||||
notesMigration.setReadChanges(false);
|
||||
List<Change.Id> sortedIds =
|
||||
ReviewDbUtil.intKeyOrdering().sortedCopy(changeIds);
|
||||
List<ChangeBundle> expected = new ArrayList<>(sortedIds.size());
|
||||
for (Change.Id id : sortedIds) {
|
||||
expected.add(bundleReader.fromReviewDb(db, id));
|
||||
}
|
||||
return expected;
|
||||
return changeIds.sorted(comparing(IntKey::get))
|
||||
.map(this::readBundleUnchecked).collect(toList());
|
||||
} finally {
|
||||
notesMigration.setReadChanges(old);
|
||||
}
|
||||
}
|
||||
|
||||
private ChangeBundle readBundleUnchecked(Change.Id id) {
|
||||
try {
|
||||
return bundleReader.fromReviewDb(getUnwrappedDb(), id);
|
||||
} catch (OrmException e) {
|
||||
throw new OrmRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkActual(List<ChangeBundle> allExpected, List<String> msgs)
|
||||
throws Exception {
|
||||
ReviewDb db = getUnwrappedDb();
|
||||
|
Loading…
Reference in New Issue
Block a user