KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > DoubleValue


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.formula;
21
22 import common.Logger;
23
24 import jxl.Cell;
25 import jxl.biff.DoubleHelper;
26
27 /**
28  * A cell reference in a formula
29  */

30 class DoubleValue extends NumberValue implements ParsedThing
31 {
32   /**
33    * The logger
34    */

35   private static Logger logger = Logger.getLogger(DoubleValue.class);
36
37   /**
38    * The value of this double in the formula
39    */

40   private double value;
41
42   /**
43    * Constructor
44    */

45   public DoubleValue()
46   {
47   }
48
49   /**
50    * Constructor - invoked when writing an integer value that's out
51    * of range for a short
52    */

53   DoubleValue(double v)
54   {
55     value = v;
56   }
57
58   /**
59    * Constructor for a double value when reading from a string
60    */

61   public DoubleValue(String JavaDoc s)
62   {
63     try
64     {
65       value = Double.parseDouble(s);
66     }
67     catch (NumberFormatException JavaDoc e)
68     {
69       logger.warn(e, e);
70       value = 0;
71     }
72   }
73
74   /**
75    * Reads the ptg data from the array starting at the specified position
76    *
77    * @param data the RPN array
78    * @param pos the current position in the array, excluding the ptg identifier
79    * @return the number of bytes read
80    */

81   public int read(byte[] data, int pos)
82   {
83     value = DoubleHelper.getIEEEDouble(data, pos);
84
85     return 8;
86   }
87
88   /**
89    * Gets the token representation of this item in RPN
90    *
91    * @return the bytes applicable to this formula
92    */

93   byte[] getBytes()
94   {
95     byte[] data = new byte[9];
96     data[0] = Token.DOUBLE.getCode();
97
98     DoubleHelper.getIEEEBytes(value, data, 1);
99
100     return data;
101   }
102
103   public double getValue()
104   {
105     return value;
106   }
107 }
108
Popular Tags