Skip to content

Commit 6c1329a

Browse files
Polishing.
Apply format and use instanceof pattern matching. Original Pull Request: #3146
1 parent 06ad21b commit 6c1329a

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.regex.Pattern;
3232

3333
import org.jspecify.annotations.Nullable;
34-
3534
import org.springframework.beans.factory.InitializingBean;
3635
import org.springframework.core.CollectionFactory;
3736
import org.springframework.core.convert.ConversionService;
@@ -173,7 +172,7 @@ public MappingRedisConverter(@Nullable RedisMappingContext mappingContext, @Null
173172
}
174173

175174
@Override
176-
@SuppressWarnings({"unchecked", "NullAway"})
175+
@SuppressWarnings({ "unchecked", "NullAway" })
177176
public <R> R read(Class<R> type, RedisData source) {
178177

179178
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
@@ -188,8 +187,8 @@ public <R> R read(Class<R> type, RedisData source) {
188187
return source.getBucket().isEmpty() ? null : doReadInternal(path, type, source);
189188
}
190189

191-
@SuppressWarnings({"unchecked", "NullAway"})
192-
private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
190+
@SuppressWarnings({ "unchecked", "NullAway" })
191+
private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
193192

194193
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
195194

@@ -403,14 +402,8 @@ public void write(@Nullable Object source, RedisData sink) {
403402
return;
404403
}
405404

406-
if (source instanceof Collection) {
407-
writeCollection(
408-
sink.getKeyspace(),
409-
"",
410-
(List<?>) source,
411-
TypeInformation.of(Object.class),
412-
sink
413-
);
405+
if (source instanceof Collection collection) {
406+
writeCollection(sink.getKeyspace(), "", collection, TypeInformation.of(Object.class), sink);
414407
return;
415408
}
416409

@@ -432,8 +425,7 @@ public void write(@Nullable Object source, RedisData sink) {
432425
sink.setKeyspace(keySpace);
433426

434427
if (entity.getTypeInformation().isCollectionLike()) {
435-
writeCollection(keySpace, "", (List) source, entity.getTypeInformation().getRequiredComponentType(),
436-
sink);
428+
writeCollection(keySpace, "", (List) source, entity.getTypeInformation().getRequiredComponentType(), sink);
437429
} else {
438430
writeInternal(keySpace, "", source, entity.getTypeInformation(), sink);
439431
}
@@ -562,8 +554,7 @@ private void writePartialPropertyUpdate(PartialUpdate<?> update, PropertyUpdate
562554
writeMap(keySpace, pUpdate.getPropertyPath(), targetProperty.getMapValueType(), map, sink);
563555
} else {
564556

565-
writeInternal(keySpace, pUpdate.getPropertyPath(), pUpdate.getValue(),
566-
targetProperty.getTypeInformation(), sink);
557+
writeInternal(keySpace, pUpdate.getPropertyPath(), pUpdate.getValue(), targetProperty.getTypeInformation(), sink);
567558

568559
Set<IndexedData> data = indexResolver.resolveIndexesFor(keySpace, pUpdate.getPropertyPath(),
569560
targetProperty.getTypeInformation(), pUpdate.getValue());
@@ -586,8 +577,7 @@ RedisPersistentProperty getTargetPropertyOrNullForPath(String path, Class<?> typ
586577
PersistentPropertyPath<RedisPersistentProperty> persistentPropertyPath = mappingContext
587578
.getPersistentPropertyPath(path, type);
588579
return persistentPropertyPath.getLeafProperty();
589-
} catch (Exception ignore) {
590-
}
580+
} catch (Exception ignore) {}
591581

592582
return null;
593583
}
@@ -694,7 +684,7 @@ private ReferenceResolver getRequiredReferenceResolver() {
694684

695685
Assert.notNull(referenceResolver, "ReferenceResolver must not be null");
696686
return referenceResolver;
697-
}
687+
}
698688

699689
private void writeAssociation(String path, RedisPersistentEntity<?> entity, @Nullable Object value, RedisData sink) {
700690

@@ -822,7 +812,8 @@ private void writeToBucket(String path, @Nullable Object value, RedisData sink,
822812
}
823813

824814
@SuppressWarnings("NullAway")
825-
private @Nullable Object readCollectionOrArray(String path, Class<?> collectionType, Class<?> valueType, Bucket bucket) {
815+
private @Nullable Object readCollectionOrArray(String path, Class<?> collectionType, Class<?> valueType,
816+
Bucket bucket) {
826817

827818
List<String> keys = new ArrayList<>(bucket.extractAllKeysFor(path));
828819
keys.sort(listKeyComparator);
@@ -991,7 +982,7 @@ private Class<?> getTypeHint(String path, Bucket bucket, Class<?> fallback) {
991982
* @return
992983
* @throws ConverterNotFoundException
993984
*/
994-
public byte@Nullable[] toBytes(Object source) {
985+
public byte @Nullable [] toBytes(Object source) {
995986

996987
if (source instanceof byte[] bytes) {
997988
return bytes;

src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@
6666

6767
import org.junit.jupiter.api.BeforeEach;
6868
import org.junit.jupiter.api.Test;
69-
import org.junit.jupiter.api.condition.EnabledOnJre;
70-
import org.junit.jupiter.api.condition.JRE;
7169
import org.junit.jupiter.api.extension.ExtendWith;
7270
import org.mockito.Mock;
7371
import org.mockito.junit.jupiter.MockitoExtension;
74-
7572
import org.springframework.core.convert.converter.Converter;
7673
import org.springframework.data.convert.ReadingConverter;
7774
import org.springframework.data.convert.WritingConverter;
@@ -1998,7 +1995,6 @@ void readGenericEntity() {
19981995
}
19991996

20001997
@Test // GH-2168
2001-
// @EnabledOnJre(JRE.JAVA_8)
20021998
void writePlainList() {
20031999

20042000
List<Object> source = Arrays.asList("Hello", "stream", "message", 100L);

0 commit comments

Comments
 (0)