1 8 14 package jfun.yan; 15 16 import jfun.util.Misc; 17 import jfun.util.SerializableMethod; 18 import jfun.yan.function.Function; 19 20 26 final class MethodFunction implements Function{ 27 private final Object obj; 28 private final jfun.util.SerializableMethod mtd; 29 30 public Object call(Object [] args) 31 throws Throwable { 32 try{ 33 return mtd.getMethod().invoke(obj, args); 34 } 35 catch(java.lang.reflect.InvocationTargetException e){ 36 throw Utils.wrapInvocationException(e); 37 } 38 } 39 public Class [] getParameterTypes() { 40 return mtd.getMethod().getParameterTypes(); 41 } 42 public Class getReturnType() { 43 return mtd.getMethod().getReturnType(); 44 } 45 public boolean isConcrete(){ 46 return false; 47 } 48 MethodFunction(final Object obj, final java.lang.reflect.Method mtd) { 49 this.obj = obj; 50 this.mtd = new SerializableMethod(mtd); 51 } 52 53 public boolean equals(Object other) { 54 if(other instanceof MethodFunction){ 55 final MethodFunction m2 = (MethodFunction)other; 56 return obj==m2.obj && mtd.equals(m2.mtd); 57 } 58 else return false; 59 } 60 public String getName() { 61 return mtd.getMethod().getName(); 62 } 63 public int hashCode() { 64 return Misc.hashcode(obj)*31+mtd.hashCode(); 65 } 66 public String toString() { 67 return mtd.toString(); 68 } 69 } 70 | Popular Tags |