Refactor instanceof to use pattern variable.

Closes #3586
This commit is contained in:
Mark Paluch
2024-08-20 14:11:07 +02:00
parent 1f95c61cba
commit 074bfecb11
8 changed files with 10 additions and 24 deletions

View File

@@ -69,11 +69,10 @@ public final class EscapeCharacter {
return true;
}
if (!(o instanceof EscapeCharacter)) {
if (!(o instanceof EscapeCharacter that)) {
return false;
}
EscapeCharacter that = (EscapeCharacter) o;
return escapeCharacter == that.escapeCharacter;
}

View File

@@ -279,12 +279,10 @@ class ParameterBinding {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof LikeParameterBinding)) {
if (!(obj instanceof LikeParameterBinding that)) {
return false;
}
LikeParameterBinding that = (LikeParameterBinding) obj;
return super.equals(obj) && this.type.equals(that.type);
}

View File

@@ -77,11 +77,10 @@ class ProcedureParameter {
return true;
}
if (!(o instanceof ProcedureParameter)) {
if (!(o instanceof ProcedureParameter that)) {
return false;
}
ProcedureParameter that = (ProcedureParameter) o;
return Objects.equals(name, that.name) && mode == that.mode && Objects.equals(type, that.type);
}

View File

@@ -223,12 +223,10 @@ public final class BeanDefinitionUtils {
return true;
}
if (!(o instanceof EntityManagerFactoryBeanDefinition)) {
if (!(o instanceof EntityManagerFactoryBeanDefinition that)) {
return false;
}
EntityManagerFactoryBeanDefinition that = (EntityManagerFactoryBeanDefinition) o;
if (!ObjectUtils.nullSafeEquals(beanName, that.beanName)) {
return false;
}

View File

@@ -58,11 +58,9 @@ public class ItemId implements Serializable {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ItemId))
if (!(o instanceof ItemId itemId))
return false;
ItemId itemId = (ItemId) o;
if (id != null ? !id.equals(itemId.id) : itemId.id != null)
return false;
return manufacturerId != null ? manufacturerId.equals(itemId.manufacturerId) : itemId.manufacturerId == null;

View File

@@ -42,11 +42,9 @@ public class ItemSiteId implements Serializable {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ItemSiteId))
if (!(o instanceof ItemSiteId that))
return false;
ItemSiteId that = (ItemSiteId) o;
if (item != null ? !item.equals(that.item) : that.item != null)
return false;
return site != null ? site.equals(that.site) : that.site == null;

View File

@@ -1,13 +1,13 @@
package org.springframework.data.jpa.domain.sample;
import java.io.Serializable;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import java.io.Serializable;
@Entity
@IdClass(SampleWithIdClass.SampleWithIdClassPK.class)
@Access(AccessType.FIELD)
@@ -29,12 +29,10 @@ public class SampleWithIdClass {
return true;
}
if (!(obj instanceof SampleWithIdClassPK)) {
if (!(obj instanceof SampleWithIdClassPK that)) {
return false;
}
SampleWithIdClassPK that = (SampleWithIdClassPK) obj;
return this.first.equals(that.first) && this.second.equals(that.second);
}

View File

@@ -262,12 +262,10 @@ public class User {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof User)) {
if (!(obj instanceof User that)) {
return false;
}
User that = (User) obj;
if ((null == this.getId()) || (null == that.getId())) {
return false;
}