sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1603178 - in /sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl: ModelAdapterFactory.java injectors/ValueMapInjector.java
Date Tue, 17 Jun 2014 14:08:57 GMT
Author: justin
Date: Tue Jun 17 14:08:57 2014
New Revision: 1603178

URL: http://svn.apache.org/r1603178
Log:
SLING-3674 - avoiding duplicating code in ClassUtils

Modified:
    sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
    sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java

Modified: sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java?rev=1603178&r1=1603177&r2=1603178&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
(original)
+++ sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
Tue Jun 17 14:08:57 2014
@@ -47,6 +47,7 @@ import javax.inject.Named;
 
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.ClassUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -612,29 +613,11 @@ public class ModelAdapterFactory impleme
     }
 
     private Type mapPrimitiveClasses(Type type) {
-        if (type == Integer.TYPE) {
-            return Integer.class;
-        }
-        if (type == Long.TYPE) {
-            return Long.class;
-        }
-        if (type == Boolean.TYPE) {
-            return Boolean.class;
-        }
-        if (type == Double.TYPE) {
-            return Double.class;
-        }
-        if (type == Float.TYPE) {
-            return Float.class;
-        }
-        if (type == Short.TYPE) {
-            return Short.class;
-        }
-        if (type == Character.TYPE) {
-            return Character.class;
+        if (type instanceof Class<?>) {
+            return ClassUtils.primitiveToWrapper((Class<?>) type);
+        } else {
+            return type;
         }
-
-        return type;
     }
 
     private static boolean setField(Field field, Object createdObject, Object value) {

Modified: sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java?rev=1603178&r1=1603177&r2=1603178&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
(original)
+++ sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
Tue Jun 17 14:08:57 2014
@@ -20,6 +20,7 @@ import java.lang.reflect.AnnotatedElemen
 import java.lang.reflect.Array;
 import java.lang.reflect.Type;
 
+import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
@@ -63,16 +64,16 @@ public class ValueMapInjector implements
                 if (clazz.isArray()) {
                     Class<?> componentType = clazz.getComponentType();
                     if (componentType.isPrimitive()) {
-                        Class<?> wrapper = getWrapperForPrimitive(componentType);
-                        if (wrapper != null) {
+                        Class<?> wrapper = ClassUtils.primitiveToWrapper(componentType);
+                        if (wrapper != componentType) {
                             Object wrapperArray = map.get(name, Array.newInstance(wrapper,
0).getClass());
                             if (wrapperArray != null) {
                                 return unwrapArray(wrapperArray, componentType);
                             }
                         }
                     } else {
-                        Class<?> primitiveType = getPrimitiveForWrapper(componentType);
-                        if (primitiveType != null) {
+                        Class<?> primitiveType = ClassUtils.wrapperToPrimitive(componentType);
+                        if (primitiveType != componentType) {
                             Object primitiveArray = map.get(name, Array.newInstance(primitiveType,
0).getClass());
                             if (primitiveArray != null) {
                                 return wrapArray(primitiveArray, componentType);
@@ -117,58 +118,6 @@ public class ValueMapInjector implements
         return wrapperArray;
     }
 
-    private Class<?> getPrimitiveForWrapper(Class<?> clazz) {
-        if (clazz == Integer.class) {
-            return Integer.TYPE;
-        }
-        if (clazz == Long.class) {
-            return Long.TYPE;
-        }
-        if (clazz == Boolean.class) {
-            return Boolean.TYPE;
-        }
-        if (clazz == Double.class) {
-            return Double.TYPE;
-        }
-        if (clazz == Float.class) {
-            return Float.TYPE;
-        }
-        if (clazz == Short.class) {
-            return Short.TYPE;
-        }
-        if (clazz == Character.class) {
-            return Character.TYPE;
-        }
-
-        return null;
-    }
-
-    private Class<?> getWrapperForPrimitive(Class<?> clazz) {
-        if (clazz == Integer.TYPE) {
-            return Integer.class;
-        }
-        if (clazz == Long.TYPE) {
-            return Long.class;
-        }
-        if (clazz == Boolean.TYPE) {
-            return Boolean.class;
-        }
-        if (clazz == Double.TYPE) {
-            return Double.class;
-        }
-        if (clazz == Float.TYPE) {
-            return Float.class;
-        }
-        if (clazz == Short.TYPE) {
-            return Short.class;
-        }
-        if (clazz == Character.TYPE) {
-            return Character.class;
-        }
-
-        return null;
-    }
-
     @Override
     public InjectAnnotationProcessor createAnnotationProcessor(Object adaptable, AnnotatedElement
element) {
         // check if the element has the expected annotation



Mime
View raw message