Skip to content

Commit 42b43e5

Browse files
committed
Polishing.
Replace instanceof check with pattern variable in production code. Add missing Deprecated annotations. See #2967 Original pull request: #2971
1 parent 85434a3 commit 42b43e5

25 files changed

+51
-95
lines changed

src/main/java/org/springframework/data/redis/connection/BitFieldSubCommands.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ public boolean equals(@Nullable Object o) {
151151
if (this == o) {
152152
return true;
153153
}
154-
if (!(o instanceof BitFieldSubCommands)) {
154+
if (!(o instanceof BitFieldSubCommands that)) {
155155
return false;
156156
}
157-
BitFieldSubCommands that = (BitFieldSubCommands) o;
158157
return ObjectUtils.nullSafeEquals(subCommands, that.subCommands);
159158
}
160159

@@ -437,10 +436,9 @@ public boolean equals(@Nullable Object o) {
437436
if (this == o) {
438437
return true;
439438
}
440-
if (!(o instanceof Offset)) {
439+
if (!(o instanceof Offset that)) {
441440
return false;
442441
}
443-
Offset that = (Offset) o;
444442
if (offset != that.offset) {
445443
return false;
446444
}
@@ -549,10 +547,9 @@ public boolean equals(@Nullable Object o) {
549547
if (this == o) {
550548
return true;
551549
}
552-
if (!(o instanceof BitFieldType)) {
550+
if (!(o instanceof BitFieldType that)) {
553551
return false;
554552
}
555-
BitFieldType that = (BitFieldType) o;
556553
if (signed != that.signed) {
557554
return false;
558555
}
@@ -597,10 +594,9 @@ public boolean equals(@Nullable Object o) {
597594
if (this == o) {
598595
return true;
599596
}
600-
if (!(o instanceof AbstractBitFieldSubCommand)) {
597+
if (!(o instanceof AbstractBitFieldSubCommand that)) {
601598
return false;
602599
}
603-
AbstractBitFieldSubCommand that = (AbstractBitFieldSubCommand) o;
604600
if (!ObjectUtils.nullSafeEquals(getClass(), that.getClass())) {
605601
return false;
606602
}
@@ -680,13 +676,12 @@ public boolean equals(@Nullable Object o) {
680676
if (this == o) {
681677
return true;
682678
}
683-
if (!(o instanceof BitFieldSet)) {
679+
if (!(o instanceof BitFieldSet that)) {
684680
return false;
685681
}
686682
if (!super.equals(o)) {
687683
return false;
688684
}
689-
BitFieldSet that = (BitFieldSet) o;
690685
if (value != that.value) {
691686
return false;
692687
}
@@ -832,10 +827,9 @@ public boolean equals(@Nullable Object o) {
832827
if (this == o) {
833828
return true;
834829
}
835-
if (!(o instanceof BitFieldIncrBy)) {
830+
if (!(o instanceof BitFieldIncrBy that)) {
836831
return false;
837832
}
838-
BitFieldIncrBy that = (BitFieldIncrBy) o;
839833
if (value != that.value) {
840834
return false;
841835
}

src/main/java/org/springframework/data/redis/connection/RedisSocketConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ public boolean equals(@Nullable Object o) {
108108
if (this == o) {
109109
return true;
110110
}
111-
if (!(o instanceof RedisSocketConfiguration)) {
111+
if (!(o instanceof RedisSocketConfiguration that)) {
112112
return false;
113113
}
114-
RedisSocketConfiguration that = (RedisSocketConfiguration) o;
115114
if (database != that.database) {
116115
return false;
117116
}

src/main/java/org/springframework/data/redis/connection/RedisStandaloneConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ public boolean equals(@Nullable Object o) {
137137
if (this == o) {
138138
return true;
139139
}
140-
if (!(o instanceof RedisStandaloneConfiguration)) {
140+
if (!(o instanceof RedisStandaloneConfiguration that)) {
141141
return false;
142142
}
143-
RedisStandaloneConfiguration that = (RedisStandaloneConfiguration) o;
144143
if (port != that.port) {
145144
return false;
146145
}

src/main/java/org/springframework/data/redis/connection/RedisStaticMasterReplicaConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ public boolean equals(@Nullable Object o) {
159159
if (this == o) {
160160
return true;
161161
}
162-
if (!(o instanceof RedisStaticMasterReplicaConfiguration)) {
162+
if (!(o instanceof RedisStaticMasterReplicaConfiguration that)) {
163163
return false;
164164
}
165-
RedisStaticMasterReplicaConfiguration that = (RedisStaticMasterReplicaConfiguration) o;
166165
if (database != that.database) {
167166
return false;
168167
}

src/main/java/org/springframework/data/redis/connection/RedisStreamCommands.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,9 @@ public boolean equals(@Nullable Object o) {
246246
if (this == o) {
247247
return true;
248248
}
249-
if (!(o instanceof XAddOptions)) {
249+
if (!(o instanceof XAddOptions that)) {
250250
return false;
251251
}
252-
XAddOptions that = (XAddOptions) o;
253252
if (nomkstream != that.nomkstream) {
254253
return false;
255254
}

src/main/java/org/springframework/data/redis/connection/SentinelMasterId.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ public boolean equals(@Nullable Object o) {
5151
if (this == o) {
5252
return true;
5353
}
54-
if (!(o instanceof SentinelMasterId)) {
54+
if (!(o instanceof SentinelMasterId that)) {
5555
return false;
5656
}
57-
SentinelMasterId that = (SentinelMasterId) o;
5857
return ObjectUtils.nullSafeEquals(name, that.name);
5958
}
6059

src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,8 @@ private static GeoSearchParam getGeoSearchParam(GeoShape predicate, GeoSearchPar
748748
return param;
749749
}
750750

751-
if (predicate instanceof BoxShape) {
751+
if (predicate instanceof BoxShape boxPredicate) {
752752

753-
BoxShape boxPredicate = (BoxShape) predicate;
754753
BoundingBox boundingBox = boxPredicate.getBoundingBox();
755754

756755
param.byBox(boundingBox.getWidth().getValue(), boundingBox.getHeight().getValue(),
@@ -770,9 +769,8 @@ private static void configureGeoReference(GeoReference<byte[]> reference, GeoSea
770769
return;
771770
}
772771

773-
if (reference instanceof GeoReference.GeoCoordinateReference) {
772+
if (reference instanceof GeoReference.GeoCoordinateReference<?> coordinates) {
774773

775-
GeoReference.GeoCoordinateReference<?> coordinates = (GeoReference.GeoCoordinateReference<?>) reference;
776774
param.fromLonLat(coordinates.getLongitude(), coordinates.getLatitude());
777775
return;
778776
}

src/main/java/org/springframework/data/redis/connection/jedis/StreamConverters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ static List<Object> mapToList(Map<String, Object> map) {
9696

9797
if (v instanceof StreamEntryID) {
9898
sources.add(v.toString());
99-
} else if (v instanceof StreamEntry) {
99+
} else if (v instanceof StreamEntry streamEntry) {
100100
List<Object> entries = new ArrayList<>(2);
101-
StreamEntry streamEntry = (StreamEntry) v;
102101
entries.add(streamEntry.getID().toString());
103102
entries.add(streamEntry.getFields());
104103
sources.add(entries);

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,8 @@ static GeoSearch.GeoPredicate toGeoPredicate(GeoShape predicate) {
863863
return GeoSearch.byRadius(radius.getValue(), toGeoArgsUnit(radius.getMetric()));
864864
}
865865

866-
if (predicate instanceof BoxShape) {
866+
if (predicate instanceof BoxShape boxPredicate) {
867867

868-
BoxShape boxPredicate = (BoxShape) predicate;
869868
BoundingBox boundingBox = boxPredicate.getBoundingBox();
870869

871870
return GeoSearch.byBox(boundingBox.getWidth().getValue(), boundingBox.getHeight().getValue(),
@@ -881,9 +880,7 @@ static <T> GeoSearch.GeoRef<T> toGeoRef(GeoReference<T> reference) {
881880
return GeoSearch.fromMember(((GeoMemberReference<T>) reference).getMember());
882881
}
883882

884-
if (reference instanceof GeoReference.GeoCoordinateReference) {
885-
886-
GeoCoordinateReference<?> coordinates = (GeoCoordinateReference<?>) reference;
883+
if (reference instanceof GeoCoordinateReference<?> coordinates) {
887884

888885
return GeoSearch.fromCoordinates(coordinates.getLongitude(), coordinates.getLatitude());
889886
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ public void release(StatefulConnection<?, ?> connection) {
165165

166166
private void discardIfNecessary(StatefulConnection<?, ?> connection) {
167167

168-
if (connection instanceof StatefulRedisConnection) {
168+
if (connection instanceof StatefulRedisConnection<?, ?> redisConnection) {
169169

170-
StatefulRedisConnection<?, ?> redisConnection = (StatefulRedisConnection<?, ?>) connection;
171170
if (redisConnection.isMulti()) {
172171
redisConnection.async().discard();
173172
}

0 commit comments

Comments
 (0)