Skip to content

Commit 81d179c

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

File tree

2 files changed

+51
-39
lines changed

2 files changed

+51
-39
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
@@ -158,13 +158,9 @@ public boolean isAssignableFrom(TypeInformation<?> target) {
158158
@Nullable
159159
protected TypeInformation<?> doGetComponentType() {
160160

161-
boolean isCustomMapImplementation = isMap() && !isMapBaseType();
162-
163-
if (isCustomMapImplementation) {
164-
return getRequiredSuperTypeInformation(getMapBaseType()).getComponentType();
165-
}
166-
167-
return createInfo(this.type.getActualTypeArguments()[0]);
161+
return isMap() && !isMapBaseType()
162+
? getRequiredSuperTypeInformation(getMapBaseType()).getComponentType()
163+
: createInfo(this.type.getActualTypeArguments()[0]);
168164
}
169165

170166
/*

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

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

536536
protected boolean isMapBaseType() {
537-
return isBaseType(MAP_TYPES);
538-
}
539-
540-
private boolean isBaseType(Class<?>[] candidates) {
541-
542-
Class<S> type = getType();
543-
544-
for (Class<?> candidate: candidates) {
545-
if (candidate.equals(type)) {
546-
return true;
547-
}
548-
}
549-
550-
return false;
537+
return isOneOf(MAP_TYPES);
551538
}
552539

553540
protected Class<?> getMapBaseType() {
554-
return getBaseType(MAP_TYPES);
555-
}
556-
557-
private Class<?> getBaseType(Class<?>[] candidates) {
558-
559-
Class<S> type = getType();
560-
561-
for (Class<?> candidate : candidates) {
562-
if (candidate.isAssignableFrom(type)) {
563-
return candidate;
564-
}
565-
}
566-
567-
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
568-
}
569-
570-
private boolean isNullableWrapper() {
571-
return NullableWrapperConverters.supports(getType());
541+
return getSuperTypeWithin(MAP_TYPES);
572542
}
573543

574544
/*
@@ -630,6 +600,52 @@ private boolean isCollection() {
630600
return false;
631601
}
632602

603+
/**
604+
* Returns whether the current's raw type is one of the given ones.
605+
*
606+
* @param candidates must not be {@literal null}.
607+
* @return
608+
*/
609+
private boolean isOneOf(Class<?>[] candidates) {
610+
611+
Assert.notNull(candidates, "Candidates must not be null!");
612+
613+
Class<S> type = getType();
614+
615+
for (Class<?> candidate : candidates) {
616+
if (candidate.equals(type)) {
617+
return true;
618+
}
619+
}
620+
621+
return false;
622+
}
623+
624+
/**
625+
* Returns the super type of the current raw type from the given candidates.
626+
*
627+
* @param candidates must not be {@literal null}.
628+
* @return
629+
*/
630+
private Class<?> getSuperTypeWithin(Class<?>[] candidates) {
631+
632+
Assert.notNull(candidates, "Candidates must not be null!");
633+
634+
Class<S> type = getType();
635+
636+
for (Class<?> candidate : candidates) {
637+
if (candidate.isAssignableFrom(type)) {
638+
return candidate;
639+
}
640+
}
641+
642+
throw new IllegalArgumentException(String.format("Type %s not contained in candidates %s!", type, candidates));
643+
}
644+
645+
private boolean isNullableWrapper() {
646+
return NullableWrapperConverters.supports(getType());
647+
}
648+
633649
/**
634650
* A synthetic {@link ParameterizedType}.
635651
*

0 commit comments

Comments
 (0)