committed by
Mark Paluch
parent
f28bf61142
commit
85e9ae50ff
@@ -23,7 +23,6 @@ import java.util.function.IntFunction;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -35,19 +34,10 @@ import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.convert.ListConverter;
|
||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessages;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.*;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoConsumers;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.stream.StringRecord;
|
||||
import org.springframework.data.redis.connection.zset.Aggregate;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
@@ -3046,8 +3036,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(converter instanceof ListConverter) && value instanceof List) {
|
||||
return (T) new ListConverter<>(converter).convert((List) value);
|
||||
if (!(converter instanceof ListConverter) && value instanceof List list) {
|
||||
return (T) new ListConverter<>(converter).convert(list);
|
||||
}
|
||||
|
||||
return value == null ? null
|
||||
|
||||
@@ -274,12 +274,10 @@ public class RedisNode implements NamedNode {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || !(obj instanceof RedisNode)) {
|
||||
if (obj == null || !(obj instanceof RedisNode other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RedisNode other = (RedisNode) obj;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(this.host, other.host)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -421,17 +421,16 @@ public abstract class Converters {
|
||||
if (source instanceof String) {
|
||||
return source.toString();
|
||||
}
|
||||
if (source instanceof byte[]) {
|
||||
return new String((byte[]) source);
|
||||
if (source instanceof byte[] bytes) {
|
||||
return new String(bytes);
|
||||
}
|
||||
if (source instanceof ByteBuffer) {
|
||||
return new String(ByteUtils.getBytes((ByteBuffer) source));
|
||||
if (source instanceof ByteBuffer byteBuffer) {
|
||||
return new String(ByteUtils.getBytes(byteBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
if (ClassUtils.isAssignable(List.class, targetType) && source instanceof List) {
|
||||
if (ClassUtils.isAssignable(List.class, targetType) && source instanceof List<?> sourceCollection) {
|
||||
|
||||
List<Object> sourceCollection = (List<Object>) source;
|
||||
List<Object> targetList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < sourceCollection.size(); i++) {
|
||||
@@ -441,9 +440,8 @@ public abstract class Converters {
|
||||
return targetList;
|
||||
}
|
||||
|
||||
if (ClassUtils.isAssignable(Map.class, targetType) && source instanceof List) {
|
||||
if (ClassUtils.isAssignable(Map.class, targetType) && source instanceof List<?> sourceCollection) {
|
||||
|
||||
List<Object> sourceCollection = ((List<Object>) source);
|
||||
Map<String, Object> targetMap = new LinkedHashMap<>();
|
||||
|
||||
for (int i = 0; i < sourceCollection.size(); i = i + 2) {
|
||||
|
||||
@@ -58,9 +58,8 @@ public class TransactionResultConverter<T> implements Converter<List<Object>, Li
|
||||
|
||||
for (Object result : execResults) {
|
||||
FutureResult<T> futureResult = txResults.remove();
|
||||
if (result instanceof Exception) {
|
||||
if (result instanceof Exception source) {
|
||||
|
||||
Exception source = (Exception) result;
|
||||
DataAccessException convertedException = exceptionConverter.convert(source);
|
||||
throw convertedException != null ? convertedException
|
||||
: new RedisSystemException("Error reading future result", source);
|
||||
|
||||
@@ -88,8 +88,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import redis.clients.jedis.util.SafeEncoder;
|
||||
|
||||
/**
|
||||
* Jedis type converters.
|
||||
*
|
||||
@@ -470,16 +468,16 @@ abstract class JedisConverters extends Converters {
|
||||
byte[] prefix = boundary.isInclusive() ? inclPrefix : exclPrefix;
|
||||
byte[] value = null;
|
||||
Object theValue = boundary.getValue().get();
|
||||
if (theValue instanceof byte[]) {
|
||||
value = (byte[]) theValue;
|
||||
} else if (theValue instanceof Double) {
|
||||
value = toBytes((Double) theValue);
|
||||
} else if (theValue instanceof Long) {
|
||||
value = toBytes((Long) theValue);
|
||||
} else if (theValue instanceof Integer) {
|
||||
value = toBytes((Integer) theValue);
|
||||
} else if (theValue instanceof String) {
|
||||
value = toBytes((String) theValue);
|
||||
if (theValue instanceof byte[] bytes) {
|
||||
value = bytes;
|
||||
} else if (theValue instanceof Double doubleValue) {
|
||||
value = toBytes(doubleValue);
|
||||
} else if (theValue instanceof Long longValue) {
|
||||
value = toBytes(longValue);
|
||||
} else if (theValue instanceof Integer integer) {
|
||||
value = toBytes(integer);
|
||||
} else if (theValue instanceof String string) {
|
||||
value = toBytes(string);
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue()));
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ public class JedisExceptionConverter implements Converter<Exception, DataAccessE
|
||||
|
||||
public DataAccessException convert(Exception ex) {
|
||||
|
||||
if (ex instanceof DataAccessException) {
|
||||
return (DataAccessException) ex;
|
||||
if (ex instanceof DataAccessException dataAccessException) {
|
||||
return dataAccessException;
|
||||
}
|
||||
|
||||
if (ex instanceof UnsupportedOperationException) {
|
||||
@@ -57,10 +57,10 @@ public class JedisExceptionConverter implements Converter<Exception, DataAccessE
|
||||
return new TooManyClusterRedirectionsException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
if (ex instanceof JedisRedirectionException) {
|
||||
if (ex instanceof JedisRedirectionException redirectionException) {
|
||||
|
||||
JedisRedirectionException re = (JedisRedirectionException) ex;
|
||||
return new ClusterRedirectException(re.getSlot(), re.getTargetNode().getHost(), re.getTargetNode().getPort(), ex);
|
||||
return new ClusterRedirectException(redirectionException.getSlot(),
|
||||
redirectionException.getTargetNode().getHost(), redirectionException.getTargetNode().getPort(), ex);
|
||||
}
|
||||
|
||||
if (ex instanceof JedisConnectionException) {
|
||||
|
||||
@@ -39,9 +39,9 @@ public class JedisScriptReturnConverter implements Converter<Object, Object> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(@Nullable Object result) {
|
||||
if (result instanceof String) {
|
||||
if (result instanceof String stringResult) {
|
||||
// evalsha converts byte[] to String. Convert back for consistency
|
||||
return SafeEncoder.encode((String) result);
|
||||
return SafeEncoder.encode(stringResult);
|
||||
}
|
||||
if (returnType == ReturnType.STATUS) {
|
||||
return JedisConverters.toString((byte[]) result);
|
||||
@@ -57,10 +57,10 @@ public class JedisScriptReturnConverter implements Converter<Object, Object> {
|
||||
List<Object> resultList = (List<Object>) result;
|
||||
List<Object> convertedResults = new ArrayList<>();
|
||||
for (Object res : resultList) {
|
||||
if (res instanceof String) {
|
||||
if (res instanceof String stringResult) {
|
||||
// evalsha converts byte[] to String. Convert back for
|
||||
// consistency
|
||||
convertedResults.add(SafeEncoder.encode((String) res));
|
||||
convertedResults.add(SafeEncoder.encode(stringResult));
|
||||
} else {
|
||||
convertedResults.add(res);
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ public class LettuceExceptionConverter implements Converter<Exception, DataAcces
|
||||
|
||||
if (ex instanceof ExecutionException || ex instanceof RedisCommandExecutionException) {
|
||||
|
||||
if (ex.getCause() != ex && ex.getCause() instanceof Exception) {
|
||||
return convert((Exception) ex.getCause());
|
||||
if (ex.getCause() != ex && ex.getCause() instanceof Exception cause) {
|
||||
return convert(cause);
|
||||
}
|
||||
return new RedisSystemException("Error in execution", ex);
|
||||
}
|
||||
|
||||
if (ex instanceof DataAccessException) {
|
||||
return (DataAccessException) ex;
|
||||
if (ex instanceof DataAccessException dataAccessException) {
|
||||
return dataAccessException;
|
||||
}
|
||||
|
||||
if (ex instanceof RedisCommandInterruptedException) {
|
||||
|
||||
@@ -134,8 +134,8 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
|
||||
if (returnType == ReturnType.MULTI) {
|
||||
List resultList = (List) source;
|
||||
for (Object obj : resultList) {
|
||||
if (obj instanceof Exception) {
|
||||
throw connection.convertLettuceAccessException((Exception) obj);
|
||||
if (obj instanceof Exception ex) {
|
||||
throw connection.convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class LettuceSubscription extends AbstractSubscription {
|
||||
|
||||
this.connection = pubsubConnection;
|
||||
this.listener = new LettuceMessageListener(listener,
|
||||
listener instanceof SubscriptionListener ? (SubscriptionListener) listener
|
||||
listener instanceof SubscriptionListener subscriptionListener ? subscriptionListener
|
||||
: SubscriptionListener.NO_OP_SUBSCRIPTION_LISTENER);
|
||||
this.connectionProvider = connectionProvider;
|
||||
this.pubsub = connection.sync();
|
||||
|
||||
@@ -135,7 +135,7 @@ class StreamConverters {
|
||||
|
||||
if (value instanceof ByteBuffer || value instanceof byte[]) {
|
||||
|
||||
byte[] targetArray = value instanceof ByteBuffer ? ByteUtils.getBytes((ByteBuffer) value) : (byte[]) value;
|
||||
byte[] targetArray = value instanceof ByteBuffer byteBuffer ? ByteUtils.getBytes(byteBuffer) : (byte[]) value;
|
||||
String tmp = LettuceConverters.toString(targetArray);
|
||||
|
||||
try {
|
||||
@@ -144,9 +144,9 @@ class StreamConverters {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
if (value instanceof List) {
|
||||
if (value instanceof List listValue) {
|
||||
List<Object> targetList = new ArrayList<>();
|
||||
for (Object it : (List) value) {
|
||||
for (Object it : listValue) {
|
||||
targetList.add(preConvertNativeValues(it));
|
||||
}
|
||||
return targetList;
|
||||
|
||||
@@ -41,8 +41,8 @@ public class ByteArrayWrapper implements Comparable<ByteArrayWrapper> {
|
||||
}
|
||||
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof ByteArrayWrapper) {
|
||||
return Arrays.equals(array, ((ByteArrayWrapper) obj).array);
|
||||
if (obj instanceof ByteArrayWrapper byteArrayWrapper) {
|
||||
return Arrays.equals(array, byteArrayWrapper.array);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -106,8 +106,8 @@ abstract class AbstractOperations<K, V> {
|
||||
|
||||
Assert.notNull(key, "non null key required");
|
||||
|
||||
if (keySerializer() == null && key instanceof byte[]) {
|
||||
return (byte[]) key;
|
||||
if (keySerializer() == null && key instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
return keySerializer().serialize(key);
|
||||
@@ -121,8 +121,8 @@ abstract class AbstractOperations<K, V> {
|
||||
@SuppressWarnings("unchecked")
|
||||
byte[] rawValue(Object value) {
|
||||
|
||||
if (valueSerializer() == null && value instanceof byte[]) {
|
||||
return (byte[]) value;
|
||||
if (valueSerializer() == null && value instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
return valueSerializer().serialize(value);
|
||||
@@ -161,8 +161,8 @@ abstract class AbstractOperations<K, V> {
|
||||
@SuppressWarnings("unchecked")
|
||||
<HK> byte[] rawHashKey(HK hashKey) {
|
||||
Assert.notNull(hashKey, "non null hash key required");
|
||||
if (hashKeySerializer() == null && hashKey instanceof byte[]) {
|
||||
return (byte[]) hashKey;
|
||||
if (hashKeySerializer() == null && hashKey instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
return hashKeySerializer().serialize(hashKey);
|
||||
}
|
||||
@@ -180,8 +180,8 @@ abstract class AbstractOperations<K, V> {
|
||||
@SuppressWarnings("unchecked")
|
||||
<HV> byte[] rawHashValue(HV value) {
|
||||
|
||||
if (hashValueSerializer() == null && value instanceof byte[]) {
|
||||
return (byte[]) value;
|
||||
if (hashValueSerializer() == null && value instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
return hashValueSerializer().serialize(value);
|
||||
}
|
||||
@@ -268,8 +268,8 @@ abstract class AbstractOperations<K, V> {
|
||||
Set<Tuple> rawTuples = new LinkedHashSet<>(values.size());
|
||||
for (TypedTuple<V> value : values) {
|
||||
byte[] rawValue;
|
||||
if (valueSerializer() == null && value.getValue() instanceof byte[]) {
|
||||
rawValue = (byte[]) value.getValue();
|
||||
if (valueSerializer() == null && value.getValue() instanceof byte[] bytes) {
|
||||
rawValue = bytes;
|
||||
} else {
|
||||
rawValue = valueSerializer().serialize(value.getValue());
|
||||
}
|
||||
|
||||
@@ -64,9 +64,8 @@ public class DefaultTypedTuple<V> implements TypedTuple<V> {
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof DefaultTypedTuple))
|
||||
if (!(obj instanceof DefaultTypedTuple<?> other))
|
||||
return false;
|
||||
DefaultTypedTuple<?> other = (DefaultTypedTuple<?>) obj;
|
||||
if (score == null) {
|
||||
if (other.score != null)
|
||||
return false;
|
||||
@@ -75,11 +74,11 @@ public class DefaultTypedTuple<V> implements TypedTuple<V> {
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (value instanceof byte[]) {
|
||||
if (!(other.value instanceof byte[])) {
|
||||
} else if (value instanceof byte[] bytes) {
|
||||
if (!(other.value instanceof byte[] otherBytes)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals((byte[]) value, (byte[]) other.value);
|
||||
return Arrays.equals(bytes, otherBytes);
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
@@ -28,8 +28,8 @@ class GeoOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForGeo());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForGeo());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.beans.PropertyEditorSupport;
|
||||
class HashOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForHash());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForHash());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -208,9 +208,9 @@ class IndexWriter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexedData instanceof SimpleIndexedPropertyValue) {
|
||||
if (indexedData instanceof SimpleIndexedPropertyValue simpleIndexedData) {
|
||||
|
||||
Object value = ((SimpleIndexedPropertyValue) indexedData).getValue();
|
||||
Object value = simpleIndexedData.getValue();
|
||||
|
||||
if (value == null) {
|
||||
return;
|
||||
@@ -222,9 +222,7 @@ class IndexWriter {
|
||||
|
||||
// keep track of indexes used for the object
|
||||
connection.sAdd(ByteUtils.concatAll(toBytes(indexedData.getKeyspace() + ":"), key, toBytes(":idx")), indexKey);
|
||||
} else if (indexedData instanceof GeoIndexedPropertyValue) {
|
||||
|
||||
GeoIndexedPropertyValue geoIndexedData = ((GeoIndexedPropertyValue) indexedData);
|
||||
} else if (indexedData instanceof GeoIndexedPropertyValue geoIndexedData) {
|
||||
|
||||
Object value = geoIndexedData.getValue();
|
||||
if (value == null) {
|
||||
@@ -248,8 +246,8 @@ class IndexWriter {
|
||||
return new byte[] {};
|
||||
}
|
||||
|
||||
if (source instanceof byte[]) {
|
||||
return (byte[]) source;
|
||||
if (source instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
if (converter.getConversionService().canConvert(source.getClass(), byte[].class)) {
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.beans.PropertyEditorSupport;
|
||||
class ListOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForList());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForList());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -305,8 +305,8 @@ public abstract class RedisConnectionUtils {
|
||||
|
||||
RedisConnection connectionToUse = connection;
|
||||
|
||||
while (connectionToUse instanceof RedisConnectionProxy) {
|
||||
connectionToUse = ((RedisConnectionProxy) connectionToUse).getTargetConnection();
|
||||
while (connectionToUse instanceof RedisConnectionProxy redisConnectionProxy) {
|
||||
connectionToUse = redisConnectionProxy.getTargetConnection();
|
||||
}
|
||||
|
||||
return connectionToUse;
|
||||
|
||||
@@ -571,8 +571,8 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
*/
|
||||
public byte[] toBytes(Object source) {
|
||||
|
||||
if (source instanceof byte[]) {
|
||||
return (byte[]) source;
|
||||
if (source instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
return converter.getConversionService().convert(source, byte[].class);
|
||||
|
||||
@@ -152,8 +152,8 @@ public class RedisKeyValueTemplate extends KeyValueTemplate {
|
||||
@Override
|
||||
public <T> T update(T objectToUpdate) {
|
||||
|
||||
if (objectToUpdate instanceof PartialUpdate) {
|
||||
doPartialUpdate((PartialUpdate<?>) objectToUpdate);
|
||||
if (objectToUpdate instanceof PartialUpdate<?> partialUpdate) {
|
||||
doPartialUpdate(partialUpdate);
|
||||
|
||||
return objectToUpdate;
|
||||
}
|
||||
|
||||
@@ -1056,8 +1056,8 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
@SuppressWarnings("unchecked")
|
||||
private byte[] rawKey(Object key) {
|
||||
Assert.notNull(key, "non null key required");
|
||||
if (keySerializer == null && key instanceof byte[]) {
|
||||
return (byte[]) key;
|
||||
if (keySerializer == null && key instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
return keySerializer.serialize(key);
|
||||
}
|
||||
@@ -1068,8 +1068,8 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private byte[] rawValue(Object value) {
|
||||
if (valueSerializer == null && value instanceof byte[]) {
|
||||
return (byte[]) value;
|
||||
if (valueSerializer == null && value instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
return valueSerializer.serialize(value);
|
||||
}
|
||||
@@ -1103,16 +1103,15 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
List<Object> values = new ArrayList<>();
|
||||
for (Object rawValue : rawValues) {
|
||||
|
||||
if (rawValue instanceof byte[] && valueSerializer != null) {
|
||||
values.add(valueSerializer.deserialize((byte[]) rawValue));
|
||||
} else if (rawValue instanceof List) {
|
||||
if (rawValue instanceof byte[] bytes && valueSerializer != null) {
|
||||
values.add(valueSerializer.deserialize(bytes));
|
||||
} else if (rawValue instanceof List list) {
|
||||
// Lists are the only potential Collections of mixed values....
|
||||
values.add(deserializeMixedResults((List) rawValue, valueSerializer, hashKeySerializer, hashValueSerializer));
|
||||
} else if (rawValue instanceof Set && !(((Set) rawValue).isEmpty())) {
|
||||
values.add(deserializeSet((Set) rawValue, valueSerializer));
|
||||
} else if (rawValue instanceof Map && !(((Map) rawValue).isEmpty())
|
||||
&& ((Map) rawValue).values().iterator().next() instanceof byte[]) {
|
||||
values.add(SerializationUtils.deserialize((Map) rawValue, hashKeySerializer, hashValueSerializer));
|
||||
values.add(deserializeMixedResults(list, valueSerializer, hashKeySerializer, hashValueSerializer));
|
||||
} else if (rawValue instanceof Set set && !(set.isEmpty())) {
|
||||
values.add(deserializeSet(set, valueSerializer));
|
||||
} else if (rawValue instanceof Map map && !(map.isEmpty()) && map.values().iterator().next() instanceof byte[]) {
|
||||
values.add(SerializationUtils.deserialize(map, hashKeySerializer, hashValueSerializer));
|
||||
} else {
|
||||
values.add(rawValue);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.beans.PropertyEditorSupport;
|
||||
class SetOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForSet());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForSet());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.beans.PropertyEditorSupport;
|
||||
class ValueOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForValue());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForValue());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.beans.PropertyEditorSupport;
|
||||
class ZSetOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForZSet());
|
||||
if (value instanceof RedisOperations<?, ?> redisOperations) {
|
||||
super.setValue(redisOperations.opsForZSet());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ public class DefaultRedisTypeMapper extends DefaultTypeMapper<BucketPropertyPath
|
||||
|
||||
if (typeKey != null) {
|
||||
|
||||
if (alias instanceof byte[]) {
|
||||
sink.put(typeKey, (byte[]) alias);
|
||||
if (alias instanceof byte[] aliasBytes) {
|
||||
sink.put(typeKey, aliasBytes);
|
||||
} else {
|
||||
sink.put(typeKey, conversionService.convert(alias, byte[].class));
|
||||
}
|
||||
|
||||
@@ -16,17 +16,8 @@
|
||||
package org.springframework.data.redis.core.convert;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -609,8 +600,8 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value instanceof byte[]) {
|
||||
sink.getBucket().put(StringUtils.hasText(path) ? path : "_raw", (byte[]) value);
|
||||
if (value instanceof byte[] valueBytes) {
|
||||
sink.getBucket().put(StringUtils.hasText(path) ? path : "_raw", valueBytes);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -974,8 +965,8 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
*/
|
||||
public byte[] toBytes(Object source) {
|
||||
|
||||
if (source instanceof byte[]) {
|
||||
return (byte[]) source;
|
||||
if (source instanceof byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
return conversionService.convert(source, byte[].class);
|
||||
|
||||
@@ -47,10 +47,8 @@ public class SpelIndexResolver implements IndexResolver {
|
||||
private final ConfigurableIndexDefinitionProvider settings;
|
||||
private final SpelExpressionParser parser;
|
||||
private final RedisMappingContext mappingContext;
|
||||
|
||||
private @Nullable BeanResolver beanResolver;
|
||||
|
||||
private final Map<SpelIndexDefinition, Expression> expressionCache;
|
||||
private @Nullable BeanResolver beanResolver;
|
||||
|
||||
/**
|
||||
* Creates a new instance using a default {@link SpelExpressionParser}.
|
||||
@@ -95,9 +93,9 @@ public class SpelIndexResolver implements IndexResolver {
|
||||
|
||||
for (IndexDefinition setting : settings.getIndexDefinitionsFor(keyspace)) {
|
||||
|
||||
if (setting instanceof SpelIndexDefinition) {
|
||||
if (setting instanceof SpelIndexDefinition spelIndexDefinition) {
|
||||
|
||||
Expression expression = getAndCacheIfAbsent((SpelIndexDefinition) setting);
|
||||
Expression expression = getAndCacheIfAbsent(spelIndexDefinition);
|
||||
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setRootObject(value);
|
||||
|
||||
@@ -140,11 +140,11 @@ public abstract class RedisIndexDefinition implements IndexDefinition {
|
||||
@Override
|
||||
public Object convert(Object source) {
|
||||
|
||||
if (!(source instanceof String)) {
|
||||
if (!(source instanceof String string)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
return ((String) source).toLowerCase();
|
||||
return string.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,16 +99,16 @@ public class DefaultScriptExecutor<K> implements ScriptExecutor<K> {
|
||||
int i = 0;
|
||||
if (keys != null) {
|
||||
for (K key : keys) {
|
||||
if (keySerializer() == null && key instanceof byte[]) {
|
||||
keysAndArgs[i++] = (byte[]) key;
|
||||
if (keySerializer() == null && key instanceof byte[] keyBytes) {
|
||||
keysAndArgs[i++] = keyBytes;
|
||||
} else {
|
||||
keysAndArgs[i++] = keySerializer().serialize(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Object arg : args) {
|
||||
if (argsSerializer == null && arg instanceof byte[]) {
|
||||
keysAndArgs[i++] = (byte[]) arg;
|
||||
if (argsSerializer == null && arg instanceof byte[] argBytes) {
|
||||
keysAndArgs[i++] = argBytes;
|
||||
} else {
|
||||
keysAndArgs[i++] = argsSerializer.serialize(arg);
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ class ScriptUtils {
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
static <T> T deserializeResult(RedisSerializer<T> resultSerializer, Object result) {
|
||||
|
||||
if (result instanceof byte[]) {
|
||||
return resultSerializer.deserialize((byte[]) result);
|
||||
if (result instanceof byte[] resultBytes) {
|
||||
return resultSerializer.deserialize(resultBytes);
|
||||
}
|
||||
|
||||
if (result instanceof List) {
|
||||
if (result instanceof List listResult) {
|
||||
|
||||
List<Object> results = new ArrayList<>(((List) result).size());
|
||||
List<Object> results = new ArrayList<>(listResult.size());
|
||||
|
||||
for (Object obj : (List) result) {
|
||||
for (Object obj : listResult) {
|
||||
results.add(deserializeResult(resultSerializer, obj));
|
||||
}
|
||||
|
||||
@@ -76,15 +76,15 @@ class ScriptUtils {
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
static <T> T deserializeResult(RedisElementReader<T> reader, Object result) {
|
||||
|
||||
if (result instanceof ByteBuffer) {
|
||||
return reader.read((ByteBuffer) result);
|
||||
if (result instanceof ByteBuffer byteBuffer) {
|
||||
return reader.read(byteBuffer);
|
||||
}
|
||||
|
||||
if (result instanceof List) {
|
||||
if (result instanceof List listResult) {
|
||||
|
||||
List<Object> results = new ArrayList<>(((List) result).size());
|
||||
List<Object> results = new ArrayList<>(listResult.size());
|
||||
|
||||
for (Object obj : (List) result) {
|
||||
for (Object obj : listResult) {
|
||||
results.add(deserializeResult(reader, obj));
|
||||
}
|
||||
|
||||
|
||||
@@ -918,9 +918,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
|
||||
try {
|
||||
|
||||
if (subscriptionExecutor instanceof ScheduledExecutorService) {
|
||||
((ScheduledExecutorService) subscriptionExecutor).schedule(retryRunnable, recoveryInterval,
|
||||
TimeUnit.MILLISECONDS);
|
||||
if (subscriptionExecutor instanceof ScheduledExecutorService scheduledExecutorService) {
|
||||
scheduledExecutorService.schedule(retryRunnable, recoveryInterval, TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
Thread.sleep(recoveryInterval);
|
||||
retryRunnable.run();
|
||||
@@ -957,8 +956,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
Executor executor = getRequiredTaskExecutor();
|
||||
|
||||
for (MessageListener messageListener : listeners) {
|
||||
if (messageListener instanceof SubscriptionListener) {
|
||||
executor.execute(() -> listenerConsumer.accept((SubscriptionListener) messageListener, source, count));
|
||||
if (messageListener instanceof SubscriptionListener subscriptionListener) {
|
||||
executor.execute(() -> listenerConsumer.accept(subscriptionListener, source, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ public abstract class AbstractRedisCollection<E> extends AbstractCollection<E> i
|
||||
if (o == this)
|
||||
return true;
|
||||
|
||||
if (o instanceof RedisStore) {
|
||||
return key.equals(((RedisStore) o).getKey());
|
||||
if (o instanceof RedisStore redisStore) {
|
||||
return key.equals(redisStore.getKey());
|
||||
}
|
||||
|
||||
if (o instanceof AbstractRedisCollection) {
|
||||
|
||||
@@ -158,8 +158,8 @@ public class DefaultRedisList<E> extends AbstractRedisCollection<E> implements R
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void potentiallyCap(RedisList<E> destination) {
|
||||
if (destination instanceof DefaultRedisList) {
|
||||
((DefaultRedisList<Object>) destination).cap();
|
||||
if (destination instanceof DefaultRedisList<?> defaultRedisList) {
|
||||
defaultRedisList.cap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,8 +619,7 @@ public class DefaultRedisList<E> extends AbstractRedisCollection<E> implements R
|
||||
*/
|
||||
int lastReturnedElementIndex = -1;
|
||||
|
||||
@Nullable
|
||||
E lastReturnedElement;
|
||||
@Nullable E lastReturnedElement;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
|
||||
Reference in New Issue
Block a user