KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > DoubleConverter


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.typeconverter;
4
5 /**
6  * Converts given object to Double.
7  */

8 public class DoubleConverter implements TypeConverter {
9
10     public static Double JavaDoc valueOf(Object JavaDoc value) {
11
12         if (value == null) {
13             return null;
14         }
15         if (value instanceof Double JavaDoc) {
16             return (Double JavaDoc) value;
17         }
18         if (value instanceof Number JavaDoc) {
19             return new Double JavaDoc(((Number JavaDoc)value).doubleValue());
20         }
21
22         try {
23             return (new Double JavaDoc(value.toString()));
24         } catch (NumberFormatException JavaDoc nfex) {
25             throw new TypeConversionException(nfex);
26         }
27     }
28
29     public Object JavaDoc convert(Object JavaDoc value) {
30         return valueOf(value);
31     }
32     
33 }
34
Popular Tags