MapRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. CreateEnumMap
  2. MapGetOrNull
  3. MapGetOrDefault
  4. MapIsEmpty
  5. MapSize
  6. MapContainsKey
  7. MapContainsValue
  8. MapKeyStream
  9. MapValueStream

CreateEnumMap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Map<RoundingMode, String> testCreateEnumMap() {
-    return new HashMap<>();
+    return new EnumMap<>(RoundingMode.class);
   }

MapGetOrNull

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testMapGetOrNull() {
-    return ImmutableMap.of(1, "foo").getOrDefault("bar", null);
+    return ImmutableMap.of(1, "foo").get("bar");
   }

MapGetOrDefault

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testMapGetOrDefault() {
-    return requireNonNullElse(ImmutableMap.of(1, "foo").get("bar"), "baz");
+    return ImmutableMap.of(1, "foo").getOrDefault("bar", "baz");
   }

MapIsEmpty

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testMapIsEmpty() {
     return ImmutableSet.of(
-        ImmutableMap.of("foo", 1).keySet().isEmpty(),
-        ImmutableMap.of("bar", 2).values().isEmpty(),
-        ImmutableMap.of("baz", 3).entrySet().isEmpty());
+        ImmutableMap.of("foo", 1).isEmpty(),
+        ImmutableMap.of("bar", 2).isEmpty(),
+        ImmutableMap.of("baz", 3).isEmpty());
   }

MapSize

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testMapSize() {
     return ImmutableSet.of(
-        ImmutableMap.of("foo", 1).keySet().size(),
-        ImmutableMap.of("bar", 2).values().size(),
-        ImmutableMap.of("baz", 3).entrySet().size());
+        ImmutableMap.of("foo", 1).size(),
+        ImmutableMap.of("bar", 2).size(),
+        ImmutableMap.of("baz", 3).size());
   }

MapContainsKey

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testMapContainsKey() {
-    return ImmutableMap.of("foo", 1).keySet().contains("bar");
+    return ImmutableMap.of("foo", 1).containsKey("bar");
   }

MapContainsValue

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testMapContainsValue() {
-    return ImmutableMap.of("foo", 1).values().contains(2);
+    return ImmutableMap.of("foo", 1).containsValue(2);
   }

MapKeyStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<String> testMapKeyStream() {
-    return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getKey);
+    return ImmutableMap.of("foo", 1).keySet().stream();
   }

MapValueStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<Integer> testMapValueStream() {
-    return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue);
+    return ImmutableMap.of("foo", 1).values().stream();
   }

Copyright © 2017-2024 Picnic Technologies BV