01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.record.formula;
19:
20: import org.apache.poi.util.LittleEndian;
21: import org.apache.poi.hssf.model.Workbook;
22: import org.apache.poi.hssf.record.RecordInputStream;
23:
24: /**
25: * Number
26: * Stores a floating point value in a formula
27: * value stored in a 8 byte field using IEEE notation
28: * @author Avik Sengupta
29: * @author Jason Height (jheight at chariot dot net dot au)
30: */
31:
32: public class NumberPtg extends Ptg {
33: public final static int SIZE = 9;
34: public final static byte sid = 0x1f;
35: private double field_1_value;
36:
37: private NumberPtg() {
38: //Required for clone methods
39: }
40:
41: /** Create a NumberPtg from a byte array read from disk */
42: public NumberPtg(RecordInputStream in) {
43: setValue(in.readDouble());
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 value) {
52: setValue(Double.parseDouble(value));
53: }
54:
55: public void setValue(double value) {
56: field_1_value = value;
57: }
58:
59: public double getValue() {
60: return field_1_value;
61: }
62:
63: public void writeBytes(byte[] array, int offset) {
64: array[offset + 0] = sid;
65: LittleEndian.putDouble(array, offset + 1, getValue());
66: }
67:
68: public int getSize() {
69: return SIZE;
70: }
71:
72: public String toFormulaString(Workbook book) {
73: return "" + getValue();
74: }
75:
76: public byte getDefaultOperandClass() {
77: return Ptg.CLASS_VALUE;
78: }
79:
80: public Object clone() {
81: NumberPtg ptg = new NumberPtg();
82: ptg.field_1_value = field_1_value;
83: return ptg;
84: }
85: }
|