KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > formula > NumberPtg


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.record.formula;
18
19 import org.apache.poi.util.LittleEndian;
20 import org.apache.poi.hssf.model.Workbook;
21 /**
22  * Number
23  * Stores a floating point value in a formula
24  * value stored in a 8 byte field using IEEE notation
25  * @author Avik Sengupta
26  * @author Jason Height (jheight at chariot dot net dot au)
27  */

28
29 public class NumberPtg
30     extends Ptg
31 {
32     public final static int SIZE = 9;
33     public final static byte sid = 0x1f;
34     private double field_1_value;
35
36     private NumberPtg() {
37       //Required for clone methods
38
}
39         
40     /** Create a NumberPtg from a byte array read from disk */
41     public NumberPtg(byte [] data, int offset)
42     {
43         setValue(LittleEndian.getDouble(data, offset + 1));
44     }
45     
46     /** Create a NumberPtg from a string representation of the number
47      * Number format is not checked, it is expected to be validated in the parser
48      * that calls this method.
49      * @param value : String representation of a floating point number
50      */

51     public NumberPtg(String JavaDoc value) {
52         setValue(Double.parseDouble(value));
53     }
54     
55     
56     public void setValue(double value)
57     {
58         field_1_value = value;
59     }
60     
61     
62     public double getValue()
63     {
64         return field_1_value;
65     }
66
67     public void writeBytes(byte [] array, int offset)
68     {
69         array[ offset + 0 ] = sid;
70         LittleEndian.putDouble(array, offset + 1, getValue());
71     }
72
73     public int getSize()
74     {
75         return SIZE;
76     }
77
78     public String JavaDoc toFormulaString(Workbook book)
79     {
80         return "" + getValue();
81     }
82        public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
83
84     public Object JavaDoc clone() {
85       NumberPtg ptg = new NumberPtg();
86       ptg.field_1_value = field_1_value;
87       return ptg;
88     }
89 }
90
Popular Tags