Remove ReviewDbUtil#intKeyOrdering()

None of the callers are subject to the null safety issue described in
the Javadoc. Although it's true that some callers require more code to
use the equivalent stream API, it's still plenty readable. On balance,
it doesn't justify having this gwtorm-specific helper.

Change-Id: Ic5b9dc07566ec9bf20da9a0ac10b9cf95d78386b
This commit is contained in:
Dave Borowitz
2018-12-14 15:07:19 -08:00
parent 4739815537
commit 74c8f429f4
5 changed files with 23 additions and 40 deletions

View File

@@ -15,9 +15,10 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.intKeyOrdering;
import static com.google.gerrit.server.ChangeUtil.PS_ID_ORDER;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
@@ -37,7 +38,6 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.GerritPersonIdent;
@@ -67,6 +67,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@@ -457,7 +458,11 @@ public class ConsistencyChecker {
problem(
String.format(
"Multiple patch sets for expected merged commit %s: %s",
commit.name(), intKeyOrdering().sortedCopy(thisCommitPsIds)));
commit.name(),
thisCommitPsIds
.stream()
.sorted(comparing(PatchSet.Id::get))
.collect(toImmutableList())));
break;
}
} catch (IOException e) {
@@ -695,7 +700,7 @@ public class ConsistencyChecker {
if (!toDelete.contains(ctx.getChange().currentPatchSetId())) {
return false;
}
Set<PatchSet.Id> all = new HashSet<>();
TreeSet<PatchSet.Id> all = new TreeSet<>(comparing(PatchSet.Id::get));
// Doesn't make any assumptions about the order in which deletes happen
// and whether they are seen by this op; we are already given the full set
// of patch sets that will eventually be deleted in this update.
@@ -707,8 +712,7 @@ public class ConsistencyChecker {
if (all.isEmpty()) {
throw new NoPatchSetsWouldRemainException();
}
PatchSet.Id latest = ReviewDbUtil.intKeyOrdering().max(all);
ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getNotes(), latest));
ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getNotes(), all.last()));
return true;
}
}

View File

@@ -37,6 +37,7 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_WORK_IN_PROGRESS;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.parseCommitMessageRange;
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;
@@ -67,7 +68,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.ReviewerByEmailSet;
import com.google.gerrit.server.ReviewerSet;
import com.google.gerrit.server.ReviewerStatusUpdate;
@@ -1004,7 +1004,7 @@ class ChangeNotesParser {
}
private void updatePatchSetStates() {
Set<PatchSet.Id> missing = new TreeSet<>(ReviewDbUtil.intKeyOrdering());
Set<PatchSet.Id> missing = new TreeSet<>(comparing(PatchSet.Id::get));
for (Iterator<PatchSet> it = patchSets.values().iterator(); it.hasNext(); ) {
PatchSet ps = it.next();
if (ps.getRevision().equals(PARTIAL_PATCH_SET)) {

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.submit;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Function;
@@ -32,7 +33,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.IdentifiedUser;
@@ -182,8 +182,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
continue; // Bogus ref, can't be merged into tip so we don't care.
}
}
commits.sort(
ReviewDbUtil.intKeyOrdering().reverse().onResultOf(CodeReviewCommit::getPatchsetId));
commits.sort(comparing((CodeReviewCommit c) -> c.getPatchsetId().get()).reversed());
CodeReviewCommit result = MergeUtil.findAnyMergedInto(rw, commits, tip);
if (result == null) {
return null;