ImmutableMapRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. ImmutableMapBuilder
  2. BuilderBuildOrThrow
  3. ImmutableMapOfEntryGetKeyEntryGetValue
  4. MapsToMap
  5. ImmutableMapCopyOf
  6. StreamCollectToImmutableMap
  7. MapsUniqueIndex
  8. ImmutableMapCopyOfMapsTransformValues
  9. ImmutableMapOf0
  10. ImmutableMapOf2
  11. ImmutableMapOf4
  12. ImmutableMapOf6
  13. ImmutableMapOf8
  14. ImmutableMapOf10
  15. ImmutableMapCopyOfMapsFilterKeys
  16. ImmutableMapCopyOfMapsFilterValues
  17. ImmutableMapOfEntries
  18. BuilderPut

ImmutableMapBuilder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableMap.Builder<String, Integer> testImmutableMapBuilder() {
-  return new ImmutableMap.Builder<>();
+  return ImmutableMap.builder();
 }

BuilderBuildOrThrow

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableMap<Object, Object> testBuilderBuildOrThrow() {
-  return ImmutableMap.builder().build();
+  return ImmutableMap.builder().buildOrThrow();
 }

ImmutableMapOfEntryGetKeyEntryGetValue

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableMap<String, Integer>> testImmutableMapOfEntryGetKeyEntryGetValue() {
   return ImmutableSet.of(
-      ImmutableMap.<String, Integer>builder().put(Map.entry("foo", 1)).buildOrThrow(),
-      Stream.of(Map.entry("bar", 2))
-          .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)));
+      ImmutableMap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()),
+      ImmutableMap.of(Map.entry("bar", 2).getKey(), Map.entry("bar", 2).getValue()));
 }

MapsToMap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableMap<Integer, Integer>> testMapsToMap() {
   return ImmutableSet.of(
       Streams.stream(ImmutableList.of(1).iterator())
           .collect(toImmutableMap(k -> 0, n -> n.intValue())),
-      Streams.stream(ImmutableList.of(2).iterator())
-          .collect(toImmutableMap(identity(), n -> n.intValue())),
+      Maps.toMap(ImmutableList.of(2).iterator(), n -> n.intValue()),
       Streams.stream(ImmutableList.of(3)::iterator)
           .collect(toImmutableMap(k -> 0, Integer::valueOf)),
-      Streams.stream(ImmutableList.of(4)::iterator)
-          .collect(toImmutableMap(identity(), Integer::valueOf)),
+      Maps.toMap(ImmutableList.of(4)::iterator, Integer::valueOf),
       ImmutableList.of(5).stream().collect(toImmutableMap(k -> 0, n -> n * 2)),
-      ImmutableList.of(6).stream().collect(toImmutableMap(identity(), n -> n * 2)),
-      ImmutableMap.copyOf(Maps.asMap(ImmutableSet.of(7), Integer::valueOf)));
+      Maps.toMap(ImmutableList.of(6), n -> n * 2),
+      Maps.toMap(ImmutableSet.of(7), Integer::valueOf));
 }

ImmutableMapCopyOf

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, Integer>> testImmutableMapCopyOf() {
   return ImmutableSet.of(
-      ImmutableMap.copyOf(ImmutableMap.of("foo", 1).entrySet()),
-      ImmutableMap.<String, Integer>builder().putAll(ImmutableMap.of("bar", 2)).buildOrThrow(),
-      Map.copyOf(ImmutableMap.of("baz", 3)),
-      ImmutableMap.<String, Integer>builder()
-          .putAll(ImmutableMap.of("qux", 4).entrySet())
-          .buildOrThrow(),
-      Streams.stream(Iterables.cycle(Map.entry("corge", 6)))
-          .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)),
-      ImmutableMap.of("quux", 5).entrySet().stream()
-          .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)));
+      ImmutableMap.copyOf(ImmutableMap.of("foo", 1)),
+      ImmutableMap.copyOf(ImmutableMap.of("bar", 2)),
+      ImmutableMap.copyOf(ImmutableMap.of("baz", 3)),
+      ImmutableMap.copyOf(ImmutableMap.of("qux", 4).entrySet()),
+      ImmutableMap.copyOf(Iterables.cycle(Map.entry("corge", 6))),
+      ImmutableMap.copyOf(ImmutableMap.of("quux", 5).entrySet()));
 }

StreamCollectToImmutableMap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableMap<Integer, String> testStreamCollectToImmutableMap() {
-  return Stream.of(1, 2, 3)
-      .map(n -> Map.entry(n, n.toString()))
-      .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
+  return Stream.of(1, 2, 3).collect(toImmutableMap(n -> n, n -> n.toString()));
 }

MapsUniqueIndex

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableMap<Integer, Integer>> testMapsUniqueIndex() {
   return ImmutableSet.of(
       Streams.stream(ImmutableList.of(1).iterator())
           .collect(toImmutableMap(n -> n.intValue(), v -> 0)),
-      Streams.stream(ImmutableList.of(2).iterator())
-          .collect(toImmutableMap(n -> n.intValue(), identity())),
+      Maps.uniqueIndex(ImmutableList.of(2).iterator(), n -> n.intValue()),
       Streams.stream(ImmutableList.of(3)::iterator)
           .collect(toImmutableMap(Integer::valueOf, v -> 0)),
-      Streams.stream(ImmutableList.of(4)::iterator)
-          .collect(toImmutableMap(Integer::valueOf, identity())),
+      Maps.uniqueIndex(ImmutableList.of(4)::iterator, Integer::valueOf),
       ImmutableList.of(5).stream().collect(toImmutableMap(n -> n * 2, v -> 0)),
-      ImmutableList.of(6).stream().collect(toImmutableMap(n -> n * 2, identity())));
+      Maps.uniqueIndex(ImmutableList.of(6), n -> n * 2));
 }

