commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 33401] New: - [lang] atLeast features : public boolean is<Checking>AtLeast>(parms)
Date Fri, 04 Feb 2005 11:19:23 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33401>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=33401

           Summary: [lang] atLeast features : public boolean
                    is<Checking>AtLeast>(parms)
           Product: Commons
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: marc.dexet@dsi.cnrs.fr


To complete Lang scope, I propose to create a set of utils that could be put in
a MethodUtils and ClassUtils classes.

- public static boolean isAssignableAtLeast(Class clazz, Class[] classes);
Behavior : return true if clazz is assignable at least from one class in classes.
Interest : to check if a class presents at least one interface aspect and/or is
subclass of one of classes class. It's completing existing
ClassUtils.isAssignable(...).
Ex: isAssignableAtLeast(Purchaser.class, new Class[] { Society.class,
Customer.class} )
 
- public static boolean isDeclaredAtLeast(Method m, Class[] classes);
behavior : return true if method m is declared by at least one class in classes.
Interest : to retain methods according to interface or upper class array. 
Ex : to keep in a map only bean methods who are method from Interface1,
Supperclass2 or Interface3.

- public static boolean isMatchingPrefix(Method m, String[] prefixStrings);
behavior : return true if method name matches at least one prefix in prefix array.
Interest: to retain some kind of method according to prefix.
Ex: to retain only add<something> or remove<something> methods in introspected
class.

Codes : 
    public static boolean isAssignableAsLeast(Class subject, Class[] classes) {
        if ( classes == null || classes.length == 0 ) {
            return true;
        }
         
        for ( int i = 0; i < classes.length; i ++) {
            if( ClassUtils.isAssignable(subject, classes[i])) {
                return true;
            }
        }
        return false;
    }



   /**
     * Check if method <i>m</i> is declared by one of the <i>boundaryClasses</i>
class or interface.
     * @param m
     * @param boundaryClasses
     * @return true if declared by one class.
     */
    public static boolean isDeclaredAtLeas(Method m, Class[] boundaryClasses) {
        if ( boundaryClasses == null || boundaryClasses.length == 0 ) {
            return true;
        }
        
        Class cl = m.getDeclaringClass();
        
        if ( isAssignableAsLeast(cl, boundaryClasses )  ) {
            for ( int iC = 0; iC < boundaryClasses.length; iC ++ ) {
                try {
                    boundaryClasses[iC].getDeclaredMethod(m.getName(),
m.getParameterTypes());
                    return true;
                } catch (Exception e) {
                } 
            }
        } 
        return false;
    }


    /**
     * Caheck if method <i>m</i> match one of the <i>prefixStrings</i>
String.
     * @param m
     * @param prefixStrings
     * @return true if matching
     * 
     */
    public static boolean isMatchingPrefix(Method m, String[] prefixStrings) {
        if ( prefixStrings == null || prefixStrings.length == 0 ) {
            return true;
        }
        String name = m.getName();
        for ( int i = 0; i < prefixStrings.length; i ++) {
            if ( name.startsWith(prefixStrings[i])) {
                return true;
            }
        }
        return false;
        
    }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
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