KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > CharacterConverter


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 Character.
7  */

8 public class CharacterConverter implements TypeConverter {
9
10     public static Character JavaDoc valueOf(Object JavaDoc value) {
11
12         if (value == null) {
13             return null;
14         }
15         if (value instanceof Character JavaDoc) {
16             return (Character JavaDoc) value;
17         }
18         try {
19             return (new Character JavaDoc(value.toString().charAt(0)));
20         } catch (IndexOutOfBoundsException JavaDoc ioobex) {
21             throw new TypeConversionException(ioobex);
22         }
23     }
24
25     public Object JavaDoc convert(Object JavaDoc value) {
26         return valueOf(value);
27     }
28     
29 }
30
Popular Tags