📄 reflectionhelper.java
字号:
package org.ozoneDB.core.helper;import org.ozoneDB.core.MethodKey;import java.lang.reflect.Method;import java.util.Set;import java.util.Iterator;import java.util.TreeSet;/** * Created by IntelliJ IDEA. * User: administrator * Date: 2003-sep-13 * Time: 20:18:05 * To change this template use Options | File Templates. */public class ReflectionHelper{ public final static String SIGNATURE_DELIMITER ="|"; public static String signature(Class[] args) { String result = new String(); for (int i = 0; i < args.length; i++) { result = i > 0 ? result + SIGNATURE_DELIMITER : result; result = result + args[i].getName(); } return "\"" + result + "\""; } public static String signature(String[] args) { String result = new String(); for (int i = 0; i < args.length; i++) { result = i > 0 ? result + SIGNATURE_DELIMITER : result; result = result + args[i]; } return "\"" + result + "\""; } /** * Returns the array index of the specified method within the array * of methods of this class. */ public static int methodArrayIndex(Method[] methods, Method m) { String mName = m.getName(); String mSig = ReflectionHelper.signature(m.getParameterTypes()); for (int i = 0; i < methods.length; i++) { String cName = methods[i].getName(); String cSig = ReflectionHelper.signature(methods[i].getParameterTypes()); if (mName.equals(cName) && mSig.equals(cSig)) { return i; } } throw new RuntimeException(m + ": Unable to find method in class."); } public static Method[] methodsOfClass(Class cl) { //System.out.println("Methods of class: "+cl); Method[] methods = cl.getMethods(); Set set = new TreeSet(); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName(); String sig = ReflectionHelper.signature(methods[i].getParameterTypes()); set.add(new MethodKey(cl.getName(), name, sig, methods[i])); } Iterator it = set.iterator(); for (int i = 0; it.hasNext(); i++) { MethodKey key = (MethodKey) it.next(); methods[i] = key.method(); } return methods; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -