Removed unused methods from CellValueRecordInterface. Converted FormulaRecordAggregate to RecordAggregate subclass

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@689721 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-08-28 05:25:24 +00:00
parent ac06af4914
commit f17e56b30e
13 changed files with 70 additions and 813 deletions

View File

@ -34,13 +34,8 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/
public class BlankRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final class BlankRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x201;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf;
@ -152,50 +147,6 @@ public class BlankRecord
field_2_col = col;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;
@ -254,50 +205,6 @@ public class BlankRecord
return 10;
}
public int compareTo(Object obj)
{
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return 0;
}
if (this.getRow() < loc.getRow())
{
return -1;
}
if (this.getRow() > loc.getRow())
{
return 1;
}
if (this.getColumn() < loc.getColumn())
{
return -1;
}
if (this.getColumn() > loc.getColumn())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof CellValueRecordInterface))
{
return false;
}
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return true;
}
return false;
}
public Object clone() {
BlankRecord rec = new BlankRecord();
rec.field_1_row = field_1_row;

View File

@ -33,14 +33,9 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/
public class BoolErrRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final class BoolErrRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x205;
//private short field_1_row;
private int field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf_index;
private byte field_4_bBoolErr;
@ -274,50 +269,6 @@ public class BoolErrRecord
return sid;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;
@ -328,50 +279,6 @@ public class BoolErrRecord
return true;
}
public int compareTo(Object obj)
{
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return 0;
}
if (this.getRow() < loc.getRow())
{
return -1;
}
if (this.getRow() > loc.getRow())
{
return 1;
}
if (this.getColumn() < loc.getColumn())
{
return -1;
}
if (this.getColumn() > loc.getColumn())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof CellValueRecordInterface))
{
return false;
}
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return true;
}
return false;
}
public Object clone() {
BoolErrRecord rec = new BoolErrRecord();
rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/*
* CellValueRecordInterface.java
*
* Created on October 2, 2001, 8:27 PM
*/
package org.apache.poi.hssf.record;
/**
@ -36,73 +29,29 @@ package org.apache.poi.hssf.record;
* @see org.apache.poi.hssf.record.Record
* @see org.apache.poi.hssf.record.RecordFactory
*/
public interface CellValueRecordInterface
{
public interface CellValueRecordInterface {
/**
* get the row this cell occurs on
*
* @return the row
* @return the row this cell occurs on
*/
//public short getRow();
public int getRow();
int getRow();
/**
* get the column this cell defines within the row
*
* @return the column
* @return the column this cell defines within the row
*/
public short getColumn();
short getColumn();
/**
* set the row this cell occurs on
* @param row the row this cell occurs within
*/
//public void setRow(short row);
public void setRow(int row);
void setRow(int row);
/**
* set the column this cell defines within the row
*
* @param col the column this cell defines
*/
void setColumn(short col);
public void setColumn(short col);
void setXFIndex(short xf);
public void setXFIndex(short xf);
public short getXFIndex();
/**
* returns whether this cell is before the passed in cell
*
* @param i another cell interface record to compare
* @return true if the cells is before, or false if not
*/
public boolean isBefore(CellValueRecordInterface i);
/**
* returns whether this cell is after the passed in cell
*
* @param i record to compare
* @return true if the cell is after, false if not
*/
public boolean isAfter(CellValueRecordInterface i);
/**
* returns whether this cell represents the same cell (NOT VALUE)
*
* @param i record to compare
* @return true if the cells are the same cell (positionally), false if not.
*/
public boolean isEqual(CellValueRecordInterface i);
public Object clone();
short getXFIndex();
}

View File

@ -32,10 +32,7 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/
public final class FormulaRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final class FormulaRecord extends Record implements CellValueRecordInterface {
public static final short sid = 0x0006; // docs say 406...because of a bug Microsoft support site article #Q184647)
@ -380,50 +377,6 @@ public final class FormulaRecord
return retval;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;
@ -433,51 +386,6 @@ public final class FormulaRecord
{
return true;
}
public int compareTo(Object obj)
{
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return 0;
}
if (this.getRow() < loc.getRow())
{
return -1;
}
if (this.getRow() > loc.getRow())
{
return 1;
}
if (this.getColumn() < loc.getColumn())
{
return -1;
}
if (this.getColumn() > loc.getColumn())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof CellValueRecordInterface))
{
return false;
}
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return true;
}
return false;
}
public String toString()
{

View File

@ -180,51 +180,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
return buffer.toString();
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
@ -30,13 +28,8 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/
public class LabelSSTRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final class LabelSSTRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0xfd;
//private short field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf_index;
@ -183,50 +176,6 @@ public class LabelSSTRecord
return sid;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;
@ -237,50 +186,6 @@ public class LabelSSTRecord
return true;
}
public int compareTo(Object obj)
{
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return 0;
}
if (this.getRow() < loc.getRow())
{
return -1;
}
if (this.getRow() > loc.getRow())
{
return 1;
}
if (this.getColumn() < loc.getColumn())
{
return -1;
}
if (this.getColumn() > loc.getColumn())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof CellValueRecordInterface))
{
return false;
}
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return true;
}
return false;
}
public Object clone() {
LabelSSTRecord rec = new LabelSSTRecord();
rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/*
* NumberRecord.java
*
* Created on October 1, 2001, 8:01 PM
*/
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian;
@ -34,13 +27,8 @@ import org.apache.poi.hssf.record.Record;
* @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre
*/
public class NumberRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final class NumberRecord extends Record implements CellValueRecordInterface {
public static final short sid = 0x203;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf;
@ -203,50 +191,6 @@ public class NumberRecord
return sid;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;
@ -257,50 +201,6 @@ public class NumberRecord
return true;
}
public int compareTo(Object obj)
{
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return 0;
}
if (this.getRow() < loc.getRow())
{
return -1;
}
if (this.getRow() > loc.getRow())
{
return 1;
}
if (this.getColumn() < loc.getColumn())
{
return -1;
}
if (this.getColumn() > loc.getColumn())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof CellValueRecordInterface))
{
return false;
}
CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
if ((this.getRow() == loc.getRow())
&& (this.getColumn() == loc.getColumn()))
{
return true;
}
return false;
}
public Object clone() {
NumberRecord rec = new NumberRecord();
rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
@ -38,17 +36,12 @@ import org.apache.poi.hssf.util.RKUtil;
* @version 2.0-pre
* @see org.apache.poi.hssf.record.NumberRecord
*/
public class RKRecord
extends Record
implements CellValueRecordInterface
{
public final class RKRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x27e;
public final static short RK_IEEE_NUMBER = 0;
public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
public final static short RK_INTEGER = 2;
public final static short RK_INTEGER_TIMES_100 = 3;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf_index;
@ -216,50 +209,6 @@ public class RKRecord
return sid;
}
public boolean isBefore(CellValueRecordInterface i)
{
if (this.getRow() > i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() > i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isAfter(CellValueRecordInterface i)
{
if (this.getRow() < i.getRow())
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() < i.getColumn()))
{
return false;
}
if ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()))
{
return false;
}
return true;
}
public boolean isEqual(CellValueRecordInterface i)
{
return ((this.getRow() == i.getRow())
&& (this.getColumn() == i.getColumn()));
}
public boolean isInValueSection()
{
return true;

View File

@ -15,10 +15,11 @@
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record.aggregates;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.StringRecord;
/**
* The formula record aggregate is used to join together the formula record and it's
@ -26,171 +27,81 @@ import org.apache.poi.hssf.record.*;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class FormulaRecordAggregate
extends Record
implements CellValueRecordInterface, Comparable
{
public final static short sid = -2000;
public final class FormulaRecordAggregate extends RecordAggregate implements CellValueRecordInterface {
private FormulaRecord formulaRecord;
private StringRecord stringRecord;
private FormulaRecord _formulaRecord;
private StringRecord _stringRecord;
public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord )
{
this.formulaRecord = formulaRecord;
this.stringRecord = stringRecord;
_formulaRecord = formulaRecord;
_stringRecord = stringRecord;
}
protected void validateSid( short id )
{
}
protected void fillFields( RecordInputStream in )
{
}
/**
* called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a
* byte array.
*
* @param offset to begin writing at
* @param data byte array containing instance data
* @return number of bytes written
*/
public int serialize( int offset, byte[] data )
{
int pos = offset;
pos += formulaRecord.serialize(pos, data);
if (stringRecord != null)
{
pos += stringRecord.serialize(pos, data);
}
return pos - offset;
}
/**
* gives the current serialized size of the record. Should include the sid and reclength (4 bytes).
*/
public int getRecordSize()
{
int size = formulaRecord.getRecordSize() + (stringRecord == null ? 0 : stringRecord.getRecordSize());
return size;
}
/**
* return the non static version of the id for this record.
*/
public short getSid()
{
return sid;
}
public void setStringRecord( StringRecord stringRecord )
{
this.stringRecord = stringRecord;
public void setStringRecord( StringRecord stringRecord ) {
_stringRecord = stringRecord;
}
public void setFormulaRecord( FormulaRecord formulaRecord )
{
this.formulaRecord = formulaRecord;
_formulaRecord = formulaRecord;
}
public FormulaRecord getFormulaRecord()
{
return formulaRecord;
return _formulaRecord;
}
public StringRecord getStringRecord()
{
return stringRecord;
return _stringRecord;
}
public boolean isEqual(CellValueRecordInterface i)
{
return formulaRecord.isEqual( i );
}
public boolean isAfter(CellValueRecordInterface i)
{
return formulaRecord.isAfter( i );
}
public boolean isBefore(CellValueRecordInterface i)
{
return formulaRecord.isBefore( i );
}
public short getXFIndex()
{
return formulaRecord.getXFIndex();
return _formulaRecord.getXFIndex();
}
public void setXFIndex(short xf)
{
formulaRecord.setXFIndex( xf );
_formulaRecord.setXFIndex( xf );
}
public void setColumn(short col)
{
formulaRecord.setColumn( col );
_formulaRecord.setColumn( col );
}
public void setRow(int row)
{
formulaRecord.setRow( row );
_formulaRecord.setRow( row );
}
public short getColumn()
{
return formulaRecord.getColumn();
return _formulaRecord.getColumn();
}
public int getRow()
{
return formulaRecord.getRow();
return _formulaRecord.getRow();
}
public int compareTo(Object o)
{
return formulaRecord.compareTo( o );
public String toString() {
return _formulaRecord.toString();
}
public boolean equals(Object obj)
{
return formulaRecord.equals( obj );
}
public String toString()
{
return formulaRecord.toString();
}
/**
* @see java.lang.Object#clone()
*/
public Object clone() {
StringRecord clonedString = (stringRecord == null) ? null : (StringRecord)stringRecord.clone();
return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), clonedString);
}
/*
* Setting to true so that this value does not abort the whole ValueAggregation
* (non-Javadoc)
* @see org.apache.poi.hssf.record.Record#isInValueSection()
*/
public boolean isInValueSection() {
return true;
}
public String getStringValue() {
if(stringRecord==null) return null;
return stringRecord.getString();
}
public void visitContainedRecords(RecordVisitor rv) {
rv.visitRecord(_formulaRecord);
if (_stringRecord != null) {
rv.visitRecord(_stringRecord);
}
}
public String getStringValue() {
if(_stringRecord==null) {
return null;
}
return _stringRecord.getString();
}
}

