ImmutableListRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$).*as compiler argument.
Table of contents
- ImmutableListBuilder
- ImmutableListCopyOf
- StreamCollectToImmutableList
- ImmutableListSortedCopyOf
- ImmutableListSortedCopyOfWithComparator
- ImmutableListSortedCopyOfIterator
- ImmutableListSortedCopyOfIteratorWithComparator
- StreamCollectToImmutableSetAsList
- ImmutableListOf0
- ImmutableListOf1
- ImmutableListOf2
- ImmutableListOf3
- ImmutableListOf4
- ImmutableListOf5
ImmutableListBuilder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListBuilder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListBuilder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableList.Builder<String> testImmutableListBuilder() {
- return new ImmutableList.Builder<>();
+ return ImmutableList.builder();
}ImmutableListCopyOf
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListCopyOf")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListCopyOf).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableList<Integer>> testImmutableListCopyOf() {
return ImmutableSet.of(
- ImmutableList.<Integer>builder().add(new Integer[] {1}).build(),
- Arrays.stream(new Integer[] {2}).collect(toImmutableList()),
- ImmutableList.<Integer>builder().addAll(ImmutableList.of(3).iterator()).build(),
- Streams.stream(ImmutableList.of(4).iterator()).collect(toImmutableList()),
- ImmutableList.<Integer>builder().addAll(ImmutableList.of(5)::iterator).build(),
- Streams.stream(ImmutableList.of(6)::iterator).collect(toImmutableList()),
- ImmutableList.of(7).stream().collect(toImmutableList()));
+ ImmutableList.copyOf(new Integer[] {1}),
+ ImmutableList.copyOf(new Integer[] {2}),
+ ImmutableList.copyOf(ImmutableList.of(3).iterator()),
+ ImmutableList.copyOf(ImmutableList.of(4).iterator()),
+ ImmutableList.copyOf(ImmutableList.of(5)::iterator),
+ ImmutableList.copyOf(ImmutableList.of(6)::iterator),
+ ImmutableList.copyOf(ImmutableList.of(7)));
}StreamCollectToImmutableList
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCollectToImmutableList")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$StreamCollectToImmutableList).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableList<Integer> testStreamCollectToImmutableList() {
- return ImmutableList.copyOf(Stream.of(1).iterator());
+ return Stream.of(1).collect(toImmutableList());
}ImmutableListSortedCopyOf
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListSortedCopyOf")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOf).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
return ImmutableSet.of(
- ImmutableList.sortedCopyOf(naturalOrder(), ImmutableSet.of(1)),
- Streams.stream(ImmutableSet.of(2)::iterator).sorted().collect(toImmutableList()),
- ImmutableSet.of(3).stream().sorted().collect(toImmutableList()));
+ ImmutableList.sortedCopyOf(ImmutableSet.of(1)),
+ ImmutableList.sortedCopyOf(ImmutableSet.of(2)::iterator),
+ ImmutableList.sortedCopyOf(ImmutableSet.of(3)));
}ImmutableListSortedCopyOfWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListSortedCopyOfWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOfWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ImmutableList<String>> testImmutableListSortedCopyOfWithComparator() {
return ImmutableSet.of(
- Streams.stream(ImmutableSet.of("foo")::iterator)
- .sorted(comparing(String::length))
- .collect(toImmutableList()),
- ImmutableSet.of("bar").stream()
- .sorted(comparing(String::isEmpty))
- .collect(toImmutableList()));
+ ImmutableList.sortedCopyOf(comparing(String::length), ImmutableSet.of("foo")::iterator),
+ ImmutableList.sortedCopyOf(comparing(String::isEmpty), ImmutableSet.of("bar")));
}ImmutableListSortedCopyOfIterator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListSortedCopyOfIterator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOfIterator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Iterator<Integer>> testImmutableListSortedCopyOfIterator() {
return ImmutableSet.of(
- Streams.stream(ImmutableList.of(1)::iterator).sorted().iterator(),
- ImmutableList.of(2).stream().sorted().iterator());
+ ImmutableList.sortedCopyOf(ImmutableList.of(1)::iterator).iterator(),
+ ImmutableList.sortedCopyOf(ImmutableList.of(2)).iterator());
}ImmutableListSortedCopyOfIteratorWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListSortedCopyOfIteratorWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOfIteratorWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Iterator<String>> testImmutableListSortedCopyOfIteratorWithComparator() {
return ImmutableSet.of(
- Streams.stream(ImmutableList.of("foo")::iterator)
- .sorted(Comparator.comparing(String::length))
+ ImmutableList.sortedCopyOf(
+ Comparator.comparing(String::length), ImmutableList.of("foo")::iterator)
.iterator(),
- ImmutableList.of("bar").stream().sorted(Comparator.comparing(String::isEmpty)).iterator());
+ ImmutableList.sortedCopyOf(Comparator.comparing(String::isEmpty), ImmutableList.of("bar"))
+ .iterator());
}StreamCollectToImmutableSetAsList
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCollectToImmutableSetAsList")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$StreamCollectToImmutableSetAsList).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableList<Integer> testStreamCollectToImmutableSetAsList() {
- return Stream.of(1).distinct().collect(toImmutableList());
+ return Stream.of(1).collect(toImmutableSet()).asList();
}ImmutableListOf0
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf0")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf0).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<List<Integer>> testImmutableListOf0() {
return ImmutableSet.of(
- ImmutableList.<Integer>builder().build(),
- Stream.<Integer>empty().collect(toImmutableList()),
- Collections.<Integer>emptyList(),
- List.<Integer>of());
+ ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of());
}ImmutableListOf1
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf1")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf1).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<List<Integer>> testImmutableListOf1() {
- return ImmutableSet.of(
- ImmutableList.<Integer>builder().add(1).build(), Collections.singletonList(2), List.of(3));
+ return ImmutableSet.of(ImmutableList.of(1), ImmutableList.of(2), ImmutableList.of(3));
}ImmutableListOf2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
List<Integer> testImmutableListOf2() {
- return List.of(1, 2);
+ return ImmutableList.of(1, 2);
}ImmutableListOf3
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf3")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf3).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
List<Integer> testImmutableListOf3() {
- return List.of(1, 2, 3);
+ return ImmutableList.of(1, 2, 3);
}ImmutableListOf4
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf4")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf4).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
List<Integer> testImmutableListOf4() {
- return List.of(1, 2, 3, 4);
+ return ImmutableList.of(1, 2, 3, 4);
}ImmutableListOf5
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutableListOf5")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf5).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
List<Integer> testImmutableListOf5() {
- return List.of(1, 2, 3, 4, 5);
+ return ImmutableList.of(1, 2, 3, 4, 5);
}