CollectionRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. CollectionIsEmpty
  2. CollectionSize
  3. CollectionContains
  4. CollectionAddAllToCollectionExpression
  5. CollectionAddAllToCollectionBlock
  6. CollectionRemoveAllFromCollectionExpression
  7. CollectionRemoveAllFromCollectionBlock
  8. SetStream
  9. SetOfVarargs
  10. NewArrayListFromCollection
  11. ImmutableCollectionStream
  12. ImmutableCollectionAsList
  13. ImmutableCollectionContains
  14. ImmutableCollectionParallelStream
  15. ImmutableCollectionToString
  16. ArraysAsList
  17. CollectionToArray
  18. ImmutableCollectionToArrayWithArray
  19. ImmutableCollectionToArrayWithGenerator
  20. CollectionIterator
  21. OptionalFirstCollectionElement
  22. OptionalFirstQueueElement
  23. RemoveOptionalFirstNavigableSetElement
  24. RemoveOptionalFirstQueueElement
  25. CollectionForEach
  26. CollectionIteratorNext
  27. SequencedCollectionGetFirst
  28. SequencedCollectionGetLast
  29. ListAddFirst
  30. ListAdd
  31. ListRemoveFirst
  32. ListRemoveLast
  33. SortedSetFirst
  34. SortedSetLast

CollectionIsEmpty

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testCollectionIsEmpty() {
   return ImmutableSet.of(
-      ImmutableSet.of(1).size() == 0,
-      ImmutableSet.of(2).size() <= 0,
-      ImmutableSet.of(3).size() < 1,
-      ImmutableSet.of(4).size() != 0,
-      ImmutableSet.of(5).size() > 0,
-      ImmutableSet.of(6).size() >= 1,
-      Iterables.isEmpty(ImmutableSet.of(7)),
-      ImmutableSet.of(8).stream().findAny().isEmpty(),
-      ImmutableSet.of(9).stream().findFirst().isEmpty(),
-      ImmutableSet.of(10).asList().isEmpty(),
-      Sets.intersection(ImmutableSet.of(11), ImmutableSet.of(12)).immutableCopy().isEmpty());
+      ImmutableSet.of(1).isEmpty(),
+      ImmutableSet.of(2).isEmpty(),
+      ImmutableSet.of(3).isEmpty(),
+      !ImmutableSet.of(4).isEmpty(),
+      !ImmutableSet.of(5).isEmpty(),
+      !ImmutableSet.of(6).isEmpty(),
+      ImmutableSet.of(7).isEmpty(),
+      ImmutableSet.of(8).isEmpty(),
+      ImmutableSet.of(9).isEmpty(),
+      ImmutableSet.of(10).isEmpty(),
+      Sets.intersection(ImmutableSet.of(11), ImmutableSet.of(12)).isEmpty());
 }

CollectionSize

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Integer> testCollectionSize() {
-  return ImmutableSet.of(Iterables.size(ImmutableSet.of(1)), ImmutableSet.of(2).asList().size());
+  return ImmutableSet.of(ImmutableSet.of(1).size(), ImmutableSet.of(2).size());
 }

CollectionContains

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testCollectionContains() {
-  return ImmutableSet.of("foo").stream().anyMatch("bar"::equals);
+  return ImmutableSet.of("foo").contains("bar");
 }

CollectionAddAllToCollectionExpression

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testCollectionAddAllToCollectionExpression() {
-  return Iterables.addAll(new ArrayList<>(), ImmutableSet.of("foo"));
+  return new ArrayList<>().addAll(ImmutableSet.of("foo"));
 }

CollectionAddAllToCollectionBlock

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCollectionAddAllToCollectionBlock() {
-  ImmutableSet.of("foo").forEach(new ArrayList<>()::add);
-  for (Number element : ImmutableSet.of(1)) {
-    new ArrayList<Number>().add(element);
-  }
-  for (Integer element : ImmutableSet.of(2)) {
-    new ArrayList<Number>().add(element);
-  }
+  new ArrayList<>().addAll(ImmutableSet.of("foo"));
+  new ArrayList<Number>().addAll(ImmutableSet.of(1));
+  new ArrayList<Number>().addAll(ImmutableSet.of(2));
 }

CollectionRemoveAllFromCollectionExpression

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testCollectionRemoveAllFromCollectionExpression() {
-  return Iterables.removeAll(new ArrayList<>(), ImmutableSet.of("foo"));
+  return new ArrayList<>().removeAll(ImmutableSet.of("foo"));
 }

CollectionRemoveAllFromCollectionBlock

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCollectionRemoveAllFromCollectionBlock() {
-  ImmutableSet.of("foo").forEach(new HashSet<>()::remove);
-  for (Number element : ImmutableList.of(1)) {
-    new HashSet<Number>().remove(element);
-  }
-  for (Integer element : ImmutableSet.of(2)) {
-    new HashSet<Number>().remove(element);
-  }
+  new HashSet<>().removeAll(ImmutableSet.of("foo"));
+  new HashSet<Number>().removeAll(ImmutableList.of(1));
+  new HashSet<Number>().removeAll(ImmutableSet.of(2));
 }

SetStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<Integer> testSetStream() {
-  return ImmutableSet.of(1).stream().distinct();
+  return ImmutableSet.of(1).stream();
 }

SetOfVarargs

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Set<Integer> testSetOfVarargs() {
-  return Stream.of(1, 2).collect(toUnmodifiableSet());
+  return Set.of(1, 2);
 }

NewArrayListFromCollection

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ArrayList<String> testNewArrayListFromCollection() {
-  return Lists.newArrayList(ImmutableList.of("foo"));
+  return new ArrayList<>(ImmutableList.of("foo"));
 }

ImmutableCollectionStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<Integer> testImmutableCollectionStream() {
-  return ImmutableSet.of(1).asList().stream();
+  return ImmutableSet.of(1).stream();
 }

ImmutableCollectionAsList

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableList<Integer> testImmutableCollectionAsList() {
-  return ImmutableList.copyOf(ImmutableSet.of(1));
+  return ImmutableSet.of(1).asList();
 }

ImmutableCollectionContains

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testImmutableCollectionContains() {
-  return ImmutableSet.of(1).asList().contains("foo");
+  return ImmutableSet.of(1).contains("foo");
 }

ImmutableCollectionParallelStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<Integer> testImmutableCollectionParallelStream() {
-  return ImmutableSet.of(1).asList().parallelStream();
+  return ImmutableSet.of(1).parallelStream();
 }

ImmutableCollectionToString

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testImmutableCollectionToString() {
-  return ImmutableSet.of(1).asList().toString();
+  return ImmutableSet.of(1).toString();
 }

ArraysAsList

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 List<String> testArraysAsList() {
-  return Arrays.stream(new String[0]).toList();
+  return Arrays.asList(new String[0]);
 }

CollectionToArray

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Object[]> testCollectionToArray() {
   return ImmutableSet.of(
-      ImmutableSet.of(1).toArray(new Object[1]),
-      ImmutableSet.of(2).toArray(Object[]::new),
-      ImmutableSet.of(3).asList().toArray());
+      ImmutableSet.of(1).toArray(), ImmutableSet.of(2).toArray(), ImmutableSet.of(3).toArray());
 }

ImmutableCollectionToArrayWithArray

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Integer[] testImmutableCollectionToArrayWithArray() {
-  return ImmutableSet.of(1).asList().toArray(new Integer[0]);
+  return ImmutableSet.of(1).toArray(new Integer[0]);
 }

ImmutableCollectionToArrayWithGenerator

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Integer[] testImmutableCollectionToArrayWithGenerator() {
-  return ImmutableSet.of(1).asList().toArray(Integer[]::new);
+  return ImmutableSet.of(1).toArray(Integer[]::new);
 }

CollectionIterator

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Iterator<Integer>> testCollectionIterator() {
-  return ImmutableSet.of(
-      ImmutableSet.of(1).stream().iterator(), ImmutableSet.of(2).asList().iterator());
+  return ImmutableSet.of(ImmutableSet.of(1).iterator(), ImmutableSet.of(2).iterator());
 }

OptionalFirstCollectionElement

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<Integer>> testOptionalFirstCollectionElement() {
   return ImmutableSet.of(
-      ImmutableSet.of(0).stream().findAny(),
-      ImmutableSet.of(1).isEmpty()
-          ? Optional.empty()
-          : Optional.of(ImmutableSet.of(1).iterator().next()),
-      ImmutableList.of(2).isEmpty()
-          ? Optional.empty()
-          : Optional.of(ImmutableList.of(2).getFirst()),
-      ImmutableSortedSet.of(3).isEmpty()
-          ? Optional.empty()
-          : Optional.of(ImmutableSortedSet.of(3).first()),
-      !ImmutableSet.of(1).isEmpty()
-          ? Optional.of(ImmutableSet.of(1).iterator().next())
-          : Optional.empty(),
-      !ImmutableList.of(2).isEmpty()
-          ? Optional.of(ImmutableList.of(2).getFirst())
-          : Optional.empty(),
-      !ImmutableSortedSet.of(3).isEmpty()
-          ? Optional.of(ImmutableSortedSet.of(3).first())
-          : Optional.empty());
+      ImmutableSet.of(0).stream().findFirst(),
+      ImmutableSet.of(1).stream().findFirst(),
+      ImmutableList.of(2).stream().findFirst(),
+      ImmutableSortedSet.of(3).stream().findFirst(),
+      ImmutableSet.of(1).stream().findFirst(),
+      ImmutableList.of(2).stream().findFirst(),
+      ImmutableSortedSet.of(3).stream().findFirst());
 }

