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. EnumReferenceEquality
  2. EnumReferenceEqualityLambda
  3. EqualsPredicate
  4. DoubleNegation
  5. Negation
  6. IndirectDoubleNegation
  7. PredicateLambda
  8. Equals
  9. ObjectsEquals

EnumReferenceEquality

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

EnumReferenceEqualityLambda

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Predicate<RoundingMode>> testEnumReferenceEqualityLambda() {
-  return ImmutableSet.of(isEqual(RoundingMode.DOWN), RoundingMode.UP::equals);
+  return ImmutableSet.of(v -> v == RoundingMode.DOWN, v -> v == RoundingMode.UP);
 }

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