← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14438: minor optimization in PropertyIntrospectorService

 

------------------------------------------------------------
revno: 14438
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-26 16:18:22 +0100
message:
  minor optimization in PropertyIntrospectorService
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java	2014-03-26 15:02:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java	2014-03-26 15:18:22 +0000
@@ -56,38 +56,29 @@
     @Override
     public List<Property> getProperties( Class<?> klass )
     {
+        return Lists.newArrayList( scanClass( klass ).values() );
+    }
+
+    @Override
+    public Map<String, Property> getPropertiesMap( Class<?> klass )
+    {
         return scanClass( klass );
     }
 
-    @Override
-    public Map<String, Property> getPropertiesMap( Class<?> klass )
-    {
-        Map<String, Property> propertyMap = Maps.newHashMap();
-
-        List<Property> properties = scanClass( klass );
-
-        for ( Property property : properties )
-        {
-            propertyMap.put( property.getName(), property );
-        }
-
-        return propertyMap;
-    }
-
     // -------------------------------------------------------------------------
     // Scanning Helpers
     // -------------------------------------------------------------------------
 
-    private static Map<Class<?>, List<Property>> classMapCache = Maps.newHashMap();
+    private static Map<Class<?>, Map<String, Property>> classMapCache = Maps.newHashMap();
 
-    private static List<Property> scanClass( Class<?> clazz )
+    private static Map<String, Property> scanClass( Class<?> clazz )
     {
         if ( classMapCache.containsKey( clazz ) )
         {
             return classMapCache.get( clazz );
         }
 
-        List<Property> properties = Lists.newArrayList();
+        Map<String, Property> propertyMap = Maps.newHashMap();
         List<Method> allMethods = ReflectionUtils.getAllMethods( clazz );
 
         for ( Method method : allMethods )
@@ -148,7 +139,7 @@
                 }
 
                 property.setName( name );
-                properties.add( property );
+                propertyMap.put( name, property );
 
                 Class<?> returnType = method.getReturnType();
                 property.setKlass( returnType );
@@ -177,8 +168,8 @@
             }
         }
 
-        classMapCache.put( clazz, properties );
+        classMapCache.put( clazz, propertyMap );
 
-        return properties;
+        return propertyMap;
     }
 }