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

ImmutableSetRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. ImmutableSetBuilder
  2. IterableToImmutableSet
  3. StreamToImmutableSet
  4. ImmutableSetCopyOfSetView
  5. ImmutableSetOf
  6. ImmutableSetOf1
  7. ImmutableSetOf2
  8. ImmutableSetOf3
  9. ImmutableSetOf4
  10. ImmutableSetOf5

ImmutableSetBuilder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet.Builder<String> testImmutableSetBuilder() {
-    return new ImmutableSet.Builder<>();
+    return ImmutableSet.builder();
   }

IterableToImmutableSet

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableSet<Integer>> testIterableToImmutableSet() {
     return ImmutableSet.of(
-        ImmutableList.of(1).stream().collect(toImmutableSet()),
-        Streams.stream(ImmutableList.of(2)::iterator).collect(toImmutableSet()),
-        Streams.stream(ImmutableList.of(3).iterator()).collect(toImmutableSet()),
-        ImmutableSet.<Integer>builder().addAll(ImmutableSet.of(4)).build(),
-        ImmutableSet.<Integer>builder().addAll(ImmutableSet.of(5)::iterator).build(),
-        ImmutableSet.<Integer>builder().addAll(ImmutableSet.of(6).iterator()).build(),
-        ImmutableSet.<Integer>builder().add(new Integer[] {7}).build(),
-        Arrays.stream(new Integer[] {8}).collect(toImmutableSet()));
+        ImmutableSet.copyOf(ImmutableList.of(1)),
+        ImmutableSet.copyOf(ImmutableList.of(2)::iterator),
+        ImmutableSet.copyOf(ImmutableList.of(3).iterator()),
+        ImmutableSet.copyOf(ImmutableSet.of(4)),
+        ImmutableSet.copyOf(ImmutableSet.of(5)::iterator),
+        ImmutableSet.copyOf(ImmutableSet.of(6).iterator()),
+        ImmutableSet.copyOf(new Integer[] {7}),
+        ImmutableSet.copyOf(new Integer[] {8}));
   }

StreamToImmutableSet

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableSet<Integer>> testStreamToImmutableSet() {
     return ImmutableSet.of(
-        ImmutableSet.copyOf(Stream.of(1).iterator()),
-        Stream.of(2).distinct().collect(toImmutableSet()));
+        Stream.of(1).collect(toImmutableSet()), Stream.of(2).collect(toImmutableSet()));
   }

ImmutableSetCopyOfSetView

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testImmutableSetCopyOfSetView() {
-    return ImmutableSet.copyOf(Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)));
+    return Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
   }

ImmutableSetOf

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Set<Integer>> testImmutableSetOf() {
     return ImmutableSet.of(
-        ImmutableSet.<Integer>builder().build(),
-        Stream.<Integer>empty().collect(toImmutableSet()),
-        Collections.<Integer>emptySet(),
-        Set.<Integer>of());
+        ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
   }

ImmutableSetOf1

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Set<Integer>> testImmutableSetOf1() {
-    return ImmutableSet.of(
-        ImmutableSet.<Integer>builder().add(1).build(), Collections.singleton(1), Set.of(1));
+    return ImmutableSet.of(ImmutableSet.of(1), ImmutableSet.of(1), ImmutableSet.of(1));
   }

ImmutableSetOf2

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Set<Integer> testImmutableSetOf2() {
-    return Set.of(1, 2);
+    return ImmutableSet.of(1, 2);
   }

ImmutableSetOf3

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Set<Integer> testImmutableSetOf3() {
-    return Set.of(1, 2, 3);
+    return ImmutableSet.of(1, 2, 3);
   }

ImmutableSetOf4

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Set<Integer> testImmutableSetOf4() {
-    return Set.of(1, 2, 3, 4);
+    return ImmutableSet.of(1, 2, 3, 4);
   }

ImmutableSetOf5

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Set<Integer> testImmutableSetOf5() {
-    return Set.of(1, 2, 3, 4, 5);
+    return ImmutableSet.of(1, 2, 3, 4, 5);
   }

Copyright © 2017-2023 Picnic Technologies BV