Skip to content

Commit d7b8ca2

Browse files
committed
Polishing.
Fix test naming. Improve equals check by caching resolved generics.
1 parent ed7389b commit d7b8ca2

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/main/java/org/springframework/data/util/TypeDiscoverer.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
6060
private final Map<Constructor<?>, List<TypeInformation<?>>> constructorParameters = new ConcurrentHashMap<>();
6161
private final Lazy<List<TypeInformation<?>>> typeArguments;
6262

63+
private final Lazy<List<Class>> resolvedGenerics;
64+
6365
protected TypeDiscoverer(ResolvableType type) {
6466

6567
Assert.notNull(type, "Type must not be null");
@@ -68,9 +70,11 @@ protected TypeDiscoverer(ResolvableType type) {
6870
this.componentType = Lazy.of(this::doGetComponentType);
6971
this.valueType = Lazy.of(this::doGetMapValueType);
7072
this.typeArguments = Lazy.of(this::doGetTypeArguments);
73+
this.resolvedGenerics = Lazy.of(() -> Arrays.stream(resolvableType.getGenerics()) //
74+
.map(ResolvableType::toClass).collect(Collectors.toList()));
7175
}
7276

73-
static TypeDiscoverer<?> td(ResolvableType type) {
77+
static TypeDiscoverer<?> ofCached(ResolvableType type) {
7478

7579
Assert.notNull(type, "Type must not be null");
7680

@@ -325,15 +329,7 @@ public boolean equals(@Nullable Object o) {
325329
return false;
326330
}
327331

328-
var collect1 = Arrays.stream(resolvableType.getGenerics()) //
329-
.map(ResolvableType::toClass) //
330-
.collect(Collectors.toList());
331-
332-
var collect2 = Arrays.stream(that.resolvableType.getGenerics()) //
333-
.map(ResolvableType::toClass) //
334-
.collect(Collectors.toList());
335-
336-
return ObjectUtils.nullSafeEquals(collect1, collect2);
332+
return ObjectUtils.nullSafeEquals(resolvedGenerics.get(), that.resolvedGenerics.get());
337333
}
338334

339335
@Override

src/main/java/org/springframework/data/util/TypeInformation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static TypeInformation<?> of(ResolvableType type) {
6060
Assert.notNull(type, "Type must not be null");
6161

6262
return type.hasGenerics() || (type.isArray() && type.getComponentType().hasGenerics()) //
63-
|| (type.getType() instanceof TypeVariable) ? TypeDiscoverer.td(type) : ClassTypeInformation.from(type);
63+
|| (type.getType() instanceof TypeVariable) ? TypeDiscoverer.ofCached(type) : ClassTypeInformation.from(type);
6464
}
6565

6666
/**

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void handlesArrayCorrectly() {
124124
}
125125

126126
@Test
127-
void handlesInvalidCollectionCompountTypeProperl() {
127+
void handlesInvalidCollectionCompoundTypeProperly() {
128128

129129
try {
130130
PropertyPath.from("usersMame", Bar.class);

0 commit comments

Comments
 (0)