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. EqualsLhsNullable
  8. EqualsRhsNullable
  9. EqualsLhsAndRhsNullable

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

EqualsLhsNullable

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testEqualsLhsNullable() {
-    return Optional.ofNullable("foo").equals(Optional.of("bar"));
+    return "bar".equals("foo");
   }

EqualsRhsNullable

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testEqualsRhsNullable() {
-    return Optional.of("foo").equals(Optional.ofNullable("bar"));
+    return "foo".equals("bar");
   }

EqualsLhsAndRhsNullable

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

Copyright © 2017-2023 Picnic Technologies BV