KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > format > IntegerHandler


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.format;
14
15 import java.util.List JavaDoc;
16
17
18 /**
19  * creates Integer objects
20  * @author av
21  */

22 public class IntegerHandler extends NumberHandler {
23
24   public Object JavaDoc parse(String JavaDoc s, String JavaDoc userPattern) throws FormatException {
25     Number JavaDoc n = (Number JavaDoc) super.parse(s, userPattern);
26     return new Integer JavaDoc(n.intValue());
27   }
28
29   public boolean canHandle(Object JavaDoc value) {
30     return value instanceof Integer JavaDoc;
31   }
32   
33   public Object JavaDoc toNativeArray(List JavaDoc list) {
34     int[] array = new int[list.size()];
35     for (int i = 0; i < array.length; i++)
36       array[i] = ((Number JavaDoc)list.get(i)).intValue();
37     return array;
38   }
39   
40   public Object JavaDoc[] toObjectArray(Object JavaDoc value) {
41     if (value instanceof Integer JavaDoc)
42       return new Integer JavaDoc[]{(Integer JavaDoc)value};
43     int[] src = (int[])value;
44     Integer JavaDoc[] dst = new Integer JavaDoc[src.length];
45     for (int i = 0; i < src.length; i++)
46       dst[i] = new Integer JavaDoc(src[i]);
47     return dst;
48   }
49   
50 }
Popular Tags