ImmutableSetRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$).*as compiler argument.
Table of contents
- ImmutableSetBuilder
- ImmutableSetCopyOf
- StreamCollectToImmutableSet
- SetViewImmutableCopy
- ImmutableSetOf0
- ImmutableSetOf1
- ImmutableSetOf2
- ImmutableSetOf3
- ImmutableSetOf4
- ImmutableSetOf5
- SetsDifferenceImmutableCopy
- SetsDifferenceMapKeySetImmutableCopy
- SetsDifferenceMultimapKeySetImmutableCopy
- SetsIntersectionImmutableCopy
- SetsIntersectionMapKeySetImmutableCopy
- SetsIntersectionMultimapKeySetImmutableCopy
- SetsUnionImmutableCopy
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();
}ImmutableSetCopyOf
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableSetCopyOf")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$ImmutableSetCopyOf).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableSet<Integer>> testImmutableSetCopyOf() {
return ImmutableSet.of(
- ImmutableSet.<Integer>builder().add(new Integer[] {1}).build(),
- Arrays.stream(new Integer[] {2}).collect(toImmutableSet()),
- ImmutableSet.<Integer>builder().addAll(ImmutableSet.of(3).iterator()).build(),
- Streams.stream(ImmutableList.of(4).iterator()).collect(toImmutableSet()),
- ImmutableSet.<Integer>builder().addAll(ImmutableSet.of(5)).build(),
- Streams.stream(ImmutableList.of(6)::iterator).collect(toImmutableSet()),
- ImmutableList.of(7).stream().collect(toImmutableSet()));
+ ImmutableSet.copyOf(new Integer[] {1}),
+ ImmutableSet.copyOf(new Integer[] {2}),
+ ImmutableSet.copyOf(ImmutableSet.of(3).iterator()),
+ ImmutableSet.copyOf(ImmutableList.of(4).iterator()),
+ ImmutableSet.copyOf(ImmutableSet.of(5)),
+ ImmutableSet.copyOf(ImmutableList.of(6)::iterator),
+ ImmutableSet.copyOf(ImmutableList.of(7)));
}StreamCollectToImmutableSet
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCollectToImmutableSet")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$StreamCollectToImmutableSet).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableSet<Integer>> testStreamCollectToImmutableSet() {
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()));
}SetViewImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetViewImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetViewImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testSetViewImmutableCopy() {
- return ImmutableSet.copyOf(Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)));
+ return Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
}ImmutableSetOf0
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableSetOf0")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$ImmutableSetOf0).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Set<Integer>> testImmutableSetOf0() {
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(2), Set.of(3));
+ return ImmutableSet.of(ImmutableSet.of(1), ImmutableSet.of(2), ImmutableSet.of(3));
}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);
}SetsDifferenceImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsDifferenceImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsDifferenceImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableSet<Integer>> testSetsDifferenceImmutableCopy() {
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());
}SetsDifferenceMapKeySetImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsDifferenceMapKeySetImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsDifferenceMapKeySetImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableSet<Integer>> testSetsDifferenceMapKeySetImmutableCopy() {
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());
}SetsDifferenceMultimapKeySetImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsDifferenceMultimapKeySetImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsDifferenceMultimapKeySetImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableSet<Integer>> testSetsDifferenceMultimapKeySetImmutableCopy() {
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());
}SetsIntersectionImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsIntersectionImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsIntersectionImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testSetsIntersectionImmutableCopy() {
- return ImmutableSet.of(1).stream()
- .filter(ImmutableSet.of(2)::contains)
- .collect(toImmutableSet());
+ return Sets.intersection(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
}SetsIntersectionMapKeySetImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsIntersectionMapKeySetImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsIntersectionMapKeySetImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testSetsIntersectionMapKeySetImmutableCopy() {
- 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();
}SetsIntersectionMultimapKeySetImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsIntersectionMultimapKeySetImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsIntersectionMultimapKeySetImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testSetsIntersectionMultimapKeySetImmutableCopy() {
- 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();
}SetsUnionImmutableCopy
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("SetsUnionImmutableCopy")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableSetRules\$SetsUnionImmutableCopy).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testSetsUnionImmutableCopy() {
- return Stream.concat(ImmutableSet.of(1).stream(), ImmutableSet.of(2).stream())
- .collect(toImmutableSet());
+ return Sets.union(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy();
}