KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > MutableByteConverter


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

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

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