public static Object chooseMostGeneralMethodWith1NullParam(FastArray methods) {
        // let's look for methods with 1 argument which matches the type of the
        // arguments
        CachedClass closestClass = null;
        CachedClass closestVargsClass = null;
        Object answer = null;
        int closestDist = -1;
        final int len = methods.size();
        for (int i = 0; i != len; ++i) {
            final Object[] data = methods.getArray();
            Object method = data[i];
            final ParameterTypes pt = (ParameterTypes) method;
            CachedClass[] paramTypes = pt.getParameterTypes();
            int paramLength = paramTypes.length;
            if (paramLength == 0 || paramLength > 2) continue;

            CachedClass theType = paramTypes[0];
            if (theType.isPrimitive) continue;

            if (paramLength == 2) {
                if (!pt.isVargsMethod(ARRAY_WITH_NULL)) continue;
                if (closestClass == null) {
                    closestVargsClass = paramTypes[1];
                    closestClass = theType;
                    answer = method;
                } else if (closestClass.getTheClass() == theType.getTheClass()) {
                    if (closestVargsClass == null) continue;
                    CachedClass newVargsClass = paramTypes[1];
                    if (isAssignableFrom(newVargsClass.getTheClass(), closestVargsClass.getTheClass())) {
                        closestVargsClass = newVargsClass;
                        answer = method;
                    }
                } else if (isAssignableFrom(theType.getTheClass(), closestClass.getTheClass())) {
                    closestVargsClass = paramTypes[1];
                    closestClass = theType;
                    answer = method;
                }
            } else {
                if (closestClass == null || isAssignableFrom(theType.getTheClass(), closestClass.getTheClass())) {
                    closestVargsClass = null;
                    closestClass = theType;
                    answer = method;
                    closestDist = -1;
                } else {
                    // closestClass and theType are not in a subtype relation, we need
                    // to check the distance to Object
                    if (closestDist == -1) closestDist = closestClass.getSuperClassDistance();
                    int newDist = theType.getSuperClassDistance();
                    if (newDist < closestDist) {
                        closestDist = newDist;
                        closestVargsClass = null;
                        closestClass = theType;
                        answer = method;
                    }
                }
            }
        }
        return answer;
    }
public static Object chooseMostGeneralMethodWith1NullParam ( FastArray methods ) { CachedClass closestClass = null ; CachedClass closestVargsClass = null ; Object answer = null ; int closestDist = - 1 ; final int len = methods . size ( ) ; for ( int i = 0 ; i != len ; ++ i ) { final Object [ ] data = methods . getArray ( ) ; Object method = data [ i ] ; final ParameterTypes pt = ( ParameterTypes ) method ; CachedClass [ ] paramTypes = pt . getParameterTypes ( ) ; int paramLength = paramTypes . length ; if ( paramLength == 0 || paramLength > 2 ) continue ; CachedClass theType = paramTypes [ 0 ] ; if ( theType . isPrimitive ) continue ; if ( paramLength == 2 ) { if ( ! pt . isVargsMethod ( ARRAY_WITH_NULL ) ) continue ; if ( closestClass == null ) { closestVargsClass = paramTypes [ 1 ] ; closestClass = theType ; answer = method ; } else if ( closestClass . getTheClass ( ) == theType . getTheClass ( ) ) { if ( closestVargsClass == null ) continue ; CachedClass newVargsClass = paramTypes [ 1 ] ; if ( isAssignableFrom ( newVargsClass . getTheClass ( ) , closestVargsClass . getTheClass ( ) ) ) { closestVargsClass = newVargsClass ; answer = method ; } } else if ( isAssignableFrom ( theType . getTheClass ( ) , closestClass . getTheClass ( ) ) ) { closestVargsClass = paramTypes [ 1 ] ; closestClass = theType ; answer = method ; } } else { if ( closestClass == null || isAssignableFrom ( theType . getTheClass ( ) , closestClass . getTheClass ( ) ) ) { closestVargsClass = null ; closestClass = theType ; answer = method ; closestDist = - 1 ; } else { if ( closestDist == - 1 ) closestDist = closestClass . getSuperClassDistance ( ) ; int newDist = theType . getSuperClassDistance ( ) ; if ( newDist < closestDist ) { closestDist = newDist ; closestVargsClass = null ; closestClass = theType ; answer = method ; } } } } return answer ; }
Warning: this method does not choose properly if multiple methods with
the same distance are encountered
@param methods the methods to choose from
@return the method with 1 parameter which takes the most general type of
object (e.g. Object) ignoring primitive types
@deprecated