Skip to content

Commit a389415

Browse files
committed
Refactor instanceof to use pattern variable.
Closes #3586
1 parent 06212b5 commit a389415

File tree

8 files changed

+10
-24
lines changed

8 files changed

+10
-24
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EscapeCharacter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ public boolean equals(Object o) {
6969
return true;
7070
}
7171

72-
if (!(o instanceof EscapeCharacter)) {
72+
if (!(o instanceof EscapeCharacter that)) {
7373
return false;
7474
}
7575

76-
EscapeCharacter that = (EscapeCharacter) o;
7776
return escapeCharacter == that.escapeCharacter;
7877
}
7978

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterBinding.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,10 @@ public Object prepare(@Nullable Object value) {
279279
@Override
280280
public boolean equals(Object obj) {
281281

282-
if (!(obj instanceof LikeParameterBinding)) {
282+
if (!(obj instanceof LikeParameterBinding that)) {
283283
return false;
284284
}
285285

286-
LikeParameterBinding that = (LikeParameterBinding) obj;
287-
288286
return super.equals(obj) && this.type.equals(that.type);
289287
}
290288

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ProcedureParameter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ public boolean equals(Object o) {
7777
return true;
7878
}
7979

80-
if (!(o instanceof ProcedureParameter)) {
80+
if (!(o instanceof ProcedureParameter that)) {
8181
return false;
8282
}
8383

84-
ProcedureParameter that = (ProcedureParameter) o;
8584
return Objects.equals(name, that.name) && mode == that.mode && Objects.equals(type, that.type);
8685
}
8786

spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,10 @@ public boolean equals(Object o) {
223223
return true;
224224
}
225225

226-
if (!(o instanceof EntityManagerFactoryBeanDefinition)) {
226+
if (!(o instanceof EntityManagerFactoryBeanDefinition that)) {
227227
return false;
228228
}
229229

230-
EntityManagerFactoryBeanDefinition that = (EntityManagerFactoryBeanDefinition) o;
231-
232230
if (!ObjectUtils.nullSafeEquals(beanName, that.beanName)) {
233231
return false;
234232
}

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/ItemId.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ public void setManufacturerId(Integer manufacturerId) {
5858
public boolean equals(Object o) {
5959
if (this == o)
6060
return true;
61-
if (!(o instanceof ItemId))
61+
if (!(o instanceof ItemId itemId))
6262
return false;
6363

64-
ItemId itemId = (ItemId) o;
65-
6664
if (id != null ? !id.equals(itemId.id) : itemId.id != null)
6765
return false;
6866
return manufacturerId != null ? manufacturerId.equals(itemId.manufacturerId) : itemId.manufacturerId == null;

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/ItemSiteId.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ public ItemSiteId(ItemId item, Integer site) {
4242
public boolean equals(Object o) {
4343
if (this == o)
4444
return true;
45-
if (!(o instanceof ItemSiteId))
45+
if (!(o instanceof ItemSiteId that))
4646
return false;
4747

48-
ItemSiteId that = (ItemSiteId) o;
49-
5048
if (item != null ? !item.equals(that.item) : that.item != null)
5149
return false;
5250
return site != null ? site.equals(that.site) : that.site == null;

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/SampleWithIdClass.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.springframework.data.jpa.domain.sample;
22

3-
import java.io.Serializable;
4-
53
import jakarta.persistence.Access;
64
import jakarta.persistence.AccessType;
75
import jakarta.persistence.Entity;
86
import jakarta.persistence.Id;
97
import jakarta.persistence.IdClass;
108

9+
import java.io.Serializable;
10+
1111
@Entity
1212
@IdClass(SampleWithIdClass.SampleWithIdClassPK.class)
1313
@Access(AccessType.FIELD)
@@ -29,12 +29,10 @@ public boolean equals(Object obj) {
2929
return true;
3030
}
3131

32-
if (!(obj instanceof SampleWithIdClassPK)) {
32+
if (!(obj instanceof SampleWithIdClassPK that)) {
3333
return false;
3434
}
3535

36-
SampleWithIdClassPK that = (SampleWithIdClassPK) obj;
37-
3836
return this.first.equals(that.first) && this.second.equals(that.second);
3937
}
4038

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/User.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,10 @@ public byte[] getBinaryData() {
284284
@Override
285285
public boolean equals(Object obj) {
286286

287-
if (!(obj instanceof User)) {
287+
if (!(obj instanceof User that)) {
288288
return false;
289289
}
290290

291-
User that = (User) obj;
292-
293291
if ((null == this.getId()) || (null == that.getId())) {
294292
return false;
295293
}

0 commit comments

Comments
 (0)