ComparatorRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$).*as compiler argument.
Table of contents
- NaturalOrder
- ReverseOrder
- ComparatorIdentity
- Comparing
- ComparatorThenComparing
- ComparatorThenComparingReverseOrder
- ComparatorThenComparingWithComparator
- ComparatorThenComparingComparatorReversed
- ComparatorThenComparingDouble
- ComparatorThenComparingInt
- ComparatorThenComparingLong
- ComparatorThenComparingNaturalOrder
- ComparableCompareTo
- CollectionsSort
- CollectionsMin
- CollectionsMinArraysAsList
- CollectionsMinWithComparator
- CollectionsMinArraysAsListVarargs
- ComparatorsMin2
- ComparatorsMin3
- CollectionsMax
- CollectionsMaxArraysAsList
- CollectionsMaxWithComparator
- CollectionsMaxArraysAsListVarargs
- ComparatorsMax2
- ComparatorsMax3
- Least
- Greatest
- LeastNaturalOrder
- GreatestNaturalOrder
- ComparatorsMin0
- ComparatorsMax0
- MinByNaturalOrder
- MaxByNaturalOrder
- EnumIsLessThan
- EnumIsLessThanOrEqualTo
NaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("NaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$NaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Comparator<String>> testNaturalOrder() {
return ImmutableSet.of(
- String::compareTo,
+ naturalOrder(),
Comparator.comparing(s -> 0),
- Comparator.comparing(identity()),
- Collections.<String>reverseOrder(reverseOrder()),
- Comparator.<String>reverseOrder().reversed());
+ naturalOrder(),
+ naturalOrder(),
+ naturalOrder());
}ReverseOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ReverseOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ReverseOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Comparator<String>> testReverseOrder() {
return ImmutableSet.of(
- Collections.reverseOrder(),
- Collections.<String>reverseOrder(naturalOrder()),
- Comparator.<String>naturalOrder().reversed());
+ Comparator.reverseOrder(), Comparator.reverseOrder(), Comparator.reverseOrder());
}ComparatorIdentity
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorIdentity")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorIdentity).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Comparator<String>> testComparatorIdentity() {
return ImmutableSet.of(
Comparator.comparing(s -> "foo", Comparator.comparingInt(String::length)),
- Comparator.comparing(identity(), Comparator.comparingInt(String::length)));
+ Comparator.comparingInt(String::length));
}Comparing
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("Comparing")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$Comparing).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<String> testComparing() {
- return Comparator.comparingInt(s -> RoundingMode.valueOf(s).ordinal());
+ return comparing(s -> RoundingMode.valueOf(s));
}ComparatorThenComparing
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparing")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparing).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<String> testComparatorThenComparing() {
- return Comparator.<String>naturalOrder().thenComparing(Comparator.comparing(String::isEmpty));
+ return Comparator.<String>naturalOrder().thenComparing(String::isEmpty);
}ComparatorThenComparingReverseOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingReverseOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingReverseOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<String> testComparatorThenComparingReverseOrder() {
- return Comparator.<String>naturalOrder()
- .thenComparing(Comparator.comparing(String::isEmpty).reversed());
+ return Comparator.<String>naturalOrder().thenComparing(String::isEmpty, reverseOrder());
}ComparatorThenComparingWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<String> testComparatorThenComparingWithComparator() {
- return Comparator.<String>naturalOrder()
- .thenComparing(Comparator.comparing(String::isEmpty, reverseOrder()));
+ return Comparator.<String>naturalOrder().thenComparing(String::isEmpty, reverseOrder());
}ComparatorThenComparingComparatorReversed
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingComparatorReversed")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingComparatorReversed).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<String> testComparatorThenComparingComparatorReversed() {
return Comparator.<String>naturalOrder()
- .thenComparing(
- Comparator.comparing(String::isEmpty, Comparator.<Boolean>reverseOrder()).reversed());
+ .thenComparing(String::isEmpty, Comparator.<Boolean>reverseOrder().reversed());
}ComparatorThenComparingDouble
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingDouble")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingDouble).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<Integer> testComparatorThenComparingDouble() {
- return Comparator.<Integer>naturalOrder()
- .thenComparing(Comparator.comparingDouble(Integer::doubleValue));
+ return Comparator.<Integer>naturalOrder().thenComparingDouble(Integer::doubleValue);
}ComparatorThenComparingInt
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingInt")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingInt).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<Integer> testComparatorThenComparingInt() {
- return Comparator.<Integer>naturalOrder()
- .thenComparing(Comparator.comparingInt(Integer::intValue));
+ return Comparator.<Integer>naturalOrder().thenComparingInt(Integer::intValue);
}ComparatorThenComparingLong
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingLong")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingLong).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Comparator<Integer> testComparatorThenComparingLong() {
- return Comparator.<Integer>naturalOrder()
- .thenComparing(Comparator.comparingLong(Integer::longValue));
+ return Comparator.<Integer>naturalOrder().thenComparingLong(Integer::longValue);
}ComparatorThenComparingNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorThenComparingNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorThenComparingNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Comparator<String>> testComparatorThenComparingNaturalOrder() {
return ImmutableSet.of(
Comparator.<String>naturalOrder().thenComparing(s -> 0),
- Comparator.<String>naturalOrder().thenComparing(identity()));
+ Comparator.<String>naturalOrder().thenComparing(naturalOrder()));
}ComparableCompareTo
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparableCompareTo")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparableCompareTo).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testComparableCompareTo() {
- return ImmutableSet.of(
- Comparator.<String>naturalOrder().compare("foo", "bar"),
- Comparator.<String>reverseOrder().compare("baz", "qux"));
+ return ImmutableSet.of("foo".compareTo("bar"), "qux".compareTo("baz"));
}CollectionsSort
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsSort")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsSort).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
void testCollectionsSort() {
- Collections.sort(ImmutableList.of("foo", "bar"), naturalOrder());
+ Collections.sort(ImmutableList.of("foo", "bar"));
}CollectionsMin
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMin")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMin).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testCollectionsMin() {
return ImmutableSet.of(
- Collections.min(ImmutableList.of("foo"), naturalOrder()),
- Collections.max(ImmutableList.of("bar"), reverseOrder()));
+ Collections.min(ImmutableList.of("foo")), Collections.min(ImmutableList.of("bar")));
}CollectionsMinArraysAsList
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMinArraysAsList")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMinArraysAsList).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testCollectionsMinArraysAsList() {
- return Arrays.stream(new String[0]).min(naturalOrder()).orElseThrow();
+ return Collections.min(Arrays.asList(new String[0]), naturalOrder());
}CollectionsMinWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMinWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMinWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testCollectionsMinWithComparator() {
- return ImmutableSet.of("foo", "bar").stream().min(naturalOrder()).orElseThrow();
+ return Collections.min(ImmutableSet.of("foo", "bar"), naturalOrder());
}CollectionsMinArraysAsListVarargs
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMinArraysAsListVarargs")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMinArraysAsListVarargs).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
int testCollectionsMinArraysAsListVarargs() {
- return Stream.of(1, 2).min(naturalOrder()).orElseThrow();
+ return Collections.min(Arrays.asList(1, 2), naturalOrder());
}ComparatorsMin2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMin2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMin2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testComparatorsMin2() {
return ImmutableSet.of(
- "foo".compareTo("bar") <= 0 ? "foo" : "bar",
- "baz".compareTo("qux") > 0 ? "qux" : "baz",
- "quux".compareTo("corge") < 0 ? "quux" : "corge",
- "grault".compareTo("garply") >= 0 ? "garply" : "grault",
- Comparators.min("waldo", "fred", naturalOrder()),
- Comparators.max("plugh", "xyzzy", reverseOrder()),
- Collections.min(Arrays.asList("thud", "foo")),
- Collections.min(ImmutableList.of("bar", "baz")),
- Collections.min(ImmutableSet.of("qux", "quux")));
+ Comparators.min("foo", "bar"),
+ Comparators.min("baz", "qux"),
+ Comparators.min("corge", "quux"),
+ Comparators.min("garply", "grault"),
+ Comparators.min("waldo", "fred"),
+ Comparators.min("plugh", "xyzzy"),
+ Comparators.min("thud", "foo"),
+ Comparators.min("bar", "baz"),
+ Comparators.min("qux", "quux"));
}ComparatorsMin3
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMin3")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMin3).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Object> testComparatorsMin3() {
return ImmutableSet.of(
- Comparator.comparingInt(String::length).compare("foo", "bar") <= 0 ? "foo" : "bar",
- Comparator.comparingInt(String::length).compare("baz", "qux") > 0 ? "qux" : "baz",
- Comparator.comparingInt(String::length).compare("quux", "corge") < 0 ? "quux" : "corge",
- Comparator.comparingInt(String::length).compare("grault", "garply") >= 0
- ? "garply"
- : "grault",
- Collections.min(Arrays.asList("waldo", "fred"), (a, b) -> -1),
- Collections.min(ImmutableList.of("plugh", "xyzzy"), (a, b) -> 0),
- Collections.min(ImmutableSet.of("thud", "foo"), (a, b) -> 1));
+ Comparators.min("foo", "bar", Comparator.comparingInt(String::length)),
+ Comparators.min("baz", "qux", Comparator.comparingInt(String::length)),
+ Comparators.min("corge", "quux", Comparator.comparingInt(String::length)),
+ Comparators.min("garply", "grault", Comparator.comparingInt(String::length)),
+ Comparators.min("waldo", "fred", (a, b) -> -1),
+ Comparators.min("plugh", "xyzzy", (a, b) -> 0),
+ Comparators.min("thud", "foo", (a, b) -> 1));
}CollectionsMax
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMax")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMax).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testCollectionsMax() {
return ImmutableSet.of(
- Collections.max(ImmutableList.of("foo"), naturalOrder()),
- Collections.min(ImmutableList.of("bar"), reverseOrder()));
+ Collections.max(ImmutableList.of("foo")), Collections.max(ImmutableList.of("bar")));
}CollectionsMaxArraysAsList
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMaxArraysAsList")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMaxArraysAsList).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testCollectionsMaxArraysAsList() {
- return Arrays.stream(new String[0]).max(naturalOrder()).orElseThrow();
+ return Collections.max(Arrays.asList(new String[0]), naturalOrder());
}CollectionsMaxWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMaxWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMaxWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testCollectionsMaxWithComparator() {
- return ImmutableSet.of("foo", "bar").stream().max(naturalOrder()).orElseThrow();
+ return Collections.max(ImmutableSet.of("foo", "bar"), naturalOrder());
}CollectionsMaxArraysAsListVarargs
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsMaxArraysAsListVarargs")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$CollectionsMaxArraysAsListVarargs).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
int testCollectionsMaxArraysAsListVarargs() {
- return Stream.of(1, 2).max(naturalOrder()).orElseThrow();
+ return Collections.max(Arrays.asList(1, 2), naturalOrder());
}ComparatorsMax2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMax2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMax2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testComparatorsMax2() {
return ImmutableSet.of(
- "foo".compareTo("bar") >= 0 ? "foo" : "bar",
- "baz".compareTo("qux") < 0 ? "qux" : "baz",
- "quux".compareTo("corge") > 0 ? "quux" : "corge",
- "grault".compareTo("garply") <= 0 ? "garply" : "grault",
- Comparators.max("waldo", "fred", naturalOrder()),
- Comparators.min("plugh", "xyzzy", reverseOrder()),
- Collections.max(Arrays.asList("thud", "foo")),
- Collections.max(ImmutableList.of("bar", "baz")),
- Collections.max(ImmutableSet.of("qux", "quux")));
+ Comparators.max("foo", "bar"),
+ Comparators.max("baz", "qux"),
+ Comparators.max("corge", "quux"),
+ Comparators.max("garply", "grault"),
+ Comparators.max("waldo", "fred"),
+ Comparators.max("plugh", "xyzzy"),
+ Comparators.max("thud", "foo"),
+ Comparators.max("bar", "baz"),
+ Comparators.max("qux", "quux"));
}ComparatorsMax3
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMax3")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMax3).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Object> testComparatorsMax3() {
return ImmutableSet.of(
- Comparator.comparingInt(String::length).compare("foo", "bar") >= 0 ? "foo" : "bar",
- Comparator.comparingInt(String::length).compare("baz", "qux") < 0 ? "qux" : "baz",
- Comparator.comparingInt(String::length).compare("quux", "corge") > 0 ? "quux" : "corge",
- Comparator.comparingInt(String::length).compare("grault", "garply") <= 0
- ? "garply"
- : "grault",
- Collections.max(Arrays.asList("waldo", "fred"), (a, b) -> -1),
- Collections.max(ImmutableList.of("plugh", "xyzzy"), (a, b) -> 0),
- Collections.max(ImmutableSet.of("thud", "foo"), (a, b) -> 1));
+ Comparators.max("foo", "bar", Comparator.comparingInt(String::length)),
+ Comparators.max("baz", "qux", Comparator.comparingInt(String::length)),
+ Comparators.max("corge", "quux", Comparator.comparingInt(String::length)),
+ Comparators.max("garply", "grault", Comparator.comparingInt(String::length)),
+ Comparators.max("waldo", "fred", (a, b) -> -1),
+ Comparators.max("plugh", "xyzzy", (a, b) -> 0),
+ Comparators.max("thud", "foo", (a, b) -> 1));
}Least
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("Least")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$Least).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<String, ?, List<String>> testLeast() {
- return greatest(1, Comparator.comparingInt(String::length).reversed());
+ return least(1, Comparator.comparingInt(String::length));
}Greatest
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("Greatest")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$Greatest).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<String, ?, List<String>> testGreatest() {
- return least(1, Comparator.comparingInt(String::length).reversed());
+ return greatest(1, Comparator.comparingInt(String::length));
}LeastNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LeastNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$LeastNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<String, ?, List<String>> testLeastNaturalOrder() {
- return greatest(1, reverseOrder());
+ return least(1, naturalOrder());
}GreatestNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("GreatestNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$GreatestNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<String, ?, List<String>> testGreatestNaturalOrder() {
- return least(1, reverseOrder());
+ return greatest(1, naturalOrder());
}ComparatorsMin0
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMin0")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMin0).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
BinaryOperator<String> testComparatorsMin0() {
- return BinaryOperator.minBy(naturalOrder());
+ return Comparators::min;
}ComparatorsMax0
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ComparatorsMax0")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$ComparatorsMax0).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
BinaryOperator<String> testComparatorsMax0() {
- return BinaryOperator.maxBy(naturalOrder());
+ return Comparators::max;
}MinByNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MinByNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$MinByNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<Integer, ?, Optional<Integer>> testMinByNaturalOrder() {
- return maxBy(reverseOrder());
+ return minBy(naturalOrder());
}MaxByNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MaxByNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$MaxByNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Collector<Integer, ?, Optional<Integer>> testMaxByNaturalOrder() {
- return minBy(reverseOrder());
+ return maxBy(naturalOrder());
}EnumIsLessThan
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("EnumIsLessThan")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$EnumIsLessThan).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testEnumIsLessThan() {
return ImmutableSet.of(
- RoundingMode.UP.ordinal() < RoundingMode.DOWN.ordinal(),
- RoundingMode.UP.ordinal() >= RoundingMode.DOWN.ordinal());
+ RoundingMode.UP.compareTo(RoundingMode.DOWN) < 0,
+ RoundingMode.UP.compareTo(RoundingMode.DOWN) >= 0);
}EnumIsLessThanOrEqualTo
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("EnumIsLessThanOrEqualTo")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ComparatorRules\$EnumIsLessThanOrEqualTo).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testEnumIsLessThanOrEqualTo() {
return ImmutableSet.of(
- RoundingMode.UP.ordinal() <= RoundingMode.DOWN.ordinal(),
- RoundingMode.UP.ordinal() > RoundingMode.DOWN.ordinal());
+ RoundingMode.UP.compareTo(RoundingMode.DOWN) <= 0,
+ RoundingMode.UP.compareTo(RoundingMode.DOWN) > 0);
}