1 8 14 package jfun.yan; 15 16 17 23 final class MappedComponent2<A,B,R> extends Component<R> { 24 private final Map2<A,B,R> m; 25 private final Creator<A> c1; 26 private final Creator<B> c2; 27 public boolean isConcrete(){ 28 return false; 29 } 30 33 public MappedComponent2(Creator<A> c1, Creator<B> c2, Map2<A,B,R> m) { 34 this.c1 = c1; 35 this.c2 = c2; 36 this.m = m; 37 } 38 public Class <R> getType(){ 39 return null; 40 } 41 public R create(Dependency dep){ 42 return run_map(c1.create(dep), c2.create(dep)); 43 } 44 public Class verify(Dependency dep){ 45 c1.verify(dep); 46 c2.verify(dep); 47 return Object .class; 48 } 49 50 public boolean equals(Object obj) { 51 if(obj instanceof MappedComponent2){ 52 final MappedComponent2 mc2 = (MappedComponent2)obj; 53 return m.equals(mc2.m) && c1.equals(mc2.c1) && c2.equals(mc2.c2); 54 } 55 else return false; 56 } 57 public int hashCode(){ 58 return c1.hashCode()*31 + c2.hashCode(); 59 } 60 public String toString(){ 61 return "map (" + c1.toString() + "," + c2.toString() + ")"; 62 } 63 private R run_map(A o1, B o2){ 64 try{ 65 return m.map(o1, o2); 66 } 67 catch(Error e){ 68 throw e; 69 } 70 catch(YanException e){ 71 throw e; 72 } 73 catch(Throwable e){ 74 throw new jfun.yan.ComponentInstantiationException(e); 75 } 76 } 77 public boolean isSingleton(){ 78 return false; 79 } 80 } 81 | Popular Tags |