KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > DeltaRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: Delta Record<P>
25  * Description: controls the accuracy of the calculations<P>
26  * REFERENCE: PG 303 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
27  * @author Andrew C. Oliver (acoliver at apache dot org)
28  * @author Jason Height (jheight at chariot dot net dot au)
29  * @version 2.0-pre
30  */

31
32 public class DeltaRecord
33     extends Record
34 {
35     public final static short sid = 0x10;
36     public final static double DEFAULT_VALUE = 0.0010; // should be .001
37

38     // a double is an IEEE 8-byte float...damn IEEE and their goofy standards an
39
// ambiguous numeric identifiers
40
private double field_1_max_change;
41
42     public DeltaRecord()
43     {
44     }
45
46     /**
47      * Constructs a Delta record and sets its fields appropriately.
48      *
49      * @param id id must be 0x10 or an exception will be throw upon validation
50      * @param size the size of the data area of the record
51      * @param data data of the record (should not contain sid/len)
52      */

53
54     public DeltaRecord(short id, short size, byte [] data)
55     {
56         super(id, size, data);
57     }
58
59     /**
60      * Constructs a Delta record and sets its fields appropriately.
61      *
62      * @param id id must be 0x10 or an exception will be throw upon validation
63      * @param size the size of the data area of the record
64      * @param data data of the record (should not contain sid/len)
65      * @param offset of record data
66      */

67
68     public DeltaRecord(short id, short size, byte [] data, int offset)
69     {
70         super(id, size, data, offset);
71     }
72
73     protected void validateSid(short id)
74     {
75         if (id != sid)
76         {
77             throw new RecordFormatException("NOT A DELTA RECORD");
78         }
79     }
80
81     protected void fillFields(byte [] data, short size, int offset)
82     {
83         field_1_max_change = LittleEndian.getDouble(data, 0 + offset);
84     }
85
86     /**
87      * set the maximum change
88      * @param maxChange - maximum rounding error
89      */

90
91     public void setMaxChange(double maxChange)
92     {
93         field_1_max_change = maxChange;
94     }
95
96     /**
97      * get the maximum change
98      * @return maxChange - maximum rounding error
99      */

100
101     public double getMaxChange()
102     {
103         return field_1_max_change;
104     }
105
106     public String JavaDoc toString()
107     {
108         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
109
110         buffer.append("[DELTA]\n");
111         buffer.append(" .maxchange = ").append(getMaxChange())
112             .append("\n");
113         buffer.append("[/DELTA]\n");
114         return buffer.toString();
115     }
116
117     public int serialize(int offset, byte [] data)
118     {
119         LittleEndian.putShort(data, 0 + offset, sid);
120         LittleEndian.putShort(data, 2 + offset, ( short ) 0x8);
121         LittleEndian.putDouble(data, 4 + offset, getMaxChange());
122         return getRecordSize();
123     }
124
125     public int getRecordSize()
126     {
127         return 12;
128     }
129
130     public short getSid()
131     {
132         return this.sid;
133     }
134
135     public Object JavaDoc clone() {
136       DeltaRecord rec = new DeltaRecord();
137       rec.field_1_max_change = field_1_max_change;
138       return rec;
139     }
140 }
141
Popular Tags