KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > BigIntegerConverter


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

3 package jodd.typeconverter;
4
5 import java.math.BigInteger JavaDoc;
6
7 /**
8  * Converts given object to BigInteger.
9  */

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