ImmutableMapCopyOfMapsTransformValues

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableMap<String, Integer>> testImmutableMapCopyOfMapsTransformValues() {
   return ImmutableSet.of(
-      ImmutableMap.of("foo", 1L).entrySet().stream()
-          .collect(toImmutableMap(Map.Entry::getKey, e -> Math.toIntExact(e.getValue()))),
-      Maps.toMap(
-          ImmutableMap.of("bar", 2L).keySet(),
-          k -> Math.toIntExact(ImmutableMap.of("bar", 2L).get(k))));
+      ImmutableMap.copyOf(
+          Maps.transformValues(ImmutableMap.of("foo", 1L), v -> Math.toIntExact(v))),
+      ImmutableMap.copyOf(
+          Maps.transformValues(ImmutableMap.of("bar", 2L), v -> Math.toIntExact(v))));
 }

ImmutableMapOf0

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf0() {
   return ImmutableSet.of(
-      ImmutableMap.<String, String>builder().buildOrThrow(),
-      ImmutableMap.ofEntries(),
-      Collections.<String, String>emptyMap(),
-      Map.<String, String>of());
+      ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of());
 }

ImmutableMapOf2

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf2() {
   return ImmutableSet.of(
-      ImmutableMap.<String, String>builder().put("foo", "bar").buildOrThrow(),
-      ImmutableMap.ofEntries(Map.entry("baz", "qux")),
-      Collections.singletonMap("quux", "corge"),
-      Map.of("grault", "garply"));
+      ImmutableMap.of("foo", "bar"),
+      ImmutableMap.of("baz", "qux"),
+      ImmutableMap.of("quux", "corge"),
+      ImmutableMap.of("grault", "garply"));
 }

ImmutableMapOf4

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf4() {
   return ImmutableSet.of(
-      ImmutableMap.ofEntries(Map.entry("foo", "bar"), Map.entry("baz", "qux")),
-      Map.of("quux", "corge", "grault", "garply"));
+      ImmutableMap.of("foo", "bar", "baz", "qux"),
+      ImmutableMap.of("quux", "corge", "grault", "garply"));
 }

ImmutableMapOf6

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf6() {
   return ImmutableSet.of(
-      ImmutableMap.ofEntries(
-          Map.entry("foo", "bar"), Map.entry("baz", "qux"), Map.entry("quux", "corge")),
-      Map.of("grault", "garply", "waldo", "fred", "plugh", "xyzzy"));
+      ImmutableMap.of("foo", "bar", "baz", "qux", "quux", "corge"),
+      ImmutableMap.of("grault", "garply", "waldo", "fred", "plugh", "xyzzy"));
 }

ImmutableMapOf8

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf8() {
   return ImmutableSet.of(
-      ImmutableMap.ofEntries(
-          Map.entry("foo", "bar"),
-          Map.entry("baz", "qux"),
-          Map.entry("quux", "corge"),
-          Map.entry("grault", "garply")),
-      Map.of("waldo", "fred", "plugh", "xyzzy", "thud", "foo", "bar", "baz"));
+      ImmutableMap.of("foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply"),
+      ImmutableMap.of("waldo", "fred", "plugh", "xyzzy", "thud", "foo", "bar", "baz"));
 }

ImmutableMapOf10

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, String>> testImmutableMapOf10() {
   return ImmutableSet.of(
-      ImmutableMap.ofEntries(
-          Map.entry("foo", "bar"),
-          Map.entry("baz", "qux"),
-          Map.entry("quux", "corge"),
-          Map.entry("grault", "garply"),
-          Map.entry("waldo", "fred")),
-      Map.of("plugh", "xyzzy", "thud", "foo", "bar", "baz", "qux", "quux", "corge", "grault"));
+      ImmutableMap.of(
+          "foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply", "waldo", "fred"),
+      ImmutableMap.of(
+          "plugh", "xyzzy", "thud", "foo", "bar", "baz", "qux", "quux", "corge", "grault"));
 }

ImmutableMapCopyOfMapsFilterKeys

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableMap<String, Integer> testImmutableMapCopyOfMapsFilterKeys() {
-  return ImmutableMap.of("foo", 1).entrySet().stream()
-      .filter(entry -> entry.getKey().length() > 1)
-      .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
+  return ImmutableMap.copyOf(Maps.filterKeys(ImmutableMap.of("foo", 1), k -> k.length() > 1));
 }

ImmutableMapCopyOfMapsFilterValues

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableMap<String, Integer> testImmutableMapCopyOfMapsFilterValues() {
-  return ImmutableMap.of("foo", 1).entrySet().stream()
-      .filter(entry -> entry.getValue() > 0)
-      .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
+  return ImmutableMap.copyOf(Maps.filterValues(ImmutableMap.of("foo", 1), v -> v > 0));
 }

ImmutableMapOfEntries

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Map<String, Integer>> testImmutableMapOfEntries() {
   return ImmutableSet.of(
-      Map.ofEntries(),
-      Map.ofEntries(Map.entry("foo", 1)),
-      Map.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3)));
+      ImmutableMap.ofEntries(),
+      ImmutableMap.ofEntries(Map.entry("foo", 1)),
+      ImmutableMap.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3)));
 }

BuilderPut

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableMap.Builder<String, Integer>> testBuilderPut() {
   return ImmutableSet.of(
-      ImmutableMap.<String, Integer>builder().put(Map.entry("foo", 1)),
-      ImmutableMap.<String, Integer>builder().putAll(ImmutableMap.of("bar", 2)));
+      ImmutableMap.<String, Integer>builder().put("foo", 1),
+      ImmutableMap.<String, Integer>builder().put("bar", 2));
 }

Copyright © 2017-2026 Picnic Technologies BV