EqualityRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. PrimitiveOrReferenceEquality
  2. EqualsPredicate
  3. DoubleNegation
  4. Negation
  5. IndirectDoubleNegation
  6. PredicateLambda
  7. Equals
  8. ObjectsEquals

PrimitiveOrReferenceEquality

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testPrimitiveOrReferenceEquality() {
     return ImmutableSet.of(
-        RoundingMode.UP.equals(RoundingMode.DOWN),
-        Objects.equals(RoundingMode.UP, RoundingMode.DOWN),
-        !RoundingMode.UP.equals(RoundingMode.DOWN),
-        !Objects.equals(RoundingMode.UP, RoundingMode.DOWN));
+        RoundingMode.UP == RoundingMode.DOWN,
+        RoundingMode.UP == RoundingMode.DOWN,
+        RoundingMode.UP != RoundingMode.DOWN,
+        RoundingMode.UP != RoundingMode.DOWN);
   }

EqualsPredicate

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testEqualsPredicate() {
     // XXX: When boxing is involved this rule seems to break. Example:
     // Stream.of(1).anyMatch(e -> Integer.MIN_VALUE.equals(e));
-    return Stream.of("foo").anyMatch(s -> "bar".equals(s));
+    return Stream.of("foo").anyMatch("bar"::equals);
   }

DoubleNegation

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testDoubleNegation() {
-    return !!Boolean.TRUE;
+    return Boolean.TRUE;
   }

Negation

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 @SuppressWarnings("SimplifyBooleanExpression")
   ImmutableSet<Boolean> testNegation() {
     return ImmutableSet.of(
-        true ? !false : false,
-        !(true == false),
-        !((byte) 3 == (byte) 4),
-        !((char) 3 == (char) 4),
-        !((short) 3 == (short) 4),
-        !(3 == 4),
-        !(3L == 4L),
-        !(3F == 4F),
-        !(3.0 == 4.0),
-        !(BoundType.OPEN == BoundType.CLOSED));
+        true != false,
+        true != false,
+        (byte) 3 != (byte) 4,
+        (char) 3 != (char) 4,
+        (short) 3 != (short) 4,
+        3 != 4,
+        3L != 4L,
+        3F != 4F,
+        3.0 != 4.0,
+        BoundType.OPEN != BoundType.CLOSED);
   }

IndirectDoubleNegation

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 @SuppressWarnings("SimplifyBooleanExpression")
   ImmutableSet<Boolean> testIndirectDoubleNegation() {
     return ImmutableSet.of(
-        true ? false : !false,
-        !(true != false),
-        !((byte) 3 != (byte) 4),
-        !((char) 3 != (char) 4),
-        !((short) 3 != (short) 4),
-        !(3 != 4),
-        !(3L != 4L),
-        !(3F != 4F),
-        !(3.0 != 4.0),
-        !(BoundType.OPEN != BoundType.CLOSED));
+        true == false,
+        true == false,
+        (byte) 3 == (byte) 4,
+        (char) 3 == (char) 4,
+        (short) 3 == (short) 4,
+        3 == 4,
+        3L == 4L,
+        3F == 4F,
+        3.0 == 4.0,
+        BoundType.OPEN == BoundType.CLOSED);
   }

PredicateLambda

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Predicate<String> testPredicateLambda() {
-    return not(v -> v.isEmpty());
+    return v -> !v.isEmpty();
   }

Equals

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testEquals() {
-    return ImmutableSet.of(
-        Optional.of("foo").equals(Optional.of("bar")),
-        Optional.of("baz").equals(Optional.ofNullable("qux")),
-        Optional.ofNullable("quux").equals(Optional.of("quuz")));
+    return ImmutableSet.of("foo".equals("bar"), "baz".equals("qux"), "quuz".equals("quux"));
   }

ObjectsEquals

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testObjectsEquals() {
-    return Optional.ofNullable("foo").equals(Optional.ofNullable("bar"));
+    return Objects.equals("foo", "bar");
   }

Copyright © 2017-2024 Picnic Technologies BV