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 61 62 public class ComposeUnary<T,F1,F2,R> extends UnaryFunctor<T,R> { 63 64 static final long serialVersionUID = -836030733262754108L; 65 66 private UnaryFunctor<T,F1> _f; 68 69 private UnaryFunctor<T,F2> _g; 71 72 private BinaryFunctor<F1,F2,R> _h; 74 75 80 public ComposeUnary(UnaryFunctor<T,F1> f, UnaryFunctor<T,F2> g, 81 BinaryFunctor<F1,F2, R> h) 82 { 83 if (f == null || g == null || h == null) { 84 throw new IllegalArgumentException ("Three functors are required"); 85 } 86 87 _f = f; _g =g; _h = h; 88 } 89 90 94 public UnaryFunctor<T,F1> getFirstInnerFunctor() { return _f; } 95 96 100 public UnaryFunctor<T,F2> getSecondInnerFunctor() { return _g; } 101 102 106 public BinaryFunctor<F1,F2,R> getOuterFunctor() { return _h; } 107 108 110 116 public R fn(T x) { 117 return _h.fn(_f.fn(x), _g.fn(x)); 118 } 119 120 124 public void accept(net.sf.jga.fn.Visitor v) { 125 if (v instanceof ComposeUnary.Visitor) 126 ((ComposeUnary.Visitor)v).visit(this); 127 else 128 v.visit(this); 129 } 130 131 133 public String toString() { 134 return _h+".compose("+_f+","+_g+")"; 135 } 136 137 139 142 public interface Visitor extends net.sf.jga.fn.Visitor { 143 public void visit(ComposeUnary host); 144 } 145 } 146 | Popular Tags |