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. EqualToWithEnum
  2. EqualTo
  3. ObjectEquals
  4. BooleanIdentity
  5. NotEqualTo
  6. EqualToWithBoolean
  7. Not
  8. ObjectEqualsWithObject
  9. ObjectsEquals

EqualToWithEnum

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testEqualToWithEnum() {
   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);
 }

EqualTo

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

ObjectEquals

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testObjectEquals() {
   // 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);
 }

BooleanIdentity

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

NotEqualTo

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 @SuppressWarnings("SimplifyBooleanExpression" /* Tests use dummy expressions. */)
 ImmutableSet<Boolean> testNotEqualTo() {
   return ImmutableSet.of(
-      !(true == false),
-      true ? !false : 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);
 }

EqualToWithBoolean

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 @SuppressWarnings("SimplifyBooleanExpression" /* Tests use dummy expressions. */)
 ImmutableSet<Boolean> testEqualToWithBoolean() {
   return ImmutableSet.of(
-      !(true != false),
-      true ? false : !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);
 }

Not

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

ObjectEqualsWithObject

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testObjectEqualsWithObject() {
-  return ImmutableSet.of(
-      Optional.of("foo").equals(Optional.of("bar")),
-      Optional.of("baz").equals(Optional.ofNullable("qux")),
-      Optional.ofNullable("quux").equals(Optional.of("corge")));
+  return ImmutableSet.of("foo".equals("bar"), "baz".equals("qux"), "corge".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-2026 Picnic Technologies BV