OptionalFirstQueueElement

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testOptionalFirstQueueElement() {
   return ImmutableSet.of(
-      new LinkedList<String>().stream().findFirst(),
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.of(new LinkedList<String>().peek()),
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.ofNullable(new LinkedList<String>().peek()),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.of(new LinkedList<String>().peek())
-          : Optional.empty(),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.ofNullable(new LinkedList<String>().peek())
-          : Optional.empty());
+      Optional.ofNullable(new LinkedList<String>().peek()),
+      Optional.ofNullable(new LinkedList<String>().peek()),
+      Optional.ofNullable(new LinkedList<String>().peek()),
+      Optional.ofNullable(new LinkedList<String>().peek()),
+      Optional.ofNullable(new LinkedList<String>().peek()));
 }

RemoveOptionalFirstNavigableSetElement

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testRemoveOptionalFirstNavigableSetElement() {
   return ImmutableSet.of(
-      new TreeSet<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.of(new TreeSet<String>().pollFirst()),
-      new TreeSet<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.ofNullable(new TreeSet<String>().pollFirst()),
-      !new TreeSet<String>().isEmpty()
-          ? Optional.of(new TreeSet<String>().pollFirst())
-          : Optional.empty(),
-      !new TreeSet<String>().isEmpty()
-          ? Optional.ofNullable(new TreeSet<String>().pollFirst())
-          : Optional.empty());
+      Optional.ofNullable(new TreeSet<String>().pollFirst()),
+      Optional.ofNullable(new TreeSet<String>().pollFirst()),
+      Optional.ofNullable(new TreeSet<String>().pollFirst()),
+      Optional.ofNullable(new TreeSet<String>().pollFirst()));
 }

RemoveOptionalFirstQueueElement

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testRemoveOptionalFirstQueueElement() {
   return ImmutableSet.of(
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.of(new LinkedList<String>().poll()),
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.of(new LinkedList<String>().remove()),
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.ofNullable(new LinkedList<String>().poll()),
-      new LinkedList<String>().isEmpty()
-          ? Optional.empty()
-          : Optional.ofNullable(new LinkedList<String>().remove()),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.of(new LinkedList<String>().poll())
-          : Optional.empty(),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.of(new LinkedList<String>().remove())
-          : Optional.empty(),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.ofNullable(new LinkedList<String>().poll())
-          : Optional.empty(),
-      !new LinkedList<String>().isEmpty()
-          ? Optional.ofNullable(new LinkedList<String>().remove())
-          : Optional.empty());
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()),
+      Optional.ofNullable(new LinkedList<String>().poll()));
 }

CollectionForEach

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCollectionForEach() {
-  ImmutableSet.of(1).stream().forEach(String::valueOf);
+  ImmutableSet.of(1).forEach(String::valueOf);
 }

CollectionIteratorNext

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testCollectionIteratorNext() {
-  return ImmutableSet.of("foo").stream().findFirst().orElseThrow();
+  return ImmutableSet.of("foo").iterator().next();
 }

SequencedCollectionGetFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<String> testSequencedCollectionGetFirst() {
-  return ImmutableSet.of(
-      ImmutableList.of("foo").iterator().next(), ImmutableList.of("bar").get(0));
+  return ImmutableSet.of(ImmutableList.of("foo").getFirst(), ImmutableList.of("bar").getFirst());
 }

SequencedCollectionGetLast

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<String> testSequencedCollectionGetLast() {
   return ImmutableSet.of(
-      ImmutableList.of("foo").reversed().getFirst(),
-      Streams.findLast(ImmutableList.of("bar").stream()).orElseThrow(),
-      ImmutableList.of("baz").get(ImmutableList.of("baz").size() - 1));
+      ImmutableList.of("foo").getLast(),
+      ImmutableList.of("bar").getLast(),
+      ImmutableList.of("baz").getLast());
 }

ListAddFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testListAddFirst() {
-  new ArrayList<String>().add(0, "foo");
+  new ArrayList<String>().addFirst("foo");
 }

ListAdd

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testListAdd() {
-  new ArrayList<String>(0).addLast("bar");
-  new ArrayList<String>(1).add(new ArrayList<String>(1).size(), "qux");
+  new ArrayList<String>(0).add("bar");
+  new ArrayList<String>(1).add("qux");
 }

ListRemoveFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testListRemoveFirst() {
-  return new ArrayList<String>().remove(0);
+  return new ArrayList<String>().removeFirst();
 }

ListRemoveLast

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testListRemoveLast() {
-  return new ArrayList<String>().remove(new ArrayList<String>().size() - 1);
+  return new ArrayList<String>().removeLast();
 }

SortedSetFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testSortedSetFirst() {
-  return ImmutableSortedSet.of("foo").getFirst();
+  return ImmutableSortedSet.of("foo").first();
 }

SortedSetLast

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 String testSortedSetLast() {
-  return ImmutableSortedSet.of("foo").getLast();
+  return ImmutableSortedSet.of("foo").last();
 }

Copyright © 2017-2026 Picnic Technologies BV