Skip to content

Commit 8bb88ff

Browse files
committed
Polishing.
Reorder methods according to conventions. More speaking names for the newly introduced type lookup methods. Issue #2517.
1 parent 8d2a346 commit 8bb88ff

File tree

3 files changed

+54
-42
lines changed

3 files changed

+54
-42
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,9 @@ public boolean isAssignableFrom(TypeInformation<?> target) {
142142
@Nullable
143143
protected TypeInformation<?> doGetComponentType() {
144144

145-
var isCustomMapImplementation = isMap() && !isMapBaseType();
146-
147-
if (isCustomMapImplementation) {
148-
return getRequiredSuperTypeInformation(getMapBaseType()).getComponentType();
149-
}
150-
151-
return createInfo(this.type.getActualTypeArguments()[0]);
145+
return isMap() && !isMapBaseType()
146+
? getRequiredSuperTypeInformation(getMapBaseType()).getComponentType()
147+
: createInfo(this.type.getActualTypeArguments()[0]);
152148
}
153149

154150
@Override

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

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -470,41 +470,11 @@ private TypeInformation<?> getTypeArgument(Class<?> bound, int index) {
470470
}
471471

472472
protected boolean isMapBaseType() {
473-
return isBaseType(MAP_TYPES);
474-
}
475-
476-
private boolean isBaseType(Class<?>[] candidates) {
477-
478-
Class<S> type = getType();
479-
480-
for (Class<?> candidate: candidates) {
481-
if (candidate.equals(type)) {
482-
return true;
483-
}
484-
}
485-
486-
return false;
473+
return isOneOf(MAP_TYPES);
487474
}
488475

489476
protected Class<?> getMapBaseType() {
490-
return getBaseType(MAP_TYPES);
491-
}
492-
493-
private Class<?> getBaseType(Class<?>[] candidates) {
494-
495-
var type = getType();
496-
497-
for (var candidate : candidates) {
498-
if (candidate.isAssignableFrom(type)) {
499-
return candidate;
500-
}
501-
}
502-
503-
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
504-
}
505-
506-
private boolean isNullableWrapper() {
507-
return NullableWrapperConverters.supports(getType());
477+
return getSuperTypeWithin(MAP_TYPES);
508478
}
509479

510480
@Override
@@ -558,6 +528,52 @@ private boolean isCollection() {
558528
return false;
559529
}
560530

531+
/**
532+
* Returns whether the current's raw type is one of the given ones.
533+
*
534+
* @param candidates must not be {@literal null}.
535+
* @return
536+
*/
537+
private boolean isOneOf(Class<?>[] candidates) {
538+
539+
Assert.notNull(candidates, "Candidates must not be null!");
540+
541+
var type = getType();
542+
543+
for (Class<?> candidate : candidates) {
544+
if (candidate.equals(type)) {
545+
return true;
546+
}
547+
}
548+
549+
return false;
550+
}
551+
552+
/**
553+
* Returns the super type of the current raw type from the given candidates.
554+
*
555+
* @param candidates must not be {@literal null}.
556+
* @return
557+
*/
558+
private Class<?> getSuperTypeWithin(Class<?>[] candidates) {
559+
560+
Assert.notNull(candidates, "Candidates must not be null!");
561+
562+
var type = getType();
563+
564+
for (Class<?> candidate : candidates) {
565+
if (candidate.isAssignableFrom(type)) {
566+
return candidate;
567+
}
568+
}
569+
570+
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
571+
}
572+
573+
private boolean isNullableWrapper() {
574+
return NullableWrapperConverters.supports(getType());
575+
}
576+
561577
/**
562578
* A synthetic {@link ParameterizedType}.
563579
*

src/test/java/org/springframework/data/util/ParameterizedTypeInformationUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ void resolvesMapTypesCorrectly() {
9595
assertThat(propertyType.getMapValueType().getType()).isEqualTo(Locale.class);
9696
}
9797

98-
@Test
98+
@Test // #2517
9999
void resolvesVavrMapTypesCorrectly() {
100100

101-
TypeInformation<VavrFoo> type = ClassTypeInformation.from(VavrFoo.class);
102-
TypeInformation<?> propertyType = type.getProperty("param");
101+
var type = ClassTypeInformation.from(VavrFoo.class);
102+
var propertyType = type.getProperty("param");
103103

104104
assertThat(propertyType.getComponentType().getType()).isEqualTo(Locale.class);
105105
assertThat(propertyType.getMapValueType().getType()).isEqualTo(String.class);

0 commit comments

Comments
 (0)