1 33 package net.sf.jga.fn.arithmetic; 34 35 import java.text.MessageFormat ; 36 import net.sf.jga.fn.EvaluationException; 37 import net.sf.jga.fn.UnaryFunctor; 38 39 47 48 public class ValueOf<T extends Number ,R extends Number > extends UnaryFunctor<T,R> { 49 50 static final long serialVersionUID = -5844974650711636917L; 51 52 private Arithmetic<R> _math; 53 54 private Class <R> _class; 55 56 64 public ValueOf(Class <R> c) { 65 _class = c; 66 _math = ArithmeticFactory.getArithmetic(c); 67 if (_math == null) { 68 String msg = "No implementation of Arithmetic registered for {0}"; 69 throw new IllegalArgumentException (MessageFormat.format(msg, new Object []{c})); 70 } 71 } 72 73 75 79 public R fn(T x) { 80 return _math.valueOf(x); 81 } 82 83 87 public void accept(net.sf.jga.fn.Visitor v) { 88 if (v instanceof ValueOf.Visitor) 89 ((ValueOf.Visitor)v).visit(this); 90 else 91 v.visit(this); 92 } 93 94 96 public String toString() { 97 return "ValueOf["+_class.getName()+"]"; 98 } 99 100 102 105 public interface Visitor extends net.sf.jga.fn.Visitor { 106 public void visit(ValueOf host); 107 } 108 } 109 | Popular Tags |