commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r502353 - /jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
Date Thu, 01 Feb 2007 20:50:41 GMT
Author: mbenson
Date: Thu Feb  1 12:50:40 2007
New Revision: 502353

URL: http://svn.apache.org/viewvc?view=rev&rev=502353
Log:
don't loop through a String array calling equals(); use a map

Modified:
    jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java

Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java?view=diff&rev=502353&r1=502352&r2=502353
==============================================================================
--- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
(original)
+++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
Thu Feb  1 12:50:40 2007
@@ -22,6 +22,7 @@
 import java.beans.PropertyDescriptor;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashMap;
 
 /**
  * An implementation of JXPathBeanInfo based on JavaBeans' BeanInfo. Properties
@@ -37,8 +38,8 @@
     private boolean atomic = false;
     private Class clazz;
     private PropertyDescriptor propertyDescriptors[];
-    private String[] propertyNames;
     private Class dynamicPropertyHandlerClass;
+    private HashMap propertyDescriptorMap;
 
     public JXPathBasicBeanInfo(Class clazz) {
         this.clazz = clazz;
@@ -70,7 +71,7 @@
         return dynamicPropertyHandlerClass != null;
     }
 
-    public PropertyDescriptor[] getPropertyDescriptors() {
+    public synchronized PropertyDescriptor[] getPropertyDescriptors() {
         if (propertyDescriptors == null) {
             try {
                 BeanInfo bi = null;
@@ -98,28 +99,15 @@
         return propertyDescriptors;
     }
 
-    public PropertyDescriptor getPropertyDescriptor(String propertyName) {
-        if (propertyNames == null) {
+    public synchronized PropertyDescriptor getPropertyDescriptor(String propertyName) {
+        if (propertyDescriptorMap == null) {
+            propertyDescriptorMap = new HashMap();
             PropertyDescriptor[] pds = getPropertyDescriptors();
-            String[] names = new String[pds.length];
             for (int i = 0; i < pds.length; i++) {
-                names[i] = pds[i].getName();
+                propertyDescriptorMap.put(pds[i].getName(), pds[i]);
             }
-            propertyNames = names;
         }
-
-        for (int i = 0; i < propertyNames.length; i++) {
-            if (propertyNames[i] == propertyName) {
-                return propertyDescriptors[i];
-            }
-        }
-
-        for (int i = 0; i < propertyNames.length; i++) {
-            if (propertyNames[i].equals(propertyName)) {
-                return propertyDescriptors[i];
-            }
-        }
-        return null;
+        return (PropertyDescriptor) propertyDescriptorMap.get(propertyName);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message