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. Disjoint
  5. CollectionAddAllExpression
  6. CollectionAddAllBlock
  7. CollectionRemoveAllExpression
  8. CollectionRemoveAllBlock
  9. SetStream
  10. SetOf
  11. NewArrayList
  12. ImmutableCollectionAsList
  13. ImmutableCollectionStream
  14. ImmutableCollectionContains
  15. ImmutableCollectionParallelStream
  16. ImmutableCollectionToString
  17. ArraysAsList
  18. CollectionToArray
  19. ImmutableCollectionToArrayObject
  20. ImmutableCollectionToArrayIntFunction
  21. CollectionIterator
  22. CollectionStreamFindFirst
  23. OptionalOfNullableQueuePeek
  24. OptionalOfNullableNavigableSetPollFirst
  25. OptionalOfNullableQueuePoll
  26. CollectionForEach
  27. CollectionIteratorNext
  28. SequencedCollectionGetFirst
  29. SequencedCollectionGetLast
  30. ListAddFirst
  31. ListAdd
  32. ListRemoveFirst
  33. ListRemoveLast
  34. SortedSetFirst
  35. 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");
 }

Disjoint

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testDisjoint() {
   return ImmutableSet.of(
-      Sets.intersection(ImmutableSet.of(1), ImmutableSet.of(2)).isEmpty(),
-      ImmutableSet.of(3).stream().noneMatch(ImmutableSet.of(4)::contains),
-      disjoint(ImmutableSet.copyOf(ImmutableList.of(5)), ImmutableList.of(6)),
-      disjoint(new HashSet<>(ImmutableList.of(7)), ImmutableList.of(8)),
-      disjoint(ImmutableList.of(9), ImmutableSet.copyOf(ImmutableList.of(10))),
-      disjoint(ImmutableList.of(11), new HashSet<>(ImmutableList.of(12))));
+      disjoint(ImmutableSet.of(1), ImmutableSet.of(2)),
+      disjoint(ImmutableSet.of(3), ImmutableSet.of(4)),
+      disjoint(ImmutableList.of(5), ImmutableList.of(6)),
+      disjoint(ImmutableList.of(7), ImmutableList.of(8)),
+      disjoint(ImmutableList.of(9), ImmutableList.of(10)),
+      disjoint(ImmutableList.of(11), ImmutableList.of(12)));
 }

CollectionAddAllExpression

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

CollectionAddAllBlock

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCollectionAddAllBlock() {
-  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));
 }

CollectionRemoveAllExpression

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

CollectionRemoveAllBlock

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCollectionRemoveAllBlock() {
-  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();
 }

SetOf

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

NewArrayList

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

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

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

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

ImmutableCollectionToArrayObject

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

ImmutableCollectionToArrayIntFunction

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Integer[] testImmutableCollectionToArrayIntFunction() {
-  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());
 }

CollectionStreamFindFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

OptionalOfNullableQueuePeek

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testOptionalOfNullableQueuePeek() {
   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()));
 }

OptionalOfNullableNavigableSetPollFirst

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testOptionalOfNullableNavigableSetPollFirst() {
   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()));
 }

OptionalOfNullableQueuePoll

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Optional<String>> testOptionalOfNullableQueuePoll() {
   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("foo");
-  new ArrayList<String>(1).add(new ArrayList<String>(1).size(), "bar");
+  new ArrayList<String>(0).add("foo");
+  new ArrayList<String>(1).add("bar");
 }

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