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
  11. SetsDifference
  12. SetsDifferenceMap
  13. SetsDifferenceMultimap
  14. SetsIntersection
  15. SetsIntersectionMap
  16. SetsIntersectionMultimap
  17. SetsUnion

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);
   }

SetsDifference

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableSet<Integer>> testSetsDifference() {
     return ImmutableSet.of(
-        ImmutableSet.of(1).stream()
-            .filter(not(ImmutableSet.of(2)::contains))
-            .collect(toImmutableSet()),
-        ImmutableSet.of(3).stream()
-            .filter(v -> !ImmutableSet.of(4).contains(v))
-            .collect(toImmutableSet()));
+        Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy(),
+        Sets.difference(ImmutableSet.of(3), ImmutableSet.of(4)).immutableCopy());
   }

SetsDifferenceMap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableSet<Integer>> testSetsDifferenceMap() {
     return ImmutableSet.of(
-        ImmutableSet.of(1).stream()
-            .filter(not(ImmutableMap.of(2, 3)::containsKey))
-            .collect(toImmutableSet()),
-        ImmutableSet.of(4).stream()
-            .filter(v -> !ImmutableMap.of(5, 6).containsKey(v))
-            .collect(toImmutableSet()));
+        Sets.difference(ImmutableSet.of(1), ImmutableMap.of(2, 3).keySet()).immutableCopy(),
+        Sets.difference(ImmutableSet.of(4), ImmutableMap.of(5, 6).keySet()).immutableCopy());
   }

SetsDifferenceMultimap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<ImmutableSet<Integer>> testSetsDifferenceMultimap() {
     return ImmutableSet.of(
-        ImmutableSet.of(1).stream()
-            .filter(not(ImmutableSetMultimap.of(2, 3)::containsKey))
-            .collect(toImmutableSet()),
-        ImmutableSet.of(4).stream()
-            .filter(v -> !ImmutableSetMultimap.of(5, 6).containsKey(v))
-            .collect(toImmutableSet()));
+        Sets.difference(ImmutableSet.of(1), ImmutableSetMultimap.of(2, 3).keySet()).immutableCopy(),
+        Sets.difference(ImmutableSet.of(4), ImmutableSetMultimap.of(5, 6).keySet())
+            .immutableCopy());
   }

SetsIntersection

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testSetsIntersection() {
-    return ImmutableSet.of(1).stream()
-        .filter(ImmutableSet.of(2)::contains)
-        .collect(toImmutableSet());
+    return Sets.intersection(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
   }

SetsIntersectionMap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testSetsIntersectionMap() {
-    return ImmutableSet.of(1).stream()
-        .filter(ImmutableMap.of(2, 3)::containsKey)
-        .collect(toImmutableSet());
+    return Sets.intersection(ImmutableSet.of(1), ImmutableMap.of(2, 3).keySet()).immutableCopy();
   }

SetsIntersectionMultimap

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testSetsIntersectionMultimap() {
-    return ImmutableSet.of(1).stream()
-        .filter(ImmutableSetMultimap.of(2, 3)::containsKey)
-        .collect(toImmutableSet());
+    return Sets.intersection(ImmutableSet.of(1), ImmutableSetMultimap.of(2, 3).keySet())
+        .immutableCopy();
   }

SetsUnion

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testSetsUnion() {
-    return Stream.concat(ImmutableSet.of(1).stream(), ImmutableSet.of(2).stream())
-        .collect(toImmutableSet());
+    return Sets.union(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
   }

Copyright © 2017-2024 Picnic Technologies BV