1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.UnaryFunctor; 36 import net.sf.jga.fn.UnaryFunctor; 37 38 48 49 public class ChainUnary<T,F,R> extends UnaryFunctor<T,R> { 50 51 static final long serialVersionUID = -6690274081307420708L; 52 53 private UnaryFunctor<F,R> _f; 55 56 private UnaryFunctor<T,F> _g; 58 59 64 public ChainUnary(UnaryFunctor<F,R> f, UnaryFunctor<T,F> g) 65 { 66 if (f == null || g == null) { 67 throw new IllegalArgumentException ("Two functors are required"); 68 } 69 70 _f = f; 71 _g = g; 72 } 73 74 78 public UnaryFunctor<F,R> getOuterFunctor() { return _f; } 79 80 84 public UnaryFunctor<T,F> getInnerFunctor() { return _g; } 85 86 88 94 public R fn(T x) { 95 return _f.fn(_g.fn(x)); 96 } 97 98 100 public String toString() { 101 return _f+".compose("+_g+")"; 102 } 103 104 108 public void accept(net.sf.jga.fn.Visitor v) { 109 if (v instanceof ChainUnary.Visitor) 110 ((ChainUnary.Visitor)v).visit(this); 111 else 112 v.visit(this); 113 } 114 115 117 120 public interface Visitor extends net.sf.jga.fn.Visitor { 121 public void visit(ChainUnary bf); 122 } 123 } 124 | Popular Tags |