AssortedRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. CheckIndex
  2. CheckIndexConditional
  3. StreamToImmutableEnumSet
  4. IteratorGetNextOrDefault
  5. LogicalImplication
  6. UnboundedSingleElementStream
  7. DisjointSets
  8. DisjointCollections
  9. IterableIsEmpty
  10. SplitToStream

CheckIndex

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 int testCheckIndex() {
-    return Preconditions.checkElementIndex(0, 1);
+    return checkIndex(0, 1);
   }

CheckIndexConditional

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCheckIndexConditional() {
-    if (1 < 0 || 1 >= 2) {
-      throw new IndexOutOfBoundsException();
-    }
+    checkIndex(1, 2);
   }

StreamToImmutableEnumSet

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<BoundType> testStreamToImmutableEnumSet() {
-    return Stream.of(BoundType.OPEN).collect(toImmutableSet());
+    return Stream.of(BoundType.OPEN).collect(toImmutableEnumSet());
   }

IteratorGetNextOrDefault

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<String> testIteratorGetNextOrDefault() {
     return ImmutableSet.of(
-        ImmutableList.of("a").iterator().hasNext()
-            ? ImmutableList.of("a").iterator().next()
-            : "foo",
-        Streams.stream(ImmutableList.of("b").iterator()).findFirst().orElse("bar"),
-        Streams.stream(ImmutableList.of("c").iterator()).findAny().orElse("baz"));
+        Iterators.getNext(ImmutableList.of("a").iterator(), "foo"),
+        Iterators.getNext(ImmutableList.of("b").iterator(), "bar"),
+        Iterators.getNext(ImmutableList.of("c").iterator(), "baz"));
   }

LogicalImplication

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testLogicalImplication() {
     return ImmutableSet.of(
-        toString().isEmpty() || (!toString().isEmpty() && Boolean.TRUE),
+        toString().isEmpty() || Boolean.TRUE,
         !toString().isEmpty() || (toString().isEmpty() && Boolean.TRUE),
         3 < 4 || (3 >= 4 && Boolean.TRUE),
         3 >= 4 || (3 < 4 && Boolean.TRUE));
   }

UnboundedSingleElementStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<String> testUnboundedSingleElementStream() {
-    return Streams.stream(Iterables.cycle("foo"));
+    return Stream.generate(() -> "foo");
   }

DisjointSets

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testDisjointSets() {
     return ImmutableSet.of(
-        Sets.intersection(ImmutableSet.of(1), ImmutableSet.of(2)).isEmpty(),
-        ImmutableSet.of(3).stream().noneMatch(ImmutableSet.of(4)::contains));
+        Collections.disjoint(ImmutableSet.of(1), ImmutableSet.of(2)),
+        Collections.disjoint(ImmutableSet.of(3), ImmutableSet.of(4)));
   }

DisjointCollections

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testDisjointCollections() {
     return ImmutableSet.of(
-        Collections.disjoint(ImmutableSet.copyOf(ImmutableList.of(1)), ImmutableList.of(2)),
-        Collections.disjoint(new HashSet<>(ImmutableList.of(3)), ImmutableList.of(4)),
-        Collections.disjoint(ImmutableList.of(5), ImmutableSet.copyOf(ImmutableList.of(6))),
-        Collections.disjoint(ImmutableList.of(7), new HashSet<>(ImmutableList.of(8))));
+        Collections.disjoint(ImmutableList.of(1), ImmutableList.of(2)),
+        Collections.disjoint(ImmutableList.of(3), ImmutableList.of(4)),
+        Collections.disjoint(ImmutableList.of(5), ImmutableList.of(6)),
+        Collections.disjoint(ImmutableList.of(7), ImmutableList.of(8)));
   }

IterableIsEmpty

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testIterableIsEmpty() {
-    return !ImmutableList.of().iterator().hasNext();
+    return Iterables.isEmpty(ImmutableList.of());
   }

SplitToStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Stream<String>> testSplitToStream() {
     return ImmutableSet.of(
-        Streams.stream(Splitter.on(':').split("foo")),
-        Splitter.on(',').splitToList(new StringBuilder("bar")).stream());
+        Splitter.on(':').splitToStream("foo"),
+        Splitter.on(',').splitToStream(new StringBuilder("bar")));
   }

Copyright © 2017-2024 Picnic Technologies BV