1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.BinaryFunctor; 36 37 47 48 public class ComposeBinary<T1,T2,F1,F2,R> extends BinaryFunctor<T1,T2,R> { 49 50 static final long serialVersionUID = -6427141311027965863L; 51 52 private BinaryFunctor<T1,T2,F1> _f; 54 55 private BinaryFunctor<T1,T2,F2> _g; 57 58 private BinaryFunctor<F1,F2,R> _h; 60 61 66 public ComposeBinary(BinaryFunctor<T1,T2,F1> f, 67 BinaryFunctor<T1,T2,F2> g, 68 BinaryFunctor<F1,F2,R> h) 69 { 70 if (f == null || g == null || h == null) { 71 throw new IllegalArgumentException ("Three functors are required"); 72 } 73 74 _f = f; _g =g; _h = h; 75 } 76 77 81 public BinaryFunctor<T1,T2,F1> getFirstInnerFunctor() { return _f; } 82 83 87 public BinaryFunctor<T1,T2,F2> getSecondInnerFunctor() { return _g; } 88 89 93 public BinaryFunctor<F1,F2,R> getOuterFunctor() { return _h; } 94 95 97 103 public R fn(T1 x, T2 y) { 104 return _h.fn(_f.fn(x,y), _g.fn(x,y)); 105 } 106 107 111 public void accept(net.sf.jga.fn.Visitor v) { 112 if (v instanceof ComposeBinary.Visitor) 113 ((ComposeBinary.Visitor)v).visit(this); 114 else 115 v.visit(this); 116 } 117 118 120 public String toString() { 121 return _h+".compose("+_f+","+_g+")"; 122 } 123 124 126 129 public interface Visitor extends net.sf.jga.fn.Visitor { 130 public void visit(ComposeBinary host); 131 } 132 } 133 | Popular Tags |