Author: hardy.ferentschik
Date: 2009-06-09 10:26:06 -0400 (Tue, 09 Jun 2009)
New Revision: 16722
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
Log:
Added a new helper method to determine the autoboxed type of a primitive type.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-09
14:19:42 UTC (rev 16721)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-09
14:26:06 UTC (rev 16722)
@@ -435,6 +435,47 @@
}
/**
+ * Returns the autoboxed type of a primitive type.
+ *
+ * @param primitiveType the primitive type
+ * @return the autoboxed type of a primitive type.
+ * @throws IllegalArgumentException in case the parameter {@code primitiveType} does not
represent a primitive type.
+ */
+ public static Class<?> boxedTyp(Type primitiveType) {
+ if ( !( primitiveType instanceof Class ) && !( ( Class ) primitiveType
).isPrimitive() ) {
+ throw new IllegalArgumentException( primitiveType.getClass() + "has to be a
primitive type" );
+ }
+
+ if ( primitiveType == boolean.class ) {
+ return Boolean.class;
+ }
+ else if ( primitiveType == char.class ) {
+ return Character.class;
+ }
+ else if ( primitiveType == double.class ) {
+ return Double.class;
+ }
+ else if ( primitiveType == float.class ) {
+ return Float.class;
+ }
+ else if ( primitiveType == long.class ) {
+ return Long.class;
+ }
+ else if ( primitiveType == int.class ) {
+ return Integer.class;
+ }
+ else if ( primitiveType == short.class ) {
+ return Short.class;
+ }
+ else if ( primitiveType == byte.class ) {
+ return Byte.class;
+ }
+ else {
+ throw new RuntimeException( "Unhandled primitive type." );
+ }
+ }
+
+ /**
* Get all superclasses and interfaces recursively.
*
* @param clazz The class to start the search with.
Show replies by date