01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.typeconverter;
04:
05: import jodd.mutable.MutableFloat;
06:
07: /**
08: * Converts given object to {@link MutableFloat}.
09: */
10: public class MutableFloatConverter implements TypeConverter {
11:
12: public static MutableFloat valueOf(Object 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) {
21: return new MutableFloat(((Number) value).floatValue());
22: }
23: try {
24: return new MutableFloat(value.toString());
25: } catch (Exception ex) {
26: throw new TypeConversionException(
27: "MutableFloat conversion for '" + value
28: + "' failed.", ex);
29: }
30: }
31:
32: public Object convert(Object value) {
33: return valueOf(value);
34: }
35:
36: }
|