Skip to content

Commit 139a25a

Browse files
committed
Internal refactoring
1 parent 86a03b4 commit 139a25a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,28 +646,24 @@ private static Type getClosestParentType(final Class<?> cls, final Class<?> supe
646646
* {@link TypeVariable#getBounds()} passed into {@link #normalizeUpperBounds}.
647647
*
648648
* @param typeVariable the subject type variable, not {@code null}
649-
* @return a non-empty array containing the bounds of the type variable.
649+
* @return a non-empty array containing the bounds of the type variable, which could be {@link Object}.
650650
* @throws NullPointerException if {@code typeVariable} is {@code null}
651651
*/
652652
public static Type[] getImplicitBounds(final TypeVariable<?> typeVariable) {
653-
Objects.requireNonNull(typeVariable, "typeVariable");
654-
final Type[] bounds = typeVariable.getBounds();
655-
656-
return bounds.length == 0 ? new Type[] { Object.class } : normalizeUpperBounds(bounds);
653+
return normalizeUpperToObject(Objects.requireNonNull(typeVariable, "typeVariable").getBounds());
657654
}
658655

659656
/**
660657
* Gets an array containing a single value of {@code null} if {@link WildcardType#getLowerBounds()} returns an empty array. Otherwise, it returns the result
661658
* of {@link WildcardType#getLowerBounds()}.
662659
*
663660
* @param wildcardType the subject wildcard type, not {@code null}
664-
* @return a non-empty array containing the lower bounds of the wildcard type.
661+
* @return a non-empty array containing the lower bounds of the wildcard type, which could be null.
665662
* @throws NullPointerException if {@code wildcardType} is {@code null}
666663
*/
667664
public static Type[] getImplicitLowerBounds(final WildcardType wildcardType) {
668665
Objects.requireNonNull(wildcardType, "wildcardType");
669666
final Type[] bounds = wildcardType.getLowerBounds();
670-
671667
return bounds.length == 0 ? new Type[] { null } : bounds;
672668
}
673669

@@ -680,10 +676,7 @@ public static Type[] getImplicitLowerBounds(final WildcardType wildcardType) {
680676
* @throws NullPointerException if {@code wildcardType} is {@code null}
681677
*/
682678
public static Type[] getImplicitUpperBounds(final WildcardType wildcardType) {
683-
Objects.requireNonNull(wildcardType, "wildcardType");
684-
final Type[] bounds = wildcardType.getUpperBounds();
685-
686-
return bounds.length == 0 ? new Type[] { Object.class } : normalizeUpperBounds(bounds);
679+
return normalizeUpperToObject(Objects.requireNonNull(wildcardType, "wildcardType").getUpperBounds());
687680
}
688681

689682
/**
@@ -1372,6 +1365,17 @@ public static Type[] normalizeUpperBounds(final Type[] bounds) {
13721365
return types.toArray(ArrayUtils.EMPTY_TYPE_ARRAY);
13731366
}
13741367

1368+
/**
1369+
* Delegates to {@link #normalizeUpperBounds(Type[])} unless {@code bounds} is empty in which case return an array with the element {@code Object.class}.
1370+
*
1371+
* @param bounds bounds an array of types representing the upper bounds of either {@link WildcardType} or {@link TypeVariable}, not {@code null}.
1372+
* @return result from {@link #normalizeUpperBounds(Type[])} unless {@code bounds} is empty in which case return an array with the element
1373+
* {@code Object.class}.
1374+
*/
1375+
private static Type[] normalizeUpperToObject(final Type[] bounds) {
1376+
return bounds.length == 0 ? new Type[] { Object.class } : normalizeUpperBounds(bounds);
1377+
}
1378+
13751379
/**
13761380
* Creates a parameterized type instance.
13771381
*

0 commit comments

Comments
 (0)