1 package jfun.yan; 2 3 import jfun.util.SerializableField; 4 import jfun.yan.function.Function; 5 6 7 15 final class FloatingFieldFunction implements Function { 16 private final Class type; 17 private final SerializableField fld; 18 public boolean isConcrete(){ 19 return false; 20 } 21 FloatingFieldFunction(final Class type, 22 final java.lang.reflect.Field fld) { 23 this.type = type; 24 this.fld = new SerializableField(fld); 25 } 26 public Class getReturnType() { 27 return fld.getField().getType(); 28 } 29 public Class [] getParameterTypes() { 30 return new Class []{type}; 31 } 32 public Object call(Object [] args) 33 throws IllegalAccessException { 34 return fld.getField().get(args[0]); 35 } 36 37 public boolean equals(Object obj) { 38 if(obj instanceof FloatingFieldFunction){ 39 final FloatingFieldFunction other = (FloatingFieldFunction)obj; 40 return type.equals(other.type) && fld.equals(other.fld); 41 } 42 else return false; 43 } 44 public int hashCode() { 45 return type.hashCode()*31+fld.hashCode(); 46 } 47 public String toString() { 48 return jfun.util.Misc.getTypeName(type) 49 + "::" + fld.getField().getName(); 50 } 51 public String getName(){ 52 return fld.getField().getName(); 53 } 54 } 55 | Popular Tags |