1 16 17 package org.apache.commons.math.util; 18 19 import java.io.Serializable ; 20 21 import org.apache.commons.math.MathException; 22 23 31 public class DefaultTransformer implements NumberTransformer, Serializable { 32 33 34 static final long serialVersionUID = 4019938025047800455L; 35 36 43 public double transform(Object o) throws MathException{ 44 45 if (o == null) { 46 throw new MathException("Conversion Exception in Transformation, Object is null"); 47 } 48 49 if (o instanceof Number ) { 50 return ((Number )o).doubleValue(); 51 } 52 53 try { 54 return new Double (o.toString()).doubleValue(); 55 } catch (Exception e) { 56 throw new MathException("Conversion Exception in Transformation: " + e.getMessage(), e); 57 } 58 } 59 } | Popular Tags |