View File

@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.DBCellRecord;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.record.StringRecord;
@ -227,7 +228,7 @@ public final class ValueRecordsAggregate {
if (row > endRow)
break;
if ((row >=startRow) && (row <= endRow))
size += ((Record)cell).getRecordSize();
size += ((RecordBase)cell).getRecordSize();
}
return size;
}
@ -255,7 +256,7 @@ public final class ValueRecordsAggregate {
CellValueRecordInterface cell = (CellValueRecordInterface)itr.next();
if (cell.getRow() != row)
break;
pos += (( Record ) cell).serialize(pos, data);
pos += (( RecordBase ) cell).serialize(pos, data);
}
return pos - offset;
}
@ -313,16 +314,6 @@ public final class ValueRecordsAggregate {
{
return new MyIterator();
}
/** Performs a deep clone of the record*/
public Object clone() {
ValueRecordsAggregate rec = new ValueRecordsAggregate();
for (Iterator valIter = getIterator(); valIter.hasNext();) {
CellValueRecordInterface val = (CellValueRecordInterface)((CellValueRecordInterface)valIter.next()).clone();
rec.insertCell(val);
}
return rec;
}
private final class MyIterator implements Iterator {
short nextColumn=-1;

View File

@ -185,40 +185,25 @@ public final class HSSFCell {
/**
* used internally -- given a cell value record, figure out its type
*/
private int determineType(CellValueRecordInterface cval)
{
private static int determineType(CellValueRecordInterface cval) {
if (cval instanceof FormulaRecordAggregate) {
return HSSFCell.CELL_TYPE_FORMULA;
}
// all others are plain BIFF records
Record record = ( Record ) cval;
int sid = record.getSid();
int retval = 0;
switch (sid)
{
case NumberRecord.sid :
retval = HSSFCell.CELL_TYPE_NUMERIC;
break;
case BlankRecord.sid :
retval = HSSFCell.CELL_TYPE_BLANK;
break;
case LabelSSTRecord.sid :
retval = HSSFCell.CELL_TYPE_STRING;
break;
case FormulaRecordAggregate.sid :
retval = HSSFCell.CELL_TYPE_FORMULA;
break;
switch (record.getSid()) {
case NumberRecord.sid : return HSSFCell.CELL_TYPE_NUMERIC;
case BlankRecord.sid : return HSSFCell.CELL_TYPE_BLANK;
case LabelSSTRecord.sid : return HSSFCell.CELL_TYPE_STRING;
case BoolErrRecord.sid :
BoolErrRecord boolErrRecord = ( BoolErrRecord ) record;
retval = (boolErrRecord.isBoolean())
return boolErrRecord.isBoolean()
? HSSFCell.CELL_TYPE_BOOLEAN
: HSSFCell.CELL_TYPE_ERROR;
break;
}
return retval;
throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")");
}
/**

View File

@ -29,23 +29,13 @@ import org.apache.poi.hssf.record.StringRecord;
*
* @author avik
*/
public class TestFormulaRecordAggregate extends junit.framework.TestCase {
public final class TestFormulaRecordAggregate extends junit.framework.TestCase {
/** Creates a new instance of TestFormulaRecordAggregate */
public TestFormulaRecordAggregate(String arg) {
super(arg);
}
public void testClone() {
public void testBasic() throws Exception {
FormulaRecord f = new FormulaRecord();
StringRecord s = new StringRecord();
s.setString("abc");
FormulaRecordAggregate fagg = new FormulaRecordAggregate(f,s);
FormulaRecordAggregate newFagg = (FormulaRecordAggregate) fagg.clone();
assertTrue("objects are different", fagg!=newFagg);
assertTrue("deep clone", fagg.getFormulaRecord() != newFagg.getFormulaRecord());
assertTrue("deep clone", fagg.getStringRecord() != newFagg.getStringRecord());
assertEquals("abc", fagg.getStringValue());
}
}

View File

@ -30,7 +30,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -50,7 +50,7 @@ public final class TestValueRecordsAggregate extends TestCase {
constructValueRecord(records);
Iterator iterator = valueRecord.getIterator();
Record record = (Record) iterator.next();
RecordBase record = (RecordBase) iterator.next();
assertNotNull( "Row contains a value", record );
assertTrue( "First record is a FormulaRecordsAggregate", ( record instanceof FormulaRecordAggregate ) );
//Ensure that the SharedFormulaRecord has been converted