KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > converters > DoubleConverter


1 package jodd.bean.converters;
2
3 /**
4  * Converts given object to Double.
5  */

6 public final class DoubleConverter implements jodd.bean.Converter {
7
8     public Object convert(Object value) {
9
10         if (value == null) {
11             return (Double) null;
12         }
13
14         if (value instanceof Double) {
15             return value;
16         } else if (value instanceof Number) {
17             return new Double(((Number)value).doubleValue());
18         }
19
20         try {
21             return (new Double(value.toString()));
22         } catch (Exception e) {
23             throw new IllegalArgumentException("Double conversion for " + value + " failed.");
24         }
25     }
26 }
27
Popular Tags