Skip to main content Link Search Menu Expand Document (external link)

ImmutableListMultimapRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. ImmutableListMultimapBuilder
  2. EmptyImmutableListMultimap
  3. PairToImmutableListMultimap
  4. EntryToImmutableListMultimap
  5. IterableToImmutableListMultimap
  6. StreamOfMapEntriesToImmutableListMultimap
  7. IndexIterableToImmutableListMultimap
  8. TransformMultimapValuesToImmutableListMultimap
  9. TransformMultimapValuesToImmutableListMultimap2

ImmutableListMultimapBuilder

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.ImmutableListMultimapBuilder)) as compiler argument.

Samples

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

 ImmutableSet<ImmutableMultimap.Builder<String, Integer>> testImmutableListMultimapBuilder() {
     return ImmutableSet.of(
-        new ImmutableListMultimap.Builder<>(),
-        new ImmutableMultimap.Builder<>(),
-        ImmutableMultimap.builder());
+        ImmutableListMultimap.builder(),
+        ImmutableListMultimap.builder(),
+        ImmutableListMultimap.builder());
   }

EmptyImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.EmptyImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableSet<ImmutableMultimap<String, Integer>> testEmptyImmutableListMultimap() {
-    return ImmutableSet.of(
-        ImmutableListMultimap.<String, Integer>builder().build(), ImmutableMultimap.of());
+    return ImmutableSet.of(ImmutableListMultimap.of(), ImmutableListMultimap.of());
   }

PairToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.PairToImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableSet<ImmutableMultimap<String, Integer>> testPairToImmutableListMultimap() {
-    return ImmutableSet.of(
-        ImmutableListMultimap.<String, Integer>builder().put("foo", 1).build(),
-        ImmutableMultimap.of("bar", 2));
+    return ImmutableSet.of(ImmutableListMultimap.of("foo", 1), ImmutableListMultimap.of("bar", 2));
   }

EntryToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.EntryToImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableList<ImmutableMultimap<String, Integer>> testEntryToImmutableListMultimap() {
     return ImmutableList.of(
-        ImmutableListMultimap.<String, Integer>builder().put(Map.entry("foo", 1)).build(),
-        Stream.of(Map.entry("foo", 1))
-            .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)));
+        ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()),
+        ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()));
   }

IterableToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.IterableToImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableList<ImmutableMultimap<String, Integer>> testIterableToImmutableListMultimap() {
     return ImmutableList.of(
+        ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)),
+        ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)),
         ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1).entries()),
-        ImmutableListMultimap.<String, Integer>builder()
-            .putAll(ImmutableListMultimap.of("foo", 1))
-            .build(),
-        ImmutableListMultimap.<String, Integer>builder()
-            .putAll(ImmutableListMultimap.of("foo", 1).entries())
-            .build(),
-        ImmutableListMultimap.of("foo", 1).entries().stream()
-            .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)),
-        Streams.stream(Iterables.cycle(Map.entry("foo", 1)))
-            .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)),
-        ImmutableMultimap.copyOf(ImmutableListMultimap.of("foo", 1)),
-        ImmutableMultimap.copyOf(ImmutableListMultimap.of("foo", 1).entries()),
-        ImmutableMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1))));
+        ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1).entries()),
+        ImmutableListMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1))),
+        ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)),
+        ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)),
+        ImmutableListMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1))));
   }

StreamOfMapEntriesToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.StreamOfMapEntriesToImmutableListMultimap)) as compiler argument.

Samples

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

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

IndexIterableToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.IndexIterableToImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableSet<ImmutableListMultimap<Integer, Integer>> testIndexIterableToImmutableListMultimap() {
     return ImmutableSet.of(
-        ImmutableList.of(1).stream().collect(toImmutableListMultimap(n -> n * 2, identity())),
-        Streams.stream(ImmutableList.of(2)::iterator)
-            .collect(toImmutableListMultimap(Integer::valueOf, n -> n)),
-        Streams.stream(ImmutableList.of(3).iterator())
-            .collect(toImmutableListMultimap(n -> n.intValue(), identity())));
+        Multimaps.index(ImmutableList.of(1), n -> n * 2),
+        Multimaps.index(ImmutableList.of(2)::iterator, Integer::valueOf),
+        Multimaps.index(ImmutableList.of(3).iterator(), n -> n.intValue()));
   }

TransformMultimapValuesToImmutableListMultimap

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.TransformMultimapValuesToImmutableListMultimap)) as compiler argument.

Samples

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

 ImmutableListMultimap<String, Integer> testTransformMultimapValuesToImmutableListMultimap() {
-    return ImmutableListMultimap.of("foo", 1L).entries().stream()
-        .collect(toImmutableListMultimap(Map.Entry::getKey, e -> Math.toIntExact(e.getValue())));
+    return ImmutableListMultimap.copyOf(
+        Multimaps.transformValues(ImmutableListMultimap.of("foo", 1L), v -> Math.toIntExact(v)));
   }

TransformMultimapValuesToImmutableListMultimap2

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(ImmutableListMultimapRules\.TransformMultimapValuesToImmutableListMultimap2)) as compiler argument.

Samples

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

 ImmutableSet<ImmutableListMultimap<String, Integer>>
       testTransformMultimapValuesToImmutableListMultimap2() {
     return ImmutableSet.of(
-        ImmutableSetMultimap.of("foo", 1L).asMap().entrySet().stream()
-            .collect(
-                flatteningToImmutableListMultimap(
-                    Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact))),
-        Multimaps.asMap((Multimap<String, Long>) ImmutableSetMultimap.of("bar", 2L))
-            .entrySet()
-            .stream()
-            .collect(
-                flatteningToImmutableListMultimap(
-                    Map.Entry::getKey, e -> e.getValue().stream().map(n -> Math.toIntExact(n)))),
-        Multimaps.asMap(ImmutableListMultimap.of("baz", 3L)).entrySet().stream()
-            .collect(
-                flatteningToImmutableListMultimap(
-                    Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact))),
-        Multimaps.asMap(ImmutableSetMultimap.of("qux", 4L)).entrySet().stream()
-            .collect(
-                flatteningToImmutableListMultimap(
-                    Map.Entry::getKey, e -> e.getValue().stream().map(n -> Math.toIntExact(n)))),
-        Multimaps.asMap(TreeMultimap.<String, Long>create()).entrySet().stream()
-            .collect(
-                flatteningToImmutableListMultimap(
-                    Map.Entry::getKey, e -> e.getValue().stream().map(Math::toIntExact))));
+        ImmutableListMultimap.copyOf(
+            Multimaps.transformValues(ImmutableSetMultimap.of("foo", 1L), Math::toIntExact)),
+        ImmutableListMultimap.copyOf(
+            Multimaps.transformValues(
+                (Multimap<String, Long>) ImmutableSetMultimap.of("bar", 2L),
+                n -> Math.toIntExact(n))),
+        ImmutableListMultimap.copyOf(
+            Multimaps.transformValues(ImmutableListMultimap.of("baz", 3L), Math::toIntExact)),
+        ImmutableListMultimap.copyOf(
+            Multimaps.transformValues(ImmutableSetMultimap.of("qux", 4L), n -> Math.toIntExact(n))),
+        ImmutableListMultimap.copyOf(
+            Multimaps.transformValues(TreeMultimap.<String, Long>create(), Math::toIntExact)));
   }

Copyright © 2017-2023 Picnic Technologies BV