KickJava   Java API By Example, From Geeks To Geeks.

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


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: Calc Count Record
25  * Description: Specifies the maximum times the gui should perform a formula
26  * recalculation. For instance: in the case a formula includes
27  * cells that are themselves a result of a formula and a value
28  * changes. This is essentially a failsafe against an infinate
29  * loop in the event the formulas are not independant. <P>
30  * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
31  * @author Andrew C. Oliver (acoliver at apache dot org)
32  * @author Jason Height (jheight at chariot dot net dot au)
33  * @version 2.0-pre
34  * @see org.apache.poi.hssf.record.CalcModeRecord
35  */

36
37 public class CalcCountRecord
38     extends Record
39 {
40     public final static short sid = 0xC;
41     private short field_1_iterations;
42
43     public CalcCountRecord()
44     {
45     }
46
47     /**
48      * Constructs a CalcCountRecord and sets its fields appropriately
49      *
50      * @param id id must be 0xC or an exception will be throw upon validation
51      * @param size the size of the data area of the record
52      * @param data data of the record (should not contain sid/len)
53      *
54      */

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

69
70     public CalcCountRecord(short id, short size, byte [] data, int offset)
71     {
72         super(id, size, data, offset);
73     }
74
75     protected void validateSid(short id)
76     {
77         if (id != sid)
78         {
79             throw new RecordFormatException("NOT An Calc Count RECORD");
80         }
81     }
82
83     protected void fillFields(byte [] data, short size, int offset)
84     {
85         field_1_iterations = LittleEndian.getShort(data, 0 + offset);
86     }
87
88     /**
89      * set the number of iterations to perform
90      * @param iterations to perform
91      */

92
93     public void setIterations(short iterations)
94     {
95         field_1_iterations = iterations;
96     }
97
98     /**
99      * get the number of iterations to perform
100      * @return iterations
101      */

102
103     public short getIterations()
104     {
105         return field_1_iterations;
106     }
107
108     public String JavaDoc toString()
109     {
110         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
111
112         buffer.append("[CALCCOUNT]\n");
113         buffer.append(" .iterations = ")
114             .append(Integer.toHexString(getIterations())).append("\n");
115         buffer.append("[/CALCCOUNT]\n");
116         return buffer.toString();
117     }
118
119     public int serialize(int offset, byte [] data)
120     {
121         LittleEndian.putShort(data, 0 + offset, sid);
122         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
123         LittleEndian.putShort(data, 4 + offset, getIterations());
124         return getRecordSize();
125     }
126
127     public int getRecordSize()
128     {
129         return 6;
130     }
131
132     public short getSid()
133     {
134         return this.sid;
135     }
136
137     public Object JavaDoc clone() {
138       CalcCountRecord rec = new CalcCountRecord();
139       rec.field_1_iterations = field_1_iterations;
140       return rec;
141     }
142 }
143
Popular Tags