Java Reflection Method Get from Object getMethods(Object obj, int cmpModifier, String prefix)

Here you can find the source of getMethods(Object obj, int cmpModifier, String prefix)

Description

get Methods

License

Apache License

Declaration

private static Method[] getMethods(Object obj, int cmpModifier,
            String prefix) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    private static Method[] getMethods(Object obj, int cmpModifier,
            String prefix) {/* w w  w. j av a  2s  . c o m*/
        Method[] retMethod = null;

        Class<?> objClass = obj.getClass();
        Method[] methods = objClass.getDeclaredMethods();

        if (methods != null && !(methods.length < 1)) {

            int j = 0;

            for (int i = 0; i < methods.length; i++) {
                int modifier = methods[i].getModifiers();
                if (prefix != null && !prefix.equals("")) {
                    if (modifier == cmpModifier
                            && methods[i].getName().startsWith(prefix))
                        j++;
                } else if (modifier == cmpModifier)
                    j++;
            }
            retMethod = new Method[j];

            j = 0;
            for (int i = 0; i < methods.length; i++) {
                int modifier = methods[i].getModifiers();
                if (prefix != null && !prefix.equals("")) {
                    if (modifier == cmpModifier
                            && methods[i].getName().startsWith(prefix)) {
                        retMethod[j] = methods[i];
                        j++;
                    }
                } else if (modifier == cmpModifier)
                    retMethod[j] = methods[i];
            }

            return retMethod;
        } else
            return null;
    }
}

Related

  1. getMethodReturn(String className, String methodName, Class[] params, Object[] args, boolean isStatic)
  2. getMethodReturnTypeGeneric(Object source, Method method)
  3. getMethods(Class objectClass, Class annotationClass)
  4. getMethods(Object instance, String name, Class[] arguments, boolean isPrefix)
  5. getMethods(Object obj, boolean hasParent)
  6. getMethodsAnnotatedWith(Class ann, Object o)
  7. getMethodsAnnotatedWith(Object target, Class annotation)
  8. getMethodsAnnotatedWithValue(Class anno, Object o, String name, Object value)
  9. getMethodsByStartsWithName(String name, Object o)