1 8 9 15 package jfun.yan; 16 17 import jfun.yan.function.Function; 18 19 25 final class IndexedPropertyWriter implements Function { 26 private final jfun.util.beans.Bean bean; 27 private final String prop; 28 private final int ind; 29 30 IndexedPropertyWriter(final jfun.util.beans.Bean bean, 31 final String prop, final int ind) { 32 this.bean = bean; 33 this.prop = prop; 34 this.ind = ind; 35 } 36 37 public Object call(Object [] args) throws Throwable { 38 bean.setProperty(prop, ind, args[0]); 39 return bean.getObject(); 40 } 41 public Class [] getParameterTypes() { 42 return new Class []{bean.getBeanType().getIndexedPropertyType(prop)}; 43 } 44 public Class getReturnType() { 45 final Object obj = bean.getObject(); 46 return obj==null?bean.getBeanType().getType():obj.getClass(); 47 } 48 public boolean isConcrete(){ 49 return bean.getObject()!=null; 50 } 51 public boolean equals(Object obj) { 52 if(obj instanceof IndexedPropertyWriter){ 53 final IndexedPropertyWriter other = (IndexedPropertyWriter)obj; 54 return ind==other.ind && prop.equals(other.prop) && 55 bean.equals(other.bean); 56 } 57 else return false; 58 } 59 public int hashCode() { 60 return (bean.hashCode() * 31 + prop.hashCode())*31+ind; 61 } 62 public String toString() { 63 return bean.toString() + "." + prop+"["+ind+"]="; 64 } 65 public String getName(){ 66 return prop; 67 } 68 } 69 | Popular Tags |