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: Calc Count Record
024: * Description: Specifies the maximum times the gui should perform a formula
025: * recalculation. For instance: in the case a formula includes
026: * cells that are themselves a result of a formula and a value
027: * changes. This is essentially a failsafe against an infinate
028: * loop in the event the formulas are not independant. <P>
029: * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
030: * @author Andrew C. Oliver (acoliver at apache dot org)
031: * @author Jason Height (jheight at chariot dot net dot au)
032: * @version 2.0-pre
033: * @see org.apache.poi.hssf.record.CalcModeRecord
034: */
035:
036: public class CalcCountRecord extends Record {
037: public final static short sid = 0xC;
038: private short field_1_iterations;
039:
040: public CalcCountRecord() {
041: }
042:
043: /**
044: * Constructs a CalcCountRecord and sets its fields appropriately
045: * @param in the RecordInputstream to read the record from
046: *
047: */
048:
049: public CalcCountRecord(RecordInputStream in) {
050: super (in);
051: }
052:
053: protected void validateSid(short id) {
054: if (id != sid) {
055: throw new RecordFormatException("NOT An Calc Count RECORD");
056: }
057: }
058:
059: protected void fillFields(RecordInputStream in) {
060: field_1_iterations = in.readShort();
061: }
062:
063: /**
064: * set the number of iterations to perform
065: * @param iterations to perform
066: */
067:
068: public void setIterations(short iterations) {
069: field_1_iterations = iterations;
070: }
071:
072: /**
073: * get the number of iterations to perform
074: * @return iterations
075: */
076:
077: public short getIterations() {
078: return field_1_iterations;
079: }
080:
081: public String toString() {
082: StringBuffer buffer = new StringBuffer();
083:
084: buffer.append("[CALCCOUNT]\n");
085: buffer.append(" .iterations = ").append(
086: Integer.toHexString(getIterations())).append("\n");
087: buffer.append("[/CALCCOUNT]\n");
088: return buffer.toString();
089: }
090:
091: public int serialize(int offset, byte[] data) {
092: LittleEndian.putShort(data, 0 + offset, sid);
093: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
094: LittleEndian.putShort(data, 4 + offset, getIterations());
095: return getRecordSize();
096: }
097:
098: public int getRecordSize() {
099: return 6;
100: }
101:
102: public short getSid() {
103: return sid;
104: }
105:
106: public Object clone() {
107: CalcCountRecord rec = new CalcCountRecord();
108: rec.field_1_iterations = field_1_iterations;
109: return rec;
110: }
111: }
|