(no commit message)
[utils] / support / general / src / main / java / org / wamblee / reflection / ReflectionUtils.java
index 0f33c1c261dac9fb7992570f4ae9a78aff669d58..0da2d1f2ff31fb93e3518a031686b30aff34b239 100644 (file)
@@ -23,7 +23,26 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * Some utilities for reflection. 
+ * 
+ * @author Erik Brakkee
+ */
 public class ReflectionUtils {
+    
+    public static final List<Class> PRIMITIVE_WRAPPERS =
+        createPrimitiveWrappers();
+    
+    private static final List<Class> createPrimitiveWrappers() { 
+        Class[] vals =   {
+            Boolean.class, Byte.class, Character.class, Short.class, Integer.class, Long.class,
+            Float.class, Double.class };
+        return Arrays.asList(vals);
+    }
+    
+  
+    
+    
     /**
      * Wraps a type by the corresponding wrapper type if it is a primitive type.
      * 
@@ -114,7 +133,7 @@ public class ReflectionUtils {
         Class... aExcludedClasses) {
         if (aClass.isInterface()) {
             throw new IllegalArgumentException(aClass.getName() +
-                " is not an interface.");
+                " is an interface.");
         }
         List<Field> found = new ArrayList<Field>();
         getAllFields(aClass, found, Arrays.asList(aExcludedClasses));
@@ -136,4 +155,16 @@ public class ReflectionUtils {
             getAllFields(superClass, aFound, aExcludedClasses);
         }
     }
+    
+    /**
+     * Checks if a class is a primitive type or wrapper type.
+     * @param aClass
+     * @return
+     */
+    public static boolean isPrimitive(Class aClass) { 
+        if ( aClass.isPrimitive()) { 
+            return true; 
+        }
+        return PRIMITIVE_WRAPPERS.contains(aClass);
+    }
 }