KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > LongConverter


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

3 package jodd.typeconverter;
4
5 /**
6  * Converts given object to a Long.
7  */

8 public class LongConverter implements TypeConverter {
9
10     public static Long JavaDoc valueOf(Object JavaDoc value) {
11         
12         if (value == null) {
13             return null;
14         }
15         if (value instanceof Long JavaDoc) {
16             return (Long JavaDoc) value;
17         }
18         if (value instanceof Number JavaDoc) {
19             return new Long JavaDoc(((Number JavaDoc)value).longValue());
20         }
21         try {
22             return (new Long JavaDoc(value.toString()));
23         } catch (NumberFormatException JavaDoc nfex) {
24             throw new TypeConversionException(nfex);
25         }
26     }
27
28     public Object JavaDoc convert(Object JavaDoc value) {
29         return valueOf(value);
30     }
31     
32 }
33
Popular Tags