Browse Source

Polishing.

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

Issue #2517.
pull/2550/head
Oliver Drotbohm 4 years ago
parent
commit
81d179c8f7
No known key found for this signature in database
GPG Key ID: C25FBFA0DA493A1D
  1. 10
      src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java
  2. 80
      src/main/java/org/springframework/data/util/TypeDiscoverer.java

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

@ -158,13 +158,9 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> @@ -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]);
}
/*

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

@ -534,41 +534,11 @@ class TypeDiscoverer<S> implements TypeInformation<S> { @@ -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> { @@ -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}.
*

Loading…
Cancel
Save