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 47 48 public class Bind2nd<T1, T2, R> extends UnaryFunctor<T1, R> { 49 50 static final long serialVersionUID = -5977756270123944716L; 51 52 private BinaryFunctor<T1, T2, R> _f; 54 55 private T2 _c; 57 58 62 public Bind2nd(T2 constant, BinaryFunctor<T1, T2, R> fn) { 63 if (fn == null) { 64 throw new IllegalArgumentException ("Must supply a function"); 65 } 66 _f = fn; 67 _c = constant; 68 } 69 70 71 75 public BinaryFunctor<T1, T2, R> getFunctor() { return _f; } 76 77 81 public T2 getConstant() { return _c; } 82 83 85 91 public R fn(T1 x) { 92 return _f.fn(x, _c); 93 } 94 95 99 public void accept(net.sf.jga.fn.Visitor v) { 100 if (v instanceof Bind2nd.Visitor) 101 ((Bind2nd.Visitor)v).visit(this); 102 else 103 v.visit(this); 104 } 105 106 108 public String toString() { 109 return _f+".bind2nd("+_c+")"; 110 } 111 112 114 117 public interface Visitor extends net.sf.jga.fn.Visitor { 118 public void visit(Bind2nd bf); 119 } 120 } 121 | Popular Tags |