KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > MutableFloatConverter


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

3 package jodd.typeconverter;
4
5 import jodd.mutable.MutableFloat;
6
7 /**
8  * Converts given object to {@link MutableFloat}.
9  */

10 public class MutableFloatConverter implements TypeConverter {
11
12     public static MutableFloat valueOf(Object JavaDoc value) {
13
14         if (value == null) {
15             return null;
16         }
17         if (value instanceof MutableFloat) {
18             return (MutableFloat) value;
19         }
20         if (value instanceof Number JavaDoc) {
21             return new MutableFloat(((Number JavaDoc)value).floatValue());
22         }
23         try {
24             return new MutableFloat(value.toString());
25         } catch (Exception JavaDoc ex) {
26             throw new TypeConversionException("MutableFloat conversion for '" + value + "' failed.", ex);
27         }
28     }
29
30     public Object JavaDoc convert(Object JavaDoc value) {
31         return valueOf(value);
32     }
33     
34 }
35
Popular Tags