Unify inline comment comparators

Use the same implementation for the PatchLineComment and CommentInfo
versions, which takes into account more fields. Some differences arose
because they were used in different places under different assumptions
about which fields would vary. Since these are now used in a variety
of places, be more general. Move both to the same location, so it's
easier to see side-by-side that the implementation matches. Use
Ordering so callers can use convenience methods where convenient.

Change-Id: Id855ed5b09b38c45b192459551a3d2c1f4c58b43
This commit is contained in:
Dave Borowitz
2015-05-01 12:59:57 -07:00
parent 23fec2b441
commit b0ef2cd435
5 changed files with 50 additions and 45 deletions

View File

@@ -18,7 +18,6 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.GERRIT_PLACEHOLDER_
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
@@ -51,7 +50,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Comparator;
import java.util.Map;
/** View of a single {@link Change} based on the log of its notes branch. */
@@ -74,20 +72,6 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
}
});
public static Comparator<PatchLineComment> PLC_ORDER =
new Comparator<PatchLineComment>() {
@Override
public int compare(PatchLineComment c1, PatchLineComment c2) {
String filename1 = c1.getKey().getParentKey().get();
String filename2 = c2.getKey().getParentKey().get();
return ComparisonChain.start()
.compare(filename1, filename2)
.compare(c1.getLine(), c2.getLine())
.compare(c1.getWrittenOn(), c2.getWrittenOn())
.result();
}
};
public static ConfigInvalidException parseException(Change.Id changeId,
String fmt, Object... args) {
return new ConfigInvalidException("Change " + changeId + ": "