1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.BinaryFunctor; 36 import net.sf.jga.fn.UnaryFunctor; 37 38 48 49 public class Distribute<T1,T2,F1,F2,R> extends BinaryFunctor<T1,T2,R> { 50 51 static final long serialVersionUID = -8288483375404557210L; 52 53 private UnaryFunctor<T1,F1> _f; 55 56 private UnaryFunctor<T2,F2> _g; 58 59 private BinaryFunctor<F1,F2,R> _h; 61 62 67 public Distribute(UnaryFunctor<T1,F1> f, 68 UnaryFunctor<T2,F2> g, 69 BinaryFunctor<F1,F2,R> h) 70 { 71 if (f == null || g == null || h == null) { 72 throw new IllegalArgumentException ("Three functors are required"); 73 } 74 75 _f = f; _g =g; _h = h; 76 } 77 78 82 public UnaryFunctor<T1,F1> getFirstInnerFunctor() { return _f; } 83 84 88 public UnaryFunctor<T2,F2> getSecondInnerFunctor() { return _g; } 89 90 94 public BinaryFunctor<F1,F2,R> getOuterFunctor() { return _h; } 95 96 98 104 public R fn(T1 x, T2 y) { 105 return _h.fn(_f.fn(x), _g.fn(y)); 106 } 107 108 112 public void accept(net.sf.jga.fn.Visitor v) { 113 if (v instanceof Distribute.Visitor) 114 ((Distribute.Visitor)v).visit(this); 115 else 116 v.visit(this); 117 } 118 119 121 public String toString() { 122 return _h+".distribute("+_f+","+_g+")"; 123 } 124 125 127 130 public interface Visitor extends net.sf.jga.fn.Visitor { 131 public void visit(Distribute host); 132 } 133 } 134 | Popular Tags |