commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r904101 - /commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
Date Thu, 28 Jan 2010 14:27:51 GMT
Author: niallp
Date: Thu Jan 28 14:27:50 2010
New Revision: 904101

URL: http://svn.apache.org/viewvc?rev=904101&view=rev
Log:
Partial Port of LANG-500 to 2.x branch - Improving performance of getAllInterfaces (changes
couldn't be fully ported as LinkedHashSet requires JDK 1.4)

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java?rev=904101&r1=904100&r2=904101&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ClassUtils.java
Thu Jan 28 14:27:50 2010
@@ -314,25 +314,33 @@
         if (cls == null) {
             return null;
         }
-        List list = new ArrayList();
+
+        List interfacesFound = new ArrayList();
+        getAllInterfaces(cls, interfacesFound);
+
+        return interfacesFound;
+    }
+
+    /**
+     * Get the interfaces for the specified class.
+     *
+     * @param cls  the class to look up, may be <code>null</code>
+     * @param interfacesFound the <code>Set</code> of interfaces for the class
+     */
+    private static void getAllInterfaces(Class cls, List interfacesFound) {
         while (cls != null) {
             Class[] interfaces = cls.getInterfaces();
+
             for (int i = 0; i < interfaces.length; i++) {
-                if (list.contains(interfaces[i]) == false) {
-                    list.add(interfaces[i]);
-                }
-                List superInterfaces = getAllInterfaces(interfaces[i]);
-                for (Iterator it = superInterfaces.iterator(); it.hasNext();) {
-                    Class intface = (Class) it.next();
-                    if (list.contains(intface) == false) {
-                        list.add(intface);
-                    }
+                if (!interfacesFound.contains(interfaces[i])) {
+                    interfacesFound.add(interfaces[i]);
+                    getAllInterfaces(interfaces[i], interfacesFound);
                 }
             }
+
             cls = cls.getSuperclass();
-        }
-        return list;
-    }
+         }
+     }
 
     // Convert list
     // ----------------------------------------------------------------------



Mime
View raw message