001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Iteration Record<P>
024: * Description: Tells whether to iterate over forumla calculations or not
025: * (if a formula is dependant upon another formula's result)
026: * (odd feature for something that can only have 32 elements in
027: * a formula!)<P>
028: * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
029: * @author Andrew C. Oliver (acoliver at apache dot org)
030: * @author Jason Height (jheight at chariot dot net dot au)
031: * @version 2.0-pre
032: */
033:
034: public class IterationRecord extends Record {
035: public final static short sid = 0x11;
036: private short field_1_iteration;
037:
038: public IterationRecord() {
039: }
040:
041: /**
042: * Constructs an Iteration record and sets its fields appropriately.
043: * @param in the RecordInputstream to read the record from
044: */
045:
046: public IterationRecord(RecordInputStream in) {
047: super (in);
048: }
049:
050: protected void validateSid(short id) {
051: if (id != sid) {
052: throw new RecordFormatException("NOT An ITERATION RECORD");
053: }
054: }
055:
056: protected void fillFields(RecordInputStream in) {
057: field_1_iteration = in.readShort();
058: }
059:
060: /**
061: * set whether or not to iterate for calculations
062: * @param iterate or not
063: */
064:
065: public void setIteration(boolean iterate) {
066: if (iterate) {
067: field_1_iteration = 1;
068: } else {
069: field_1_iteration = 0;
070: }
071: }
072:
073: /**
074: * get whether or not to iterate for calculations
075: *
076: * @return whether iterative calculations are turned off or on
077: */
078:
079: public boolean getIteration() {
080: return (field_1_iteration == 1);
081: }
082:
083: public String toString() {
084: StringBuffer buffer = new StringBuffer();
085:
086: buffer.append("[ITERATION]\n");
087: buffer.append(" .iteration = ").append(getIteration())
088: .append("\n");
089: buffer.append("[/ITERATION]\n");
090: return buffer.toString();
091: }
092:
093: public int serialize(int offset, byte[] data) {
094: LittleEndian.putShort(data, 0 + offset, sid);
095: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
096: LittleEndian.putShort(data, 4 + offset, field_1_iteration);
097: return getRecordSize();
098: }
099:
100: public int getRecordSize() {
101: return 6;
102: }
103:
104: public short getSid() {
105: return sid;
106: }
107:
108: public Object clone() {
109: IterationRecord rec = new IterationRecord();
110: rec.field_1_iteration = field_1_iteration;
111: return rec;
112: }
113: }
|