KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > converters > IntegerConverter


1 package jodd.bean.converters;
2
3 /**
4  * Converts given object to an Integer.
5  */

6 public final class IntegerConverter implements jodd.bean.Converter {
7
8     public Object convert(Object value) throws IllegalArgumentException {
9         
10         if (value == null) {
11             return (Integer) null;
12         }
13
14         if (value instanceof Integer) {
15             return (value);
16         } else if (value instanceof Number) {
17             return new Integer(((Number)value).intValue());
18         }
19         try {
20             return (new Integer(value.toString()));
21         } catch (Exception e) {
22             throw new IllegalArgumentException("Integer conversion for " + value + " failed.");
23         }
24     }
25 }
26
Popular Tags