Skip to content

Commit

Permalink
Replace ComparisonChain with a Comparator chain.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 668477671
  • Loading branch information
eamonnmcmanus authored and Error Prone Team committed Aug 28, 2024
1 parent 7e9a100 commit a5a7189
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.base.Joiner;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;
Expand All @@ -41,15 +39,9 @@ public class Replacements {
* length of the input don't affect the position of earlier replacements.
*/
private static final Comparator<Range<Integer>> DESCENDING =
new Comparator<Range<Integer>>() {
@Override
public int compare(Range<Integer> o1, Range<Integer> o2) {
return ComparisonChain.start()
.compare(o1.lowerEndpoint(), o2.lowerEndpoint(), Ordering.natural().reverse())
.compare(o1.upperEndpoint(), o2.upperEndpoint(), Ordering.natural().reverse())
.result();
}
};
Comparator.<Range<Integer>, Integer>comparing(Range::lowerEndpoint)
.thenComparing(Range::upperEndpoint)
.reversed();

private final TreeMap<Range<Integer>, Replacement> replacements = new TreeMap<>(DESCENDING);
private final RangeMap<Integer, Replacement> overlaps = TreeRangeMap.create();
Expand Down

0 comments on commit a5a7189

Please sign in to comment.