commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-500) ClassUtils.getAllInterfaces(...) could be more efficient
Date Sun, 09 Aug 2009 02:45:15 GMT

     [ https://issues.apache.org/jira/browse/LANG-500?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed LANG-500.
------------------------------

    Resolution: Fixed

svn ci -m "Improving performance of getAllInterfaces per LANG-500's patch from Pino Silvaggio"
Sending        src/java/org/apache/commons/lang/ClassUtils.java
Transmitting file data .
Committed revision 802477.

> ClassUtils.getAllInterfaces(...) could be more efficient
> --------------------------------------------------------
>
>                 Key: LANG-500
>                 URL: https://issues.apache.org/jira/browse/LANG-500
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 3.x
>            Reporter: Pino Silvaggio
>            Priority: Trivial
>             Fix For: 3.0
>
>         Attachments: LANG-500.patch, patch-ClassUtils-01.txt, patch-ClassUtils-02.txt
>
>
> This could seem like a very minor thing but why not improve
> the code once in a while...
> Something like this could replace the current inefficient code:
> {code}
>     public static List<Class<?>> getAllInterfaces(Class<?> clazz)
>     {
>         if (clazz == null)
>         {
>             return null;
>         }
>         HashSet<Class<?>> interfacesSet = new HashSet<Class<?>>();
>         LinkedList<Class<?>> interfacesList = new LinkedList<Class<?>>();
>         getAllInterfaces(clazz, interfacesSet, interfacesList);
>         return interfacesList;
>     }
>     private static void getAllInterfaces(
>             Class<?> clazz,
>             HashSet<Class<?>> interfacesSet, List<Class<?>> interfacesList)
>     {
>         while (clazz != null)
>         {
>             Class<?>[] interfaces = clazz.getInterfaces();
>             for (Class<?> i : interfaces)
>             {
>                 if (!interfacesSet.add(i))
>                 {
>                     interfacesList.add(i);
>                     getAllInterfaces(i, interfacesSet, interfacesList);
>                 }
>             }
>             clazz = clazz.getSuperclass();
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message