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: Delta Record<P>
024: * Description: controls the accuracy of the calculations<P>
025: * REFERENCE: PG 303 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
026: * @author Andrew C. Oliver (acoliver at apache dot org)
027: * @author Jason Height (jheight at chariot dot net dot au)
028: * @version 2.0-pre
029: */
030:
031: public class DeltaRecord extends Record {
032: public final static short sid = 0x10;
033: public final static double DEFAULT_VALUE = 0.0010; // should be .001
034:
035: // a double is an IEEE 8-byte float...damn IEEE and their goofy standards an
036: // ambiguous numeric identifiers
037: private double field_1_max_change;
038:
039: public DeltaRecord() {
040: }
041:
042: /**
043: * Constructs a Delta record and sets its fields appropriately.
044: * @param in the RecordInputstream to read the record from
045: */
046:
047: public DeltaRecord(RecordInputStream in) {
048: super (in);
049: }
050:
051: protected void validateSid(short id) {
052: if (id != sid) {
053: throw new RecordFormatException("NOT A DELTA RECORD");
054: }
055: }
056:
057: protected void fillFields(RecordInputStream in) {
058: field_1_max_change = in.readDouble();
059: }
060:
061: /**
062: * set the maximum change
063: * @param maxChange - maximum rounding error
064: */
065:
066: public void setMaxChange(double maxChange) {
067: field_1_max_change = maxChange;
068: }
069:
070: /**
071: * get the maximum change
072: * @return maxChange - maximum rounding error
073: */
074:
075: public double getMaxChange() {
076: return field_1_max_change;
077: }
078:
079: public String toString() {
080: StringBuffer buffer = new StringBuffer();
081:
082: buffer.append("[DELTA]\n");
083: buffer.append(" .maxchange = ").append(getMaxChange())
084: .append("\n");
085: buffer.append("[/DELTA]\n");
086: return buffer.toString();
087: }
088:
089: public int serialize(int offset, byte[] data) {
090: LittleEndian.putShort(data, 0 + offset, sid);
091: LittleEndian.putShort(data, 2 + offset, (short) 0x8);
092: LittleEndian.putDouble(data, 4 + offset, getMaxChange());
093: return getRecordSize();
094: }
095:
096: public int getRecordSize() {
097: return 12;
098: }
099:
100: public short getSid() {
101: return sid;
102: }
103:
104: public Object clone() {
105: DeltaRecord rec = new DeltaRecord();
106: rec.field_1_max_change = field_1_max_change;
107: return rec;
108: }
109: }
|