|
28 | 28 | import java.util.Objects; |
29 | 29 | import java.util.WeakHashMap; |
30 | 30 |
|
| 31 | +import org.apache.commons.lang3.ClassUtils; |
31 | 32 | import org.apache.commons.logging.Log; |
32 | 33 | import org.apache.commons.logging.LogFactory; |
33 | 34 |
|
@@ -493,7 +494,7 @@ private static float getObjectTransformationCost(Class<?> srcClass, final Class< |
493 | 494 | float cost = 0.0f; |
494 | 495 | while (srcClass != null && !destClass.equals(srcClass)) { |
495 | 496 | if (destClass.isPrimitive()) { |
496 | | - final Class<?> destClassWrapperClazz = getPrimitiveWrapper(destClass); |
| 497 | + final Class<?> destClassWrapperClazz = ClassUtils.wrapperToPrimitive(destClass); |
497 | 498 | if (destClassWrapperClazz != null && destClassWrapperClazz.equals(srcClass)) { |
498 | 499 | cost += 0.25f; |
499 | 500 | break; |
@@ -521,41 +522,6 @@ private static float getObjectTransformationCost(Class<?> srcClass, final Class< |
521 | 522 | return cost; |
522 | 523 | } |
523 | 524 |
|
524 | | - /** |
525 | | - * Gets the wrapper object class for the given primitive type class. For example, passing {@code boolean.class</code> returns <code>Boolean.class} |
526 | | - * |
527 | | - * @param primitiveType the primitive type class for which a match is to be found |
528 | | - * @return the wrapper type associated with the given primitive or null if no match is found |
529 | | - */ |
530 | | - public static Class<?> getPrimitiveWrapper(final Class<?> primitiveType) { |
531 | | - // does anyone know a better strategy than comparing names? |
532 | | - if (boolean.class.equals(primitiveType)) { |
533 | | - return Boolean.class; |
534 | | - } |
535 | | - if (float.class.equals(primitiveType)) { |
536 | | - return Float.class; |
537 | | - } |
538 | | - if (long.class.equals(primitiveType)) { |
539 | | - return Long.class; |
540 | | - } |
541 | | - if (int.class.equals(primitiveType)) { |
542 | | - return Integer.class; |
543 | | - } |
544 | | - if (short.class.equals(primitiveType)) { |
545 | | - return Short.class; |
546 | | - } |
547 | | - if (byte.class.equals(primitiveType)) { |
548 | | - return Byte.class; |
549 | | - } |
550 | | - if (double.class.equals(primitiveType)) { |
551 | | - return Double.class; |
552 | | - } |
553 | | - if (char.class.equals(primitiveType)) { |
554 | | - return Character.class; |
555 | | - } |
556 | | - return null; |
557 | | - } |
558 | | - |
559 | 525 | /** |
560 | 526 | * Returns the sum of the object transformation cost for each class in the source argument list. |
561 | 527 | * |
@@ -749,7 +715,7 @@ public static boolean isAssignmentCompatible(final Class<?> parameterType, final |
749 | 715 | if (parameterType.isPrimitive()) { |
750 | 716 | // this method does *not* do widening - you must specify exactly |
751 | 717 | // is this the right behavior? |
752 | | - final Class<?> parameterWrapperClazz = getPrimitiveWrapper(parameterType); |
| 718 | + final Class<?> parameterWrapperClazz = ClassUtils.wrapperToPrimitive(parameterType); |
753 | 719 | if (parameterWrapperClazz != null) { |
754 | 720 | return parameterWrapperClazz.equals(parameterization); |
755 | 721 | } |
|
0 commit comments