KickJava   Java API By Example, From Geeks To Geeks.

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


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  * number parser, that creates Double objects
19  */

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