1 8 9 15 package jfun.yan; 16 17 import jfun.yan.function.Signature; 18 19 25 final class UseArgumentComponent<T> extends Component<T> { 26 private final Signature sig; 27 private final int key; 28 private final Class <T> type; 29 public boolean isConcrete(){ 30 return false; 31 } 32 UseArgumentComponent(final Signature sig, final int key, final Class <T> type) { 33 this.sig = sig; 34 this.key = key; 35 this.type = type; 36 } 37 public Class <T> getType() { 38 return type; 39 } 40 public T create(Dependency pp){ 41 return (T)findDependency(pp).getArgument(sig, key, type); 42 } 43 public Class verify(Dependency pp){ 44 return findDependency(pp).verifyArgument(sig, key, type); 45 } 46 47 public boolean equals(Object obj) { 48 if(obj instanceof UseArgumentComponent){ 49 final UseArgumentComponent other = (UseArgumentComponent)obj; 50 return sig.equals(other.sig) && key == other.key && type.equals(other.type); 51 } 52 else return false; 53 } 54 public int hashCode() { 55 return (key*31 + type.hashCode())*31+sig.hashCode(); 56 } 57 public String toString() { 58 return "useArgument(" + sig.getName()+","+key + ","+jfun.util.Misc.getTypeName(type)+")"; 59 } 60 private Dependency findDependency(Dependency dep){ 61 final Dependency parent = dep.getParent(); 62 if(parent == null) 63 throw new YanException("useArgument can only be used for parameter or property"); 64 return parent; 65 } 66 public boolean isSingleton(){ 67 return false; 68 } 69 } 70 | Popular Tags |