KickJava   Java API By Example, From Geeks To Geeks.

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


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

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