Here you can find the source of getMethods(Object instance, String name, Class>[] arguments, boolean isPrefix)
public static List<Method> getMethods(Object instance, String name, Class<?>[] arguments, boolean isPrefix)
//package com.java2s; /**//from w ww. ja v a2s . c om * This file is part of GraphJ * * Copyright (C) 2009 Nils Meier * * GraphJ is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GraphJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GraphJ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; public class Main { /** * Returns setters of given instance with given argumentType * @name regex for matching method-name */ public static List<Method> getMethods(Object instance, String name, Class<?>[] arguments, boolean isPrefix) { // loop over methods Method[] methods = instance.getClass().getMethods(); ArrayList<Method> collect = new ArrayList<Method>(methods.length); compliance: for (int m = 0; m < methods.length; m++) { // here's a method Method method = methods[m]; // check prefix if (!method.getName().matches(name)) continue; // check public if (!Modifier.isPublic(method.getModifiers())) continue; // check static if (Modifier.isStatic(method.getModifiers())) continue; // check parameter types Class<?>[] ptypes = method.getParameterTypes(); for (int a = 0; a < ptypes.length; a++) { if (a >= arguments.length) { if (!isPrefix) continue compliance; else break; } if (arguments[a] != null && !ptypes[a].isAssignableFrom(arguments[a])) continue compliance; } collect.add(method); } // done return collect; } /** * Returns the name of a class without package information */ public static String getName(Class<?> clazz) { String result = clazz.getName(); int dot = result.lastIndexOf('.'); return dot < 0 ? result : result.substring(dot + 1); } }