Convert some Functions/Predicates to streams & lambdas (2)
Change-Id: I6558525ed5df1da588fcf69d177952e4f692cc2d
This commit is contained in:
@@ -19,7 +19,6 @@ import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
|||||||
import static java.util.Comparator.comparing;
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
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;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -89,12 +88,8 @@ public class ApprovalsUtil {
|
|||||||
|
|
||||||
private static Iterable<PatchSetApproval> filterApprovals(
|
private static Iterable<PatchSetApproval> filterApprovals(
|
||||||
Iterable<PatchSetApproval> psas, final Account.Id accountId) {
|
Iterable<PatchSetApproval> psas, final Account.Id accountId) {
|
||||||
return Iterables.filter(psas, new Predicate<PatchSetApproval>() {
|
return Iterables.filter(
|
||||||
@Override
|
psas, a -> Objects.equals(a.getAccountId(), accountId));
|
||||||
public boolean apply(PatchSetApproval input) {
|
|
||||||
return Objects.equals(input.getAccountId(), accountId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final NotesMigration migration;
|
private final NotesMigration migration;
|
||||||
|
|||||||
@@ -16,11 +16,10 @@ package com.google.gerrit.server;
|
|||||||
|
|
||||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.ComparisonChain;
|
import com.google.common.collect.ComparisonChain;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@@ -60,6 +59,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility functions to manipulate PatchLineComments.
|
* Utility functions to manipulate PatchLineComments.
|
||||||
@@ -178,13 +178,7 @@ public class PatchLineCommentsUtil {
|
|||||||
ResultSet<PatchLineComment> comments,
|
ResultSet<PatchLineComment> comments,
|
||||||
final PatchLineComment.Status status) {
|
final PatchLineComment.Status status) {
|
||||||
return Lists.newArrayList(
|
return Lists.newArrayList(
|
||||||
Iterables.filter(comments, new Predicate<PatchLineComment>() {
|
Iterables.filter(comments, c -> c.getStatus() == status));
|
||||||
@Override
|
|
||||||
public boolean apply(PatchLineComment input) {
|
|
||||||
return (input.getStatus() == status);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PatchLineComment> byPatchSet(ReviewDb db,
|
public List<PatchLineComment> byPatchSet(ReviewDb db,
|
||||||
@@ -251,16 +245,11 @@ public class PatchLineCommentsUtil {
|
|||||||
throws OrmException {
|
throws OrmException {
|
||||||
if (!migration.readChanges()) {
|
if (!migration.readChanges()) {
|
||||||
final Change.Id matchId = notes.getChangeId();
|
final Change.Id matchId = notes.getChangeId();
|
||||||
return FluentIterable
|
return StreamSupport.stream(
|
||||||
.from(db.patchComments().draftByAuthor(author))
|
db.patchComments().draftByAuthor(author).spliterator(), false)
|
||||||
.filter(new Predicate<PatchLineComment>() {
|
.filter(c -> c.getPatchSetId().getParentKey().equals(matchId))
|
||||||
@Override
|
.sorted(PLC_ORDER)
|
||||||
public boolean apply(PatchLineComment in) {
|
.collect(toList());
|
||||||
Change.Id changeId =
|
|
||||||
in.getKey().getParentKey().getParentKey().getParentKey();
|
|
||||||
return changeId.equals(matchId);
|
|
||||||
}
|
|
||||||
}).toSortedList(PLC_ORDER);
|
|
||||||
}
|
}
|
||||||
List<PatchLineComment> comments = new ArrayList<>();
|
List<PatchLineComment> comments = new ArrayList<>();
|
||||||
comments.addAll(notes.getDraftComments(author).values());
|
comments.addAll(notes.getDraftComments(author).values());
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import static java.util.stream.Collectors.toSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.gerrit.common.data.PermissionRule;
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
@@ -28,7 +28,6 @@ import com.google.gerrit.server.project.ProjectCache;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/** Access control management for one account's access to other accounts. */
|
/** Access control management for one account's access to other accounts. */
|
||||||
@@ -186,14 +185,9 @@ public class AccountControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<AccountGroup.UUID> groupsOf(IdentifiedUser user) {
|
private Set<AccountGroup.UUID> groupsOf(IdentifiedUser user) {
|
||||||
return new HashSet<>(Sets.filter(
|
return user.getEffectiveGroups().getKnownGroups().stream()
|
||||||
user.getEffectiveGroups().getKnownGroups(),
|
.filter(a -> !SystemGroupBackend.isSystemGroup(a))
|
||||||
new Predicate<AccountGroup.UUID>() {
|
.collect(toSet());
|
||||||
@Override
|
|
||||||
public boolean apply(AccountGroup.UUID in) {
|
|
||||||
return !SystemGroupBackend.isSystemGroup(in);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract static class OtherUser {
|
private abstract static class OtherUser {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.index;
|
|||||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
|
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
|
||||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableCollection;
|
import com.google.common.collect.ImmutableCollection;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -110,19 +109,11 @@ public class IndexModule extends LifecycleModule {
|
|||||||
accounts,
|
accounts,
|
||||||
changes);
|
changes);
|
||||||
Set<String> expected = FluentIterable.from(ALL_SCHEMA_DEFS)
|
Set<String> expected = FluentIterable.from(ALL_SCHEMA_DEFS)
|
||||||
.transform(new Function<SchemaDefinitions<?>, String>() {
|
.transform(SchemaDefinitions::getName)
|
||||||
@Override
|
.toSet();
|
||||||
public String apply(SchemaDefinitions<?> in) {
|
|
||||||
return in.getName();
|
|
||||||
}
|
|
||||||
}).toSet();
|
|
||||||
Set<String> actual = FluentIterable.from(result)
|
Set<String> actual = FluentIterable.from(result)
|
||||||
.transform(new Function<IndexDefinition<?, ?, ?>, String>() {
|
.transform(IndexDefinition::getName)
|
||||||
@Override
|
.toSet();
|
||||||
public String apply(IndexDefinition<?, ?, ?> in) {
|
|
||||||
return in.getName();
|
|
||||||
}
|
|
||||||
}).toSet();
|
|
||||||
if (!expected.equals(actual)) {
|
if (!expected.equals(actual)) {
|
||||||
throw new ProvisionException(
|
throw new ProvisionException(
|
||||||
"need index definitions for all schemas: "
|
"need index definitions for all schemas: "
|
||||||
|
|||||||
@@ -14,14 +14,12 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.index.account;
|
package com.google.gerrit.server.index.account;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
|
|
||||||
import com.google.gerrit.server.index.FieldDef;
|
import com.google.gerrit.server.index.FieldDef;
|
||||||
import com.google.gerrit.server.index.FieldType;
|
import com.google.gerrit.server.index.FieldType;
|
||||||
import com.google.gerrit.server.index.SchemaUtil;
|
import com.google.gerrit.server.index.SchemaUtil;
|
||||||
@@ -47,13 +45,7 @@ public class AccountField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<String> get(AccountState input, FillArgs args) {
|
public Iterable<String> get(AccountState input, FillArgs args) {
|
||||||
return Iterables.transform(
|
return Iterables.transform(
|
||||||
input.getExternalIds(),
|
input.getExternalIds(), id -> id.getKey().get());
|
||||||
new Function<AccountExternalId, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(AccountExternalId in) {
|
|
||||||
return in.getKey().get();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,12 +60,7 @@ public class AccountField {
|
|||||||
fullName,
|
fullName,
|
||||||
Iterables.transform(
|
Iterables.transform(
|
||||||
input.getExternalIds(),
|
input.getExternalIds(),
|
||||||
new Function<AccountExternalId, String>() {
|
AccountExternalId::getEmailAddress));
|
||||||
@Override
|
|
||||||
public String apply(AccountExternalId in) {
|
|
||||||
return in.getEmailAddress();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Additional values not currently added by getPersonParts.
|
// Additional values not currently added by getPersonParts.
|
||||||
// TODO(dborowitz): Move to getPersonParts and remove this hack.
|
// TODO(dborowitz): Move to getPersonParts and remove this hack.
|
||||||
@@ -108,23 +95,11 @@ public class AccountField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<String> get(AccountState input, FillArgs args) {
|
public Iterable<String> get(AccountState input, FillArgs args) {
|
||||||
return FluentIterable.from(input.getExternalIds())
|
return FluentIterable.from(input.getExternalIds())
|
||||||
.transform(
|
.transform(AccountExternalId::getEmailAddress)
|
||||||
new Function<AccountExternalId, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(AccountExternalId in) {
|
|
||||||
return in.getEmailAddress();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.append(
|
.append(
|
||||||
Collections.singleton(input.getAccount().getPreferredEmail()))
|
Collections.singleton(input.getAccount().getPreferredEmail()))
|
||||||
.filter(Predicates.notNull())
|
.filter(Predicates.notNull())
|
||||||
.transform(
|
.transform(String::toLowerCase)
|
||||||
new Function<String, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(String in) {
|
|
||||||
return in.toLowerCase();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toSet();
|
.toSet();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -153,12 +128,8 @@ public class AccountField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<String> get(AccountState input, FillArgs args) {
|
public Iterable<String> get(AccountState input, FillArgs args) {
|
||||||
return FluentIterable.from(input.getProjectWatches().keySet())
|
return FluentIterable.from(input.getProjectWatches().keySet())
|
||||||
.transform(new Function<ProjectWatchKey, String>() {
|
.transform(k -> k.project().get())
|
||||||
@Override
|
.toSet();
|
||||||
public String apply(ProjectWatchKey in) {
|
|
||||||
return in.project().get();
|
|
||||||
}
|
|
||||||
}).toSet();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,11 @@
|
|||||||
package com.google.gerrit.server.index.change;
|
package com.google.gerrit.server.index.change;
|
||||||
|
|
||||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
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.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -246,13 +247,9 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<String> get(ChangeData input, FillArgs args)
|
public Iterable<String> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return ImmutableSet.copyOf(Iterables.transform(input.hashtags(),
|
return input.hashtags().stream()
|
||||||
new Function<String, String>() {
|
.map(String::toLowerCase)
|
||||||
@Override
|
.collect(toSet());
|
||||||
public String apply(String input) {
|
|
||||||
return input.toLowerCase();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -263,13 +260,9 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<byte[]> get(ChangeData input, FillArgs args)
|
public Iterable<byte[]> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return ImmutableSet.copyOf(Iterables.transform(input.hashtags(),
|
return input.hashtags().stream()
|
||||||
new Function<String, byte[]>() {
|
.map(t -> t.getBytes(UTF_8))
|
||||||
@Override
|
.collect(toSet());
|
||||||
public byte[] apply(String hashtag) {
|
|
||||||
return hashtag.getBytes(UTF_8);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -656,13 +649,7 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return Iterables.transform(input.starredBy(),
|
return Iterables.transform(input.starredBy(), Account.Id::get);
|
||||||
new Function<Account.Id, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(Account.Id accountId) {
|
|
||||||
return accountId.get();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -675,13 +662,11 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<String> get(ChangeData input, FillArgs args)
|
public Iterable<String> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return Iterables.transform(input.stars().entries(),
|
return Iterables.transform(
|
||||||
new Function<Map.Entry<Account.Id, String>, String>() {
|
input.stars().entries(),
|
||||||
@Override
|
(Map.Entry<Account.Id, String> e) -> {
|
||||||
public String apply(Map.Entry<Account.Id, String> e) {
|
|
||||||
return StarredChangesUtil.StarField.create(
|
return StarredChangesUtil.StarField.create(
|
||||||
e.getKey(), e.getValue()).toString();
|
e.getKey(), e.getValue()).toString();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -738,13 +723,9 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return ImmutableSet.copyOf(Iterables.transform(input.editsByUser(),
|
return input.editsByUser().stream()
|
||||||
new Function<Account.Id, Integer>() {
|
.map(Account.Id::get)
|
||||||
@Override
|
.collect(toSet());
|
||||||
public Integer apply(Account.Id account) {
|
|
||||||
return account.get();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -756,13 +737,9 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
public Iterable<Integer> get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
return ImmutableSet.copyOf(Iterables.transform(input.draftsByUser(),
|
return input.draftsByUser().stream()
|
||||||
new Function<Account.Id, Integer>() {
|
.map(Account.Id::get)
|
||||||
@Override
|
.collect(toSet());
|
||||||
public Integer apply(Account.Id account) {
|
|
||||||
return account.get();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import static com.google.gerrit.server.index.change.ChangeField.CHANGE;
|
|||||||
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
@@ -94,12 +93,9 @@ public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData>
|
|||||||
public Iterator<ChangeData> iterator() {
|
public Iterator<ChangeData> iterator() {
|
||||||
return Iterables.transform(
|
return Iterables.transform(
|
||||||
rs,
|
rs,
|
||||||
new Function<ChangeData, ChangeData>() {
|
cd -> {
|
||||||
@Override
|
|
||||||
public ChangeData apply(ChangeData cd) {
|
|
||||||
fromSource.put(cd, currSource);
|
fromSource.put(cd, currSource);
|
||||||
return cd;
|
return cd;
|
||||||
}
|
|
||||||
}).iterator();
|
}).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -383,13 +383,8 @@ public class ChangeBundle {
|
|||||||
if (current == null) {
|
if (current == null) {
|
||||||
return Predicates.alwaysFalse();
|
return Predicates.alwaysFalse();
|
||||||
}
|
}
|
||||||
final int max = current.get();
|
int max = current.get();
|
||||||
return new Predicate<PatchSet.Id>() {
|
return p -> p.get() <= max;
|
||||||
@Override
|
|
||||||
public boolean apply(PatchSet.Id in) {
|
|
||||||
return in.get() <= max;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<PatchSet.Id, PatchSet> filterPatchSets() {
|
private Map<PatchSet.Id, PatchSet> filterPatchSets() {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
|
|||||||
import static java.util.Comparator.comparing;
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
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;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
@@ -77,6 +76,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/** View of a single {@link Change} based on the log of its notes branch. */
|
/** View of a single {@link Change} based on the log of its notes branch. */
|
||||||
public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||||
@@ -236,7 +236,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
if (args.migration.enabled()) {
|
if (args.migration.enabled()) {
|
||||||
for (Change.Id cid : changeIds) {
|
for (Change.Id cid : changeIds) {
|
||||||
ChangeNotes cn = create(db, project, cid);
|
ChangeNotes cn = create(db, project, cid);
|
||||||
if (cn.getChange() != null && predicate.apply(cn)) {
|
if (cn.getChange() != null && predicate.test(cn)) {
|
||||||
notes.add(cn);
|
notes.add(cn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +246,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
for (Change c : ReviewDbUtil.unwrapDb(db).changes().get(changeIds)) {
|
for (Change c : ReviewDbUtil.unwrapDb(db).changes().get(changeIds)) {
|
||||||
if (c != null && project.equals(c.getDest().getParentKey())) {
|
if (c != null && project.equals(c.getDest().getParentKey())) {
|
||||||
ChangeNotes cn = createFromChangeOnlyWhenNoteDbDisabled(c);
|
ChangeNotes cn = createFromChangeOnlyWhenNoteDbDisabled(c);
|
||||||
if (predicate.apply(cn)) {
|
if (predicate.test(cn)) {
|
||||||
notes.add(cn);
|
notes.add(cn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
try (Repository repo = args.repoManager.openRepository(project)) {
|
try (Repository repo = args.repoManager.openRepository(project)) {
|
||||||
List<ChangeNotes> changes = scanNoteDb(repo, db, project);
|
List<ChangeNotes> changes = scanNoteDb(repo, db, project);
|
||||||
for (ChangeNotes cn : changes) {
|
for (ChangeNotes cn : changes) {
|
||||||
if (predicate.apply(cn)) {
|
if (predicate.test(cn)) {
|
||||||
m.put(project, cn);
|
m.put(project, cn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
} else {
|
} else {
|
||||||
for (Change change : ReviewDbUtil.unwrapDb(db).changes().all()) {
|
for (Change change : ReviewDbUtil.unwrapDb(db).changes().all()) {
|
||||||
ChangeNotes notes = createFromChangeOnlyWhenNoteDbDisabled(change);
|
ChangeNotes notes = createFromChangeOnlyWhenNoteDbDisabled(change);
|
||||||
if (predicate.apply(notes)) {
|
if (predicate.test(notes)) {
|
||||||
m.put(change.getProject(), notes);
|
m.put(change.getProject(), notes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,16 +445,13 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
// failed.
|
// failed.
|
||||||
Multimap<RevId, PatchLineComment> filtered = Multimaps.filterEntries(
|
Multimap<RevId, PatchLineComment> filtered = Multimaps.filterEntries(
|
||||||
draftCommentNotes.getComments(),
|
draftCommentNotes.getComments(),
|
||||||
new Predicate<Map.Entry<RevId, PatchLineComment>>() {
|
(Map.Entry<RevId, PatchLineComment> e) -> {
|
||||||
@Override
|
for (PatchLineComment c : published.get(e.getKey())) {
|
||||||
public boolean apply(Map.Entry<RevId, PatchLineComment> in) {
|
if (c.getKey().equals(e.getValue().getKey())) {
|
||||||
for (PatchLineComment c : published.get(in.getKey())) {
|
|
||||||
if (c.getKey().equals(in.getValue().getKey())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return ImmutableListMultimap.copyOf(
|
return ImmutableListMultimap.copyOf(
|
||||||
filtered);
|
filtered);
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ 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.ChangeNoteUtil.FOOTER_HASHTAGS;
|
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_HASHTAGS;
|
||||||
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET;
|
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
@@ -391,13 +391,10 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
|
|
||||||
private static List<PatchLineComment> getPatchLineComments(ChangeBundle bundle,
|
private static List<PatchLineComment> getPatchLineComments(ChangeBundle bundle,
|
||||||
final PatchSet ps) {
|
final PatchSet ps) {
|
||||||
return FluentIterable.from(bundle.getPatchLineComments())
|
return bundle.getPatchLineComments().stream()
|
||||||
.filter(new Predicate<PatchLineComment>() {
|
.filter(c -> c.getPatchSetId().equals(ps.getId()))
|
||||||
@Override
|
.sorted(PatchLineCommentsUtil.PLC_ORDER)
|
||||||
public boolean apply(PatchLineComment in) {
|
.collect(toList());
|
||||||
return in.getPatchSetId().equals(ps.getId());
|
|
||||||
}
|
|
||||||
}).toSortedList(PatchLineCommentsUtil.PLC_ORDER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortAndFillEvents(Change change, Change noteDbChange,
|
private void sortAndFillEvents(Change change, Change noteDbChange,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.project;
|
|||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -445,13 +444,8 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
|||||||
} else if (matchSubstring != null) {
|
} else if (matchSubstring != null) {
|
||||||
checkMatchOptions(matchPrefix == null && matchRegex == null);
|
checkMatchOptions(matchPrefix == null && matchRegex == null);
|
||||||
return Iterables.filter(projectCache.all(),
|
return Iterables.filter(projectCache.all(),
|
||||||
new Predicate<Project.NameKey>() {
|
p -> p.get().toLowerCase(Locale.US)
|
||||||
@Override
|
.contains(matchSubstring.toLowerCase(Locale.US)));
|
||||||
public boolean apply(Project.NameKey in) {
|
|
||||||
return in.get().toLowerCase(Locale.US)
|
|
||||||
.contains(matchSubstring.toLowerCase(Locale.US));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (matchRegex != null) {
|
} else if (matchRegex != null) {
|
||||||
checkMatchOptions(matchPrefix == null && matchSubstring == null);
|
checkMatchOptions(matchPrefix == null && matchSubstring == null);
|
||||||
RegexListSearcher<Project.NameKey> searcher;
|
RegexListSearcher<Project.NameKey> searcher;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.project;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -124,12 +123,9 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
|||||||
+ " not found");
|
+ " not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Iterables.tryFind(parent.tree(), new Predicate<ProjectState>() {
|
if (Iterables.tryFind(parent.tree(), p -> {
|
||||||
@Override
|
return p.getProject().getNameKey()
|
||||||
public boolean apply(ProjectState input) {
|
|
||||||
return input.getProject().getNameKey()
|
|
||||||
.equals(ctl.getProject().getNameKey());
|
.equals(ctl.getProject().getNameKey());
|
||||||
}
|
|
||||||
}).isPresent()) {
|
}).isPresent()) {
|
||||||
throw new ResourceConflictException("cycle exists between "
|
throw new ResourceConflictException("cycle exists between "
|
||||||
+ ctl.getProject().getName() + " and "
|
+ ctl.getProject().getName() + " and "
|
||||||
|
|||||||
@@ -904,15 +904,12 @@ public class ChangeData {
|
|||||||
* @throws OrmException an error occurred reading the database.
|
* @throws OrmException an error occurred reading the database.
|
||||||
*/
|
*/
|
||||||
public Collection<PatchSet> visiblePatchSets() throws OrmException {
|
public Collection<PatchSet> visiblePatchSets() throws OrmException {
|
||||||
Predicate<PatchSet> predicate = new Predicate<PatchSet>() {
|
Predicate<PatchSet> predicate = ps -> {
|
||||||
@Override
|
|
||||||
public boolean apply(PatchSet input) {
|
|
||||||
try {
|
try {
|
||||||
return changeControl().isPatchVisible(input, db);
|
return changeControl().isPatchVisible(ps, db);
|
||||||
} catch (OrmException e) {
|
} catch (OrmException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return FluentIterable.from(patchSets()).filter(predicate).toList();
|
return FluentIterable.from(patchSets()).filter(predicate).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule plugins/reviewnotes updated: 982292220c...85069a4bd8
Reference in New Issue
Block a user