MapEntryRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$).* as compiler argument.

Table of contents
  1. MapEntry
  2. ComparingByKey
  3. ComparingByKeyWithComparator
  4. ComparingByValue
  5. ComparingByValueWithComparator

MapEntry

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("MapEntry") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$MapEntry).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Map.Entry<String, Integer>> testMapEntry() {
-  return ImmutableSet.of(
-      Maps.immutableEntry("foo", 1), new AbstractMap.SimpleImmutableEntry<>("bar", 2));
+  return ImmutableSet.of(Map.entry("foo", 1), Map.entry("bar", 2));
 }

ComparingByKey

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ComparingByKey") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$ComparingByKey).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Comparator<Map.Entry<Integer, String>>> testComparingByKey() {
-  return ImmutableSet.of(
-      Comparator.comparing(Map.Entry::getKey),
-      Map.Entry.comparingByKey(Comparator.naturalOrder()));
+  return ImmutableSet.of(comparingByKey(), comparingByKey());
 }

ComparingByKeyWithComparator

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ComparingByKeyWithComparator") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$ComparingByKeyWithComparator).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Comparator<Map.Entry<Integer, String>> testComparingByKeyWithComparator() {
-  return Comparator.comparing(Map.Entry::getKey, Comparator.comparingInt(i -> i * 2));
+  return comparingByKey(Comparator.comparingInt(i -> i * 2));
 }

ComparingByValue

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ComparingByValue") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$ComparingByValue).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Comparator<Map.Entry<Integer, String>>> testComparingByValue() {
-  return ImmutableSet.of(
-      Comparator.comparing(Map.Entry::getValue),
-      Map.Entry.comparingByValue(Comparator.naturalOrder()));
+  return ImmutableSet.of(comparingByValue(), comparingByValue());
 }

ComparingByValueWithComparator

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ComparingByValueWithComparator") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!MapEntryRules\$ComparingByValueWithComparator).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Comparator<Map.Entry<Integer, String>> testComparingByValueWithComparator() {
-  return Comparator.comparing(Map.Entry::getValue, Comparator.comparingInt(String::length));
+  return comparingByValue(Comparator.comparingInt(String::length));
 }

Copyright © 2017-2026 Picnic Technologies BV