Polishing.

Reorder methods according to conventions. More speaking names for the newly introduced type lookup methods.

Issue #2517.
This commit is contained in:
Oliver Drotbohm
2022-02-14 14:23:53 +01:00
parent 8d2a3466ef
commit 8bb88ffce1
3 changed files with 54 additions and 42 deletions

View File

@@ -142,13 +142,9 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
@Nullable
protected TypeInformation<?> doGetComponentType() {
var isCustomMapImplementation = isMap() && !isMapBaseType();
if (isCustomMapImplementation) {
return getRequiredSuperTypeInformation(getMapBaseType()).getComponentType();
}
return createInfo(this.type.getActualTypeArguments()[0]);
return isMap() && !isMapBaseType()
? getRequiredSuperTypeInformation(getMapBaseType()).getComponentType()
: createInfo(this.type.getActualTypeArguments()[0]);
}
@Override

View File

@@ -470,41 +470,11 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
}
protected boolean isMapBaseType() {
return isBaseType(MAP_TYPES);
}
private boolean isBaseType(Class<?>[] candidates) {
Class<S> type = getType();
for (Class<?> candidate: candidates) {
if (candidate.equals(type)) {
return true;
}
}
return false;
return isOneOf(MAP_TYPES);
}
protected Class<?> getMapBaseType() {
return getBaseType(MAP_TYPES);
}
private Class<?> getBaseType(Class<?>[] candidates) {
var type = getType();
for (var candidate : candidates) {
if (candidate.isAssignableFrom(type)) {
return candidate;
}
}
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
}
private boolean isNullableWrapper() {
return NullableWrapperConverters.supports(getType());
return getSuperTypeWithin(MAP_TYPES);
}
@Override
@@ -558,6 +528,52 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
return false;
}
/**
* Returns whether the current's raw type is one of the given ones.
*
* @param candidates must not be {@literal null}.
* @return
*/
private boolean isOneOf(Class<?>[] candidates) {
Assert.notNull(candidates, "Candidates must not be null!");
var type = getType();
for (Class<?> candidate : candidates) {
if (candidate.equals(type)) {
return true;
}
}
return false;
}
/**
* Returns the super type of the current raw type from the given candidates.
*
* @param candidates must not be {@literal null}.
* @return
*/
private Class<?> getSuperTypeWithin(Class<?>[] candidates) {
Assert.notNull(candidates, "Candidates must not be null!");
var type = getType();
for (Class<?> candidate : candidates) {
if (candidate.isAssignableFrom(type)) {
return candidate;
}
}
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
}
private boolean isNullableWrapper() {
return NullableWrapperConverters.supports(getType());
}
/**
* A synthetic {@link ParameterizedType}.
*