KickJava   Java API By Example, From Geeks To Geeks.

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


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: Iteration Record<P>
25  * Description: Tells whether to iterate over forumla calculations or not
26  * (if a formula is dependant upon another formula's result)
27  * (odd feature for something that can only have 32 elements in
28  * a formula!)<P>
29  * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
30  * @author Andrew C. Oliver (acoliver at apache dot org)
31  * @author Jason Height (jheight at chariot dot net dot au)
32  * @version 2.0-pre
33  */

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

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

66
67     public IterationRecord(short id, short size, byte [] data, int offset)
68     {
69         super(id, size, data, offset);
70     }
71
72     protected void validateSid(short id)
73     {
74         if (id != sid)
75         {
76             throw new RecordFormatException("NOT An ITERATION RECORD");
77         }
78     }
79
80     protected void fillFields(byte [] data, short size, int offset)
81     {
82         field_1_iteration = LittleEndian.getShort(data, 0 + offset);
83     }
84
85     /**
86      * set whether or not to iterate for calculations
87      * @param iterate or not
88      */

89
90     public void setIteration(boolean iterate)
91     {
92         if (iterate)
93         {
94             field_1_iteration = 1;
95         }
96         else
97         {
98             field_1_iteration = 0;
99         }
100     }
101
102     /**
103      * get whether or not to iterate for calculations
104      *
105      * @return whether iterative calculations are turned off or on
106      */

107
108     public boolean getIteration()
109     {
110         return (field_1_iteration == 1);
111     }
112
113     public String JavaDoc toString()
114     {
115         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
116
117         buffer.append("[ITERATION]\n");
118         buffer.append(" .iteration = ").append(getIteration())
119             .append("\n");
120         buffer.append("[/ITERATION]\n");
121         return buffer.toString();
122     }
123
124     public int serialize(int offset, byte [] data)
125     {
126         LittleEndian.putShort(data, 0 + offset, sid);
127         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
128         LittleEndian.putShort(data, 4 + offset, field_1_iteration);
129         return getRecordSize();
130     }
131
132     public int getRecordSize()
133     {
134         return 6;
135     }
136
137     public short getSid()
138     {
139         return this.sid;
140     }
141
142     public Object JavaDoc clone() {
143       IterationRecord rec = new IterationRecord();
144       rec.field_1_iteration = field_1_iteration;
145       return rec;
146     }
147 }
148
Popular Tags