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 d832052625
commit 81d179c8f7
2 changed files with 51 additions and 39 deletions

View File

@@ -158,13 +158,9 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
@Nullable
protected TypeInformation<?> doGetComponentType() {
boolean 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]);
}
/*

View File

@@ -534,41 +534,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) {
Class<S> 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());
return getSuperTypeWithin(MAP_TYPES);
}
/*
@@ -630,6 +600,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!");
Class<S> 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!");
Class<S> 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}.
*