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
}

src/main/java/org/springframework/data/redis/connection/zset/DefaultTuple.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ public boolean equals(@Nullable Object obj) {
5858
return true;
5959
if (obj == null)
6060
return false;
61-
if (!(obj instanceof DefaultTuple))
61+
if (!(obj instanceof DefaultTuple other))
6262
return false;
63-
DefaultTuple other = (DefaultTuple) obj;
6463
if (score == null) {
6564
if (other.score != null)
6665
return false;

src/main/java/org/springframework/data/redis/connection/zset/Weights.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ public boolean equals(@Nullable Object o) {
151151
return true;
152152
}
153153

154-
if (!(o instanceof Weights)) {
154+
if (!(o instanceof Weights that)) {
155155
return false;
156156
}
157157

158-
Weights that = (Weights) o;
159158
return ObjectUtils.nullSafeEquals(this.weights, that.weights);
160159
}
161160

src/main/java/org/springframework/data/redis/core/BoundSetOperations.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
185185
* @deprecated since 3.0, use {@link #difference(Object)} instead to follow a consistent method naming scheme.
186186
*/
187187
@Nullable
188+
@Deprecated(since = "3.0")
188189
default Set<V> diff(K key) {
189190
return difference(key);
190191
}
@@ -209,6 +210,7 @@ default Set<V> diff(K key) {
209210
* @deprecated since 3.0, use {@link #difference(Collection)} instead to follow a consistent method naming scheme.
210211
*/
211212
@Nullable
213+
@Deprecated(since = "3.0")
212214
default Set<V> diff(Collection<K> keys) {
213215
return difference(keys);
214216
}

src/main/java/org/springframework/data/redis/core/convert/GeoIndexedPropertyValue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ public boolean equals(@Nullable Object o) {
7474
return true;
7575
}
7676

77-
if (!(o instanceof GeoIndexedPropertyValue)) {
77+
if (!(o instanceof GeoIndexedPropertyValue that)) {
7878
return false;
7979
}
8080

81-
GeoIndexedPropertyValue that = (GeoIndexedPropertyValue) o;
8281
if (!ObjectUtils.nullSafeEquals(keyspace, that.keyspace)) {
8382
return false;
8483
}

src/main/java/org/springframework/data/redis/core/index/RedisIndexDefinition.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ public boolean equals(@Nullable Object obj) {
105105
if (obj == null) {
106106
return false;
107107
}
108-
if (!(obj instanceof RedisIndexDefinition)) {
108+
if (!(obj instanceof RedisIndexDefinition that)) {
109109
return false;
110110
}
111-
RedisIndexDefinition that = (RedisIndexDefinition) obj;
112111

113112
if (!ObjectUtils.nullSafeEquals(this.keyspace, that.keyspace)) {
114113
return false;

src/main/java/org/springframework/data/redis/domain/geo/BoundingBox.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.springframework.data.geo.Distance;
1919
import org.springframework.data.geo.Metric;
2020
import org.springframework.data.geo.Shape;
21-
import org.springframework.data.redis.connection.RedisGeoCommands;
2221
import org.springframework.lang.Nullable;
2322
import org.springframework.util.Assert;
2423
import org.springframework.util.ObjectUtils;
@@ -94,10 +93,9 @@ public boolean equals(@Nullable Object o) {
9493
if (this == o) {
9594
return true;
9695
}
97-
if (!(o instanceof BoundingBox)) {
96+
if (!(o instanceof BoundingBox that)) {
9897
return false;
9998
}
100-
BoundingBox that = (BoundingBox) o;
10199
if (!ObjectUtils.nullSafeEquals(width, that.width)) {
102100
return false;
103101
}

src/main/java/org/springframework/data/redis/domain/geo/GeoLocation.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.redis.domain.geo;
1717

1818
import org.springframework.data.geo.Point;
19-
import org.springframework.data.redis.connection.RedisGeoCommands;
2019
import org.springframework.lang.Nullable;
2120
import org.springframework.util.ObjectUtils;
2221

@@ -49,12 +48,10 @@ public boolean equals(@Nullable Object o) {
4948
return true;
5049
}
5150

52-
if (!(o instanceof GeoLocation)) {
51+
if (!(o instanceof GeoLocation<?> that)) {
5352
return false;
5453
}
5554

56-
GeoLocation<?> that = (GeoLocation<?>) o;
57-
5855
if (!ObjectUtils.nullSafeEquals(name, that.name)) {
5956
return false;
6057
}

src/main/java/org/springframework/data/redis/domain/geo/GeoReference.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ public boolean equals(@Nullable Object o) {
133133
if (this == o) {
134134
return true;
135135
}
136-
if (!(o instanceof GeoReference.GeoMemberReference)) {
136+
if (!(o instanceof GeoMemberReference<?> that)) {
137137
return false;
138138
}
139-
GeoMemberReference<?> that = (GeoMemberReference<?>) o;
140139
return ObjectUtils.nullSafeEquals(member, that.member);
141140
}
142141

@@ -178,10 +177,9 @@ public boolean equals(@Nullable Object o) {
178177
if (this == o) {
179178
return true;
180179
}
181-
if (!(o instanceof GeoReference.GeoCoordinateReference)) {
180+
if (!(o instanceof GeoCoordinateReference<?> that)) {
182181
return false;
183182
}
184-
GeoCoordinateReference<?> that = (GeoCoordinateReference<?>) o;
185183
if (longitude != that.longitude) {
186184
return false;
187185
}

src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,12 @@
1515
*/
1616
package org.springframework.data.redis.hash;
1717

18-
import static com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping.EVERYTHING;
18+
import static com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping.*;
1919

2020
import java.io.IOException;
2121
import java.text.ParseException;
22-
import java.util.ArrayList;
23-
import java.util.Arrays;
24-
import java.util.Calendar;
25-
import java.util.Collections;
26-
import java.util.Date;
27-
import java.util.HashMap;
28-
import java.util.Iterator;
29-
import java.util.LinkedHashMap;
30-
import java.util.LinkedHashSet;
31-
import java.util.List;
32-
import java.util.Map;
22+
import java.util.*;
3323
import java.util.Map.Entry;
34-
import java.util.Set;
3524

3625
import org.springframework.data.mapping.MappingException;
3726
import org.springframework.data.redis.support.collections.CollectionUtils;
@@ -379,13 +368,11 @@ private void doFlatten(String propertyPrefix, Iterator<Entry<String, JsonNode>>
379368

380369
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) {
381370

382-
if (!(source instanceof JsonNode)) {
371+
if (!(source instanceof JsonNode element)) {
383372
resultMap.put(propertyPrefix, source);
384373
return;
385374
}
386375

387-
JsonNode element = (JsonNode) source;
388-
389376
if (element.isArray()) {
390377

391378
Iterator<JsonNode> nodes = element.elements();

0 commit comments

Comments
 (0)