| 1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.UnaryFunctor; 36 37 42 43 public class CompoundUnary<T,R> extends UnaryFunctor<T,R> { 44 45 static final long serialVersionUID = 3041907427002719706L; 46 47 private UnaryFunctor<T,?> _fn1; 49 50 private UnaryFunctor<T,R> _fn2; 52 53 public CompoundUnary (UnaryFunctor<T,?> fn1, UnaryFunctor<T,R> fn2) { 54 if (fn1 == null || fn2 == null) 55 throw new IllegalArgumentException ("Two functors are required"); 56 57 _fn1 = fn1; 58 _fn2 = fn2; 59 } 60 61 62 65 public UnaryFunctor<T,?> getFirstFunctor() { return _fn1; } 66 67 68 71 public UnaryFunctor<T,R> getSecondFunctor() { return _fn2; } 72 73 74 77 public R fn(T arg) { 78 _fn1.fn(arg); 79 return _fn2.fn(arg); 80 } 81 82 83 87 public void accept(net.sf.jga.fn.Visitor v) { 88 if (v instanceof CompoundUnary.Visitor) 89 ((CompoundUnary.Visitor)v).visit(this); 90 else 91 v.visit(this); 92 } 93 94 96 public String toString() { 97 return _fn1 +"," +_fn2; 98 } 99 100 102 105 public interface Visitor extends net.sf.jga.fn.Visitor { 106 public void visit(CompoundUnary host); 107 } 108 } 109 | Popular Tags |