Skip to content

Commit

Permalink
Refactor instanceof to use pattern variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Aug 20, 2024
1 parent 06212b5 commit a389415
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public boolean equals(Object o) {
return true;
}

if (!(o instanceof EscapeCharacter)) {
if (!(o instanceof EscapeCharacter that)) {
return false;
}

EscapeCharacter that = (EscapeCharacter) o;
return escapeCharacter == that.escapeCharacter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@ public Object prepare(@Nullable Object value) {
@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ public boolean equals(Object o) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,10 @@ public boolean equals(Object o) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ public void setManufacturerId(Integer manufacturerId) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ public ItemSiteId(ItemId item, Integer site) {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -29,12 +29,10 @@ public boolean equals(Object obj) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,10 @@ public byte[] getBinaryData() {
@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;
}
Expand Down

0 comments on commit a389415

Please sign in to comment.