KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > MutableShortConverter


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

3 package jodd.typeconverter;
4
5 import jodd.mutable.MutableShort;
6
7
8 /**
9  * Converts given object to {@link MutableShort}. Given object (if not already instance of
10  * MutableShort) is first converted to String and then analyzed.
11  */

12 public class MutableShortConverter implements TypeConverter {
13
14
15     public static MutableShort valueOf(Object JavaDoc value) {
16
17         if (value == null) {
18             return null;
19         }
20         if (value instanceof MutableShort) {
21             return (MutableShort) value;
22         }
23         if (value instanceof Number JavaDoc) {
24             return new MutableShort(((Number JavaDoc)value).byteValue());
25         }
26         try {
27             return new MutableShort(value.toString());
28         } catch (NumberFormatException JavaDoc nfex) {
29             throw new TypeConversionException(nfex);
30         }
31     }
32
33     public Object JavaDoc convert(Object JavaDoc value) {
34         return valueOf(value);
35     }
36
37 }
38
Popular Tags