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) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class BlankRecord extends Record implements CellValueRecordInterface {
public class BlankRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0x201; public final static short sid = 0x201;
//private short field_1_row;
private int field_1_row; private int field_1_row;
private short field_2_col; private short field_2_col;
private short field_3_xf; private short field_3_xf;
@ -152,50 +147,6 @@ public class BlankRecord
field_2_col = col; 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() public boolean isInValueSection()
{ {
return true; return true;
@ -254,50 +205,6 @@ public class BlankRecord
return 10; 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() { public Object clone() {
BlankRecord rec = new BlankRecord(); BlankRecord rec = new BlankRecord();
rec.field_1_row = field_1_row; 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) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class BoolErrRecord extends Record implements CellValueRecordInterface {
public class BoolErrRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0x205; 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_2_column;
private short field_3_xf_index; private short field_3_xf_index;
private byte field_4_bBoolErr; private byte field_4_bBoolErr;
@ -274,50 +269,6 @@ public class BoolErrRecord
return sid; 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() public boolean isInValueSection()
{ {
return true; return true;
@ -328,50 +279,6 @@ public class BoolErrRecord
return true; 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() { public Object clone() {
BoolErrRecord rec = new BoolErrRecord(); BoolErrRecord rec = new BoolErrRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,12 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* CellValueRecordInterface.java
*
* Created on October 2, 2001, 8:27 PM
*/
package org.apache.poi.hssf.record; 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.Record
* @see org.apache.poi.hssf.record.RecordFactory * @see org.apache.poi.hssf.record.RecordFactory
*/ */
public interface CellValueRecordInterface {
public interface CellValueRecordInterface
{
/** /**
* get the row this cell occurs on * @return the row this cell occurs on
*
* @return the row
*/ */
int getRow();
//public short getRow();
public int getRow();
/** /**
* get the column this cell defines within the row * @return the column this cell defines within the row
*
* @return the column
*/ */
short getColumn();
public short getColumn();
/** /**
* set the row this cell occurs on
* @param row the row this cell occurs within * @param row the row this cell occurs within
*/ */
void setRow(int row);
//public void setRow(short row);
public void setRow(int row);
/** /**
* set the column this cell defines within the row
*
* @param col the column this cell defines * @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); short getXFIndex();
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();
} }

View File

@ -32,10 +32,7 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class FormulaRecord public final class FormulaRecord extends Record implements CellValueRecordInterface {
extends Record
implements CellValueRecordInterface, Comparable
{
public static final short sid = 0x0006; // docs say 406...because of a bug Microsoft support site article #Q184647) 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; 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() public boolean isInValueSection()
{ {
return true; return true;
@ -434,51 +387,6 @@ public final class FormulaRecord
return true; 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() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View File

@ -180,51 +180,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
return buffer.toString(); 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() public boolean isInValueSection()
{ {
return true; return true;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,7 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -30,13 +28,8 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class LabelSSTRecord extends Record implements CellValueRecordInterface {
public class LabelSSTRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0xfd; public final static short sid = 0xfd;
//private short field_1_row;
private int field_1_row; private int field_1_row;
private short field_2_column; private short field_2_column;
private short field_3_xf_index; private short field_3_xf_index;
@ -183,50 +176,6 @@ public class LabelSSTRecord
return sid; 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() public boolean isInValueSection()
{ {
return true; return true;
@ -237,50 +186,6 @@ public class LabelSSTRecord
return true; 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() { public Object clone() {
LabelSSTRecord rec = new LabelSSTRecord(); LabelSSTRecord rec = new LabelSSTRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,12 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* NumberRecord.java
*
* Created on October 1, 2001, 8:01 PM
*/
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian; 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) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class NumberRecord extends Record implements CellValueRecordInterface {
public class NumberRecord
extends Record
implements CellValueRecordInterface, Comparable
{
public static final short sid = 0x203; public static final short sid = 0x203;
//private short field_1_row;
private int field_1_row; private int field_1_row;
private short field_2_col; private short field_2_col;
private short field_3_xf; private short field_3_xf;
@ -203,50 +191,6 @@ public class NumberRecord
return sid; 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() public boolean isInValueSection()
{ {
return true; return true;
@ -257,50 +201,6 @@ public class NumberRecord
return true; 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() { public Object clone() {
NumberRecord rec = new NumberRecord(); NumberRecord rec = new NumberRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,7 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.hssf.util.RKUtil; import org.apache.poi.hssf.util.RKUtil;
@ -38,17 +36,12 @@ import org.apache.poi.hssf.util.RKUtil;
* @version 2.0-pre * @version 2.0-pre
* @see org.apache.poi.hssf.record.NumberRecord * @see org.apache.poi.hssf.record.NumberRecord
*/ */
public final class RKRecord extends Record implements CellValueRecordInterface {
public class RKRecord
extends Record
implements CellValueRecordInterface
{
public final static short sid = 0x27e; public final static short sid = 0x27e;
public final static short RK_IEEE_NUMBER = 0; public final static short RK_IEEE_NUMBER = 0;
public final static short RK_IEEE_NUMBER_TIMES_100 = 1; public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
public final static short RK_INTEGER = 2; public final static short RK_INTEGER = 2;
public final static short RK_INTEGER_TIMES_100 = 3; public final static short RK_INTEGER_TIMES_100 = 3;
//private short field_1_row;
private int field_1_row; private int field_1_row;
private short field_2_col; private short field_2_col;
private short field_3_xf_index; private short field_3_xf_index;
@ -216,50 +209,6 @@ public class RKRecord
return sid; 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() public boolean isInValueSection()
{ {
return true; return true;

View File

@ -15,10 +15,11 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record.aggregates; 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 * 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) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class FormulaRecordAggregate public final class FormulaRecordAggregate extends RecordAggregate implements CellValueRecordInterface {
extends Record
implements CellValueRecordInterface, Comparable
{
public final static short sid = -2000;
private FormulaRecord formulaRecord; private FormulaRecord _formulaRecord;
private StringRecord stringRecord; private StringRecord _stringRecord;
public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord ) public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord )
{ {
this.formulaRecord = formulaRecord; _formulaRecord = formulaRecord;
this.stringRecord = stringRecord; _stringRecord = stringRecord;
} }
protected void validateSid( short id ) public void setStringRecord( StringRecord stringRecord ) {
{ _stringRecord = stringRecord;
}
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 setFormulaRecord( FormulaRecord formulaRecord ) public void setFormulaRecord( FormulaRecord formulaRecord )
{ {
this.formulaRecord = formulaRecord; _formulaRecord = formulaRecord;
} }
public FormulaRecord getFormulaRecord() public FormulaRecord getFormulaRecord()
{ {
return formulaRecord; return _formulaRecord;
} }
public StringRecord getStringRecord() 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() public short getXFIndex()
{ {
return formulaRecord.getXFIndex(); return _formulaRecord.getXFIndex();
} }
public void setXFIndex(short xf) public void setXFIndex(short xf)
{ {
formulaRecord.setXFIndex( xf ); _formulaRecord.setXFIndex( xf );
} }
public void setColumn(short col) public void setColumn(short col)
{ {
formulaRecord.setColumn( col ); _formulaRecord.setColumn( col );
} }
public void setRow(int row) public void setRow(int row)
{ {
formulaRecord.setRow( row ); _formulaRecord.setRow( row );
} }
public short getColumn() public short getColumn()
{ {
return formulaRecord.getColumn(); return _formulaRecord.getColumn();
} }
public int getRow() public int getRow()
{ {
return formulaRecord.getRow(); return _formulaRecord.getRow();
} }
public int compareTo(Object o) public String toString() {
{ return _formulaRecord.toString();
return formulaRecord.compareTo( o );
} }
public boolean equals(Object obj) public void visitContainedRecords(RecordVisitor rv) {
{ rv.visitRecord(_formulaRecord);
return formulaRecord.equals( obj ); if (_stringRecord != null) {
rv.visitRecord(_stringRecord);
}
} }
public String toString() public String getStringValue() {
{ if(_stringRecord==null) {
return formulaRecord.toString(); return null;
}
return _stringRecord.getString();
} }
/**
* @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();
}
} }

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.FormulaRecord;
import org.apache.poi.hssf.record.MergeCellsRecord; import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.Record; 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.RowRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord; import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.StringRecord;
@ -227,7 +228,7 @@ public final class ValueRecordsAggregate {
if (row > endRow) if (row > endRow)
break; break;
if ((row >=startRow) && (row <= endRow)) if ((row >=startRow) && (row <= endRow))
size += ((Record)cell).getRecordSize(); size += ((RecordBase)cell).getRecordSize();
} }
return size; return size;
} }
@ -255,7 +256,7 @@ public final class ValueRecordsAggregate {
CellValueRecordInterface cell = (CellValueRecordInterface)itr.next(); CellValueRecordInterface cell = (CellValueRecordInterface)itr.next();
if (cell.getRow() != row) if (cell.getRow() != row)
break; break;
pos += (( Record ) cell).serialize(pos, data); pos += (( RecordBase ) cell).serialize(pos, data);
} }
return pos - offset; return pos - offset;
} }
@ -314,16 +315,6 @@ public final class ValueRecordsAggregate {
return new MyIterator(); 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 { private final class MyIterator implements Iterator {
short nextColumn=-1; short nextColumn=-1;
int nextRow,lastRow; int nextRow,lastRow;

View File

@ -185,40 +185,25 @@ public final class HSSFCell {
/** /**
* used internally -- given a cell value record, figure out its type * 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; Record record = ( Record ) cval;
int sid = record.getSid(); switch (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;
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 : case BoolErrRecord.sid :
BoolErrRecord boolErrRecord = ( BoolErrRecord ) record; BoolErrRecord boolErrRecord = ( BoolErrRecord ) record;
retval = (boolErrRecord.isBoolean()) return boolErrRecord.isBoolean()
? HSSFCell.CELL_TYPE_BOOLEAN ? HSSFCell.CELL_TYPE_BOOLEAN
: HSSFCell.CELL_TYPE_ERROR; : 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 * @author avik
*/ */
public class TestFormulaRecordAggregate extends junit.framework.TestCase { public final class TestFormulaRecordAggregate extends junit.framework.TestCase {
/** Creates a new instance of TestFormulaRecordAggregate */ public void testBasic() throws Exception {
public TestFormulaRecordAggregate(String arg) {
super(arg);
}
public void testClone() {
FormulaRecord f = new FormulaRecord(); FormulaRecord f = new FormulaRecord();
StringRecord s = new StringRecord(); StringRecord s = new StringRecord();
s.setString("abc");
FormulaRecordAggregate fagg = new FormulaRecordAggregate(f,s); FormulaRecordAggregate fagg = new FormulaRecordAggregate(f,s);
FormulaRecordAggregate newFagg = (FormulaRecordAggregate) fagg.clone(); assertEquals("abc", fagg.getStringValue());
assertTrue("objects are different", fagg!=newFagg);
assertTrue("deep clone", fagg.getFormulaRecord() != newFagg.getFormulaRecord());
assertTrue("deep clone", fagg.getStringRecord() != newFagg.getStringRecord());
} }
} }

View File

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