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.aggregates;
019:
020: import org.apache.poi.hssf.record.*;
021:
022: /**
023: * The formula record aggregate is used to join together the formula record and it's
024: * (optional) string record and (optional) Shared Formula Record (template reads, excel optimization).
025: *
026: * @author Glen Stampoultzis (glens at apache.org)
027: */
028: public class FormulaRecordAggregate extends Record implements
029: CellValueRecordInterface, Comparable {
030: public final static short sid = -2000;
031:
032: private FormulaRecord formulaRecord;
033: private StringRecord stringRecord;
034:
035: public FormulaRecordAggregate(FormulaRecord formulaRecord,
036: StringRecord stringRecord) {
037: this .formulaRecord = formulaRecord;
038: this .stringRecord = stringRecord;
039: }
040:
041: protected void validateSid(short id) {
042: }
043:
044: protected void fillFields(RecordInputStream in) {
045: }
046:
047: /**
048: * called by the class that is responsible for writing this sucker.
049: * Subclasses should implement this so that their data is passed back in a
050: * byte array.
051: *
052: * @param offset to begin writing at
053: * @param data byte array containing instance data
054: * @return number of bytes written
055: */
056:
057: public int serialize(int offset, byte[] data) {
058: int pos = offset;
059: pos += formulaRecord.serialize(pos, data);
060:
061: if (stringRecord != null) {
062: pos += stringRecord.serialize(pos, data);
063: }
064: return pos - offset;
065:
066: }
067:
068: /**
069: * gives the current serialized size of the record. Should include the sid and reclength (4 bytes).
070: */
071: public int getRecordSize() {
072: int size = formulaRecord.getRecordSize()
073: + (stringRecord == null ? 0 : stringRecord
074: .getRecordSize());
075: return size;
076: }
077:
078: /**
079: * return the non static version of the id for this record.
080: */
081: public short getSid() {
082: return sid;
083: }
084:
085: public void setStringRecord(StringRecord stringRecord) {
086: this .stringRecord = stringRecord;
087: }
088:
089: public void setFormulaRecord(FormulaRecord formulaRecord) {
090: this .formulaRecord = formulaRecord;
091: }
092:
093: public FormulaRecord getFormulaRecord() {
094: return formulaRecord;
095: }
096:
097: public StringRecord getStringRecord() {
098: return stringRecord;
099: }
100:
101: public boolean isEqual(CellValueRecordInterface i) {
102: return formulaRecord.isEqual(i);
103: }
104:
105: public boolean isAfter(CellValueRecordInterface i) {
106: return formulaRecord.isAfter(i);
107: }
108:
109: public boolean isBefore(CellValueRecordInterface i) {
110: return formulaRecord.isBefore(i);
111: }
112:
113: public short getXFIndex() {
114: return formulaRecord.getXFIndex();
115: }
116:
117: public void setXFIndex(short xf) {
118: formulaRecord.setXFIndex(xf);
119: }
120:
121: public void setColumn(short col) {
122: formulaRecord.setColumn(col);
123: }
124:
125: public void setRow(int row) {
126: formulaRecord.setRow(row);
127: }
128:
129: public short getColumn() {
130: return formulaRecord.getColumn();
131: }
132:
133: public int getRow() {
134: return formulaRecord.getRow();
135: }
136:
137: public int compareTo(Object o) {
138: return formulaRecord.compareTo(o);
139: }
140:
141: public boolean equals(Object obj) {
142: return formulaRecord.equals(obj);
143: }
144:
145: public String toString() {
146: return formulaRecord.toString();
147: }
148:
149: /**
150: * @see java.lang.Object#clone()
151: */
152: public Object clone() {
153: StringRecord clonedString = (stringRecord == null) ? null
154: : (StringRecord) stringRecord.clone();
155:
156: return new FormulaRecordAggregate(
157: (FormulaRecord) this .formulaRecord.clone(),
158: clonedString);
159: }
160:
161: /*
162: * Setting to true so that this value does not abort the whole ValueAggregation
163: * (non-Javadoc)
164: * @see org.apache.poi.hssf.record.Record#isInValueSection()
165: */
166: public boolean isInValueSection() {
167:
168: return true;
169: }
170:
171: public String getStringValue() {
172: if (stringRecord == null)
173: return null;
174: return stringRecord.getString();
175: }
176: }
|