1 33 package net.sf.jga.fn.arithmetic; 34 35 import java.math.BigDecimal ; 36 import java.math.BigInteger ; 37 import java.util.HashMap ; 38 39 48 49 public class ArithmeticFactory { 50 static private HashMap <Class <? extends Number >,Arithmetic<? extends Number >> 51 _arithmeticMap = new HashMap <Class <? extends Number >,Arithmetic<? extends Number >>(); 52 53 static private HashMap <Class <? extends Number >,IntegerArithmetic<? extends Number >> 54 _integralMap = new HashMap <Class <? extends Number >,IntegerArithmetic<? extends Number >>(); 55 56 59 static public <T extends Number > void register (Class <T> c, Arithmetic<T> math) { 60 _arithmeticMap.put(c, math); 61 } 62 63 66 static public <T extends Number > void register (Class <T> c, IntegerArithmetic<T> math) { 67 _arithmeticMap.put(c, math); 68 _integralMap.put(c, math); 69 } 70 71 75 static public <T extends Number > Arithmetic<T> getArithmetic (Class <T> c) { 76 return (Arithmetic<T>) _arithmeticMap.get(c); 81 } 82 83 89 static public <T extends Number > IntegerArithmetic<T> getIntegralArithmetic (Class <T> c) { 90 return (IntegerArithmetic<T>) _integralMap.get(c); 95 } 96 97 static { 98 register(Byte .class, new ByteMath()); 99 register(Short .class, new ShortMath()); 100 register(Integer .class, new IntegerMath()); 101 register(Long .class, new LongMath()); 102 register(Float .class, new FloatMath()); 103 register(Double .class, new DoubleMath()); 104 register(BigDecimal .class, new DecimalMath()); 105 register(BigInteger .class, new BigIntMath()); 106 } 107 } 108 | Popular Tags |