1 33 package net.sf.jga.fn.adaptor; 34 35 import net.sf.jga.fn.Generator; 36 import net.sf.jga.fn.UnaryFunctor; 37 38 46 47 public class Bind<T, R> extends Generator<R> { 48 49 static final long serialVersionUID = -7970887561245835912L; 50 51 private UnaryFunctor<T, R> _f; 53 54 private T _c; 56 57 61 public Bind(T constant, UnaryFunctor<T, R> fn) { 62 if (fn == null) { 63 throw new IllegalArgumentException ("Must supply a function"); 64 } 65 66 _f = fn; 67 _c = constant; 68 } 69 70 74 public UnaryFunctor<T, R> getFunctor() { return _f; } 75 76 80 public T getConstant() { return _c; } 81 82 84 90 public R gen() { 91 return _f.fn(_c); 92 } 93 94 98 public void accept(net.sf.jga.fn.Visitor v) { 99 if (v instanceof Bind.Visitor) 100 ((Bind.Visitor)v).visit(this); 101 else 102 v.visit(this); 103 } 104 105 107 public String toString() { 108 return _f+".bind("+_c+")"; 109 } 110 111 113 116 public interface Visitor extends net.sf.jga.fn.Visitor { 117 public void visit(Bind bf); 118 } 119 } 120 | Popular Tags |