poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r742785 - in /poi/trunk/src/java/org/apache/poi/hssf/record: BoolErrRecord.java CellRecord.java FormulaRecord.java LabelSSTRecord.java NumberRecord.java RKRecord.java
Date Mon, 09 Feb 2009 23:16:53 GMT
Author: josh
Date: Mon Feb  9 23:16:49 2009
New Revision: 742785

URL: http://svn.apache.org/viewvc?rev=742785&view=rev
Log:
Refactored common CellValueRecordInterface code into a new superclass CellRecord

Added:
    poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/BoolErrRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/NumberRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/BoolErrRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/BoolErrRecord.java?rev=742785&r1=742784&r2=742785&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/BoolErrRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/BoolErrRecord.java Mon Feb  9 23:16:49 2009
@@ -27,47 +27,25 @@
  * @author Michael P. Harhen
  * @author Jason Height (jheight at chariot dot net dot au)
  */
-public final class BoolErrRecord extends StandardRecord implements CellValueRecordInterface
{
+public final class BoolErrRecord extends CellRecord {
 	public final static short sid = 0x0205;
-	private int field_1_row;
-	private short field_2_column;
-	private short field_3_xf_index;
 	private byte field_4_bBoolErr;
 	private byte field_5_fError;
 
 	/** Creates new BoolErrRecord */
 	public BoolErrRecord() {
- 
+		// fields uninitialised 
 	}
 
 	/**
 	 * @param in the RecordInputstream to read the record from
 	 */
 	public BoolErrRecord(RecordInputStream in) {
-		field_1_row      = in.readUShort();
-		field_2_column   = in.readShort();
-		field_3_xf_index = in.readShort();
+		super(in);
 		field_4_bBoolErr = in.readByte();
 		field_5_fError   = in.readByte();
 	}
 
-	public void setRow(int row) {
-		field_1_row = row;
-	}
-
-	public void setColumn(short col) {
-		field_2_column = col;
-	}
-
-	/**
-	 * set the index to the ExtendedFormat
-	 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-	 * @param xf    index to the XF record
-	 */
-	public void setXFIndex(short xf) {
-		field_3_xf_index = xf;
-	}
-
 	/**
 	 * set the boolean value for the cell
 	 *
@@ -101,23 +79,6 @@
 		throw new IllegalArgumentException("Error Value can only be 0,7,15,23,29,36 or 42. It cannot
be "+value);
 	}
 
-	public int getRow() {
-		return field_1_row;
-	}
-
-	public short getColumn() {
-		return field_2_column;
-	}
-
-	/**
-	 * get the index to the ExtendedFormat
-	 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-	 * @return index to the XF record
-	 */
-	public short getXFIndex() {
-		return field_3_xf_index;
-	}
-
 	/**
 	 * get the value for the cell
 	 *
@@ -162,44 +123,39 @@
 		return field_5_fError != 0;
 	}
 
-	public String toString() {
-		StringBuffer sb = new StringBuffer();
-
-		sb.append("[BOOLERR]\n");
-		sb.append("    .row    = ").append(HexDump.shortToHex(getRow())).append("\n");
-		sb.append("    .col    = ").append(HexDump.shortToHex(getColumn())).append("\n");
-		sb.append("    .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
+	@Override
+	protected String getRecordName() {
+		return "BOOLERR";
+	}
+	@Override
+	protected void appendValueText(StringBuilder sb) {
 		if (isBoolean()) {
-			sb.append("    .booleanValue   = ").append(getBooleanValue()).append("\n");
+			sb.append("  .boolVal = ");
+			sb.append(getBooleanValue());
 		} else {
-			sb.append("    .errorValue     = ").append(getErrorValue()).append("\n");
+			sb.append("  .errCode = ");
+			sb.append(ErrorConstants.getText(getErrorValue()));
+			sb.append(" (").append(HexDump.byteToHex(getErrorValue())).append(")");
 		}
-		sb.append("[/BOOLERR]\n");
-		return sb.toString();
 	}
-
-	public void serialize(LittleEndianOutput out) {
-		out.writeShort(getRow());
-		out.writeShort(getColumn());
-		out.writeShort(getXFIndex());
+	@Override
+	protected void serializeValue(LittleEndianOutput out) {
 		out.writeByte(field_4_bBoolErr);
 		out.writeByte(field_5_fError);
 	}
 
-	protected int getDataSize() {
-		return 8;
+	@Override
+	protected int getValueDataSize() {
+		return 2;
 	}
 
-	public short getSid()
-	{
+	public short getSid() {
 		return sid;
 	}
 
 	public Object clone() {
 	  BoolErrRecord rec = new BoolErrRecord();
-	  rec.field_1_row = field_1_row;
-	  rec.field_2_column = field_2_column;
-	  rec.field_3_xf_index = field_3_xf_index;
+	  copyBaseFields(rec);
 	  rec.field_4_bBoolErr = field_4_bBoolErr;
 	  rec.field_5_fError = field_5_fError;
 	  return rec;

Added: poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java?rev=742785&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java Mon Feb  9 23:16:49 2009
@@ -0,0 +1,132 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record;
+
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianOutput;
+
+/**
+ * Base class for all cell value records (implementors of {@link CellValueRecordInterface}).
+ * Subclasses are expected to manage the cell data values (of various types). 
+ * 
+ * @author Josh Micich
+ */
+public abstract class CellRecord extends StandardRecord implements CellValueRecordInterface
{
+	private int _rowIndex;
+	private int _columnIndex;
+	private int _formatIndex;
+
+	protected CellRecord() {
+		// fields uninitialised
+	}
+
+	protected CellRecord(RecordInputStream in) {
+		_rowIndex = in.readUShort();
+		_columnIndex = in.readUShort();
+		_formatIndex = in.readUShort();
+	}
+
+	public final void setRow(int row) {
+		_rowIndex = row;
+	}
+
+	public final void setColumn(short col) {
+		_columnIndex = col;
+	}
+
+	/**
+	 * set the index to the ExtendedFormat
+	 * 
+	 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
+	 * @param xf index to the XF record
+	 */
+	public final void setXFIndex(short xf) {
+		_formatIndex = xf;
+	}
+
+	public final int getRow() {
+		return _rowIndex;
+	}
+
+	public final short getColumn() {
+		return (short) _columnIndex;
+	}
+
+	/**
+	 * get the index to the ExtendedFormat
+	 * 
+	 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
+	 * @return index to the XF record
+	 */
+	public final short getXFIndex() {
+		return (short) _formatIndex;
+	}
+
+	public final String toString() {
+		StringBuilder sb = new StringBuilder();
+		String recordName = getRecordName();
+
+		sb.append("[").append(recordName).append("]\n");
+		sb.append("    .row    = ").append(HexDump.shortToHex(getRow())).append("\n");
+		sb.append("    .col    = ").append(HexDump.shortToHex(getColumn())).append("\n");
+		sb.append("    .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
+		appendValueText(sb);
+		sb.append("\n");
+		sb.append("[/NUMBER]\n");
+		return sb.toString();
+	}
+
+	/**
+	 * Append specific debug info (used by {@link #toString()} for the value
+	 * contained in this record. Trailing new-line should not be appended
+	 * (superclass does that).
+	 */
+	protected abstract void appendValueText(StringBuilder sb);
+
+	/**
+	 * Gets the debug info BIFF record type name (used by {@link #toString()}.
+	 */
+	protected abstract String getRecordName();
+
+	/**
+	 * writes out the value data for this cell record
+	 */
+	protected abstract void serializeValue(LittleEndianOutput out);
+
+	/**
+	 * @return the size (in bytes) of the value data for this cell record
+	 */
+	protected abstract int getValueDataSize();
+
+	public final void serialize(LittleEndianOutput out) {
+		out.writeShort(getRow());
+		out.writeShort(getColumn());
+		out.writeShort(getXFIndex());
+		serializeValue(out);
+	}
+
+	protected final int getDataSize() {
+		return 6 + getValueDataSize();
+	}
+
+	protected final void copyBaseFields(CellRecord rec) {
+		rec._rowIndex = _rowIndex;
+		rec._columnIndex = _columnIndex;
+		rec._formatIndex = _formatIndex;
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=742785&r1=742784&r2=742785&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Mon Feb  9 23:16:49 2009
@@ -24,7 +24,6 @@
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndianByteArrayOutputStream;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
 
@@ -33,12 +32,11 @@
  * REFERENCE:  PG 317/444 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
- * @version 2.0-pre
  */
-public final class FormulaRecord extends StandardRecord implements CellValueRecordInterface
{
+public final class FormulaRecord extends CellRecord {
 
 	public static final short sid = 0x0006;   // docs say 406...because of a bug Microsoft support
site article #Q184647)
-	private static int FIXED_SIZE = 20;
+	private static int FIXED_SIZE = 14; // double + short + int
 
 	private static final BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
 	private static final BitField calcOnLoad = BitFieldFactory.getInstance(0x0002);
@@ -168,11 +166,6 @@
 		}
 	}
 
-
-
-	private int    field_1_row;
-	private short  field_2_column;
-	private short  field_3_xf;
 	private double field_4_value;
 	private short  field_5_options;
 	/**
@@ -195,10 +188,8 @@
 	}
 
 	public FormulaRecord(RecordInputStream ris) {
+		super(ris);
 		LittleEndianInput in = ris;
-		field_1_row = in.readUShort();
-		field_2_column = in.readShort();
-		field_3_xf = in.readShort();
 		long valueLongBits  = in.readLong();
 		field_5_options = in.readShort();
 		specialCachedValue = SpecialCachedValue.create(valueLongBits);
@@ -213,19 +204,6 @@
 		field_8_parsed_expr = Formula.read(field_7_expression_len, in, nBytesAvailable);
 	}
 
-
-	public void setRow(int row) {
-		field_1_row = row;
-	}
-
-	public void setColumn(short column) {
-		field_2_column = column;
-	}
-
-	public void setXFIndex(short xf) {
-		field_3_xf = xf;
-	}
-
 	/**
 	 * set the calculated value of the formula
 	 *
@@ -284,18 +262,6 @@
 		field_5_options = options;
 	}
 
-	public int getRow() {
-		return field_1_row;
-	}
-
-	public short getColumn() {
-		return field_2_column;
-	}
-
-	public short getXFIndex() {
-		return field_3_xf;
-	}
-
 	/**
 	 * get the calculated value of the formula
 	 *
@@ -357,14 +323,12 @@
 		return sid;
 	}
 
-	protected int getDataSize() {
+	@Override
+	protected int getValueDataSize() {
 		return FIXED_SIZE + field_8_parsed_expr.getEncodedSize();
 	}
-	public void serialize(LittleEndianOutput out) {
-
-		out.writeShort(getRow());
-		out.writeShort(getColumn());
-		out.writeShort(getXFIndex());
+	@Override
+	protected void serializeValue(LittleEndianOutput out) {
 
 		if (specialCachedValue == null) {
 			out.writeDouble(field_4_value);
@@ -377,14 +341,14 @@
 		out.writeInt(field_6_zero); // may as well write original data back so as to minimise differences
from original
 		field_8_parsed_expr.serialize(out);
 	}
-
-	public String toString() {
-
-		StringBuffer sb = new StringBuffer();
-		sb.append("[FORMULA]\n");
-		sb.append("  .row	   = ").append(HexDump.shortToHex(getRow())).append("\n");
-		sb.append("  .column	= ").append(HexDump.shortToHex(getColumn())).append("\n");
-		sb.append("  .xf		= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
+	
+	@Override
+	protected String getRecordName() {
+		return "FORMULA";
+	}
+	
+	@Override
+	protected void appendValueText(StringBuilder sb) {
 		sb.append("  .value	 = ");
 		if (specialCachedValue == null) {
 			sb.append(field_4_value).append("\n");
@@ -395,23 +359,22 @@
 		sb.append("    .alwaysCalc= ").append(isAlwaysCalc()).append("\n");
 		sb.append("    .calcOnLoad= ").append(isCalcOnLoad()).append("\n");
 		sb.append("    .shared    = ").append(isSharedFormula()).append("\n");
-		sb.append("  .zero      = ").append(HexDump.intToHex(field_6_zero)).append("\n");
+		sb.append("  .zero      = ").append(HexDump.intToHex(field_6_zero));
 
 		Ptg[] ptgs = field_8_parsed_expr.getTokens();
 		for (int k = 0; k < ptgs.length; k++ ) {
+			if (k>0) {
+				sb.append("\n");
+			}
 			sb.append("    Ptg[").append(k).append("]=");
 			Ptg ptg = ptgs[k];
-			sb.append(ptg.toString()).append(ptg.getRVAType()).append("\n");
+			sb.append(ptg.toString()).append(ptg.getRVAType());
 		}
-		sb.append("[/FORMULA]\n");
-		return sb.toString();
 	}
 
 	public Object clone() {
 		FormulaRecord rec = new FormulaRecord();
-		rec.field_1_row = field_1_row;
-		rec.field_2_column = field_2_column;
-		rec.field_3_xf = field_3_xf;
+		copyBaseFields(rec);
 		rec.field_4_value = field_4_value;
 		rec.field_5_options = field_5_options;
 		rec.field_6_zero = field_6_zero;

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java?rev=742785&r1=742784&r2=742785&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java Mon Feb  9 23:16:49
2009
@@ -27,82 +27,30 @@
  * REFERENCE:  PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
- * @version 2.0-pre
  */
-public final class LabelSSTRecord extends StandardRecord implements CellValueRecordInterface
{
+public final class LabelSSTRecord extends CellRecord {
     public final static short sid = 0xfd;
-    private int field_1_row;
-    private int field_2_column;
-    private int field_3_xf_index;
     private int field_4_sst_index;
 
-    public LabelSSTRecord()
-    {
+    public LabelSSTRecord() {
+    	// fields uninitialised
     }
 
-    public LabelSSTRecord(RecordInputStream in)
-    {
-        field_1_row       = in.readUShort();
-        field_2_column    = in.readUShort();
-        field_3_xf_index  = in.readUShort();
+    public LabelSSTRecord(RecordInputStream in) {
+        super(in);
         field_4_sst_index = in.readInt();
     }
 
-    public void setRow(int row)
-    {
-        field_1_row = row;
-    }
-
-    public void setColumn(short col)
-    {
-        field_2_column = col;
-    }
-
-    /**
-     * set the index to the extended format record
-     *
-     * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-     * @param index - the index to the XF record
-     */
-
-    public void setXFIndex(short index)
-    {
-        field_3_xf_index = index;
-    }
-
     /**
      * set the index to the string in the SSTRecord
      *
      * @param index - of string in the SST Table
      * @see org.apache.poi.hssf.record.SSTRecord
      */
-
-    public void setSSTIndex(int index)
-    {
+    public void setSSTIndex(int index) {
         field_4_sst_index = index;
     }
 
-    public int getRow()
-    {
-        return field_1_row;
-    }
-
-    public short getColumn()
-    {
-        return (short)field_2_column;
-    }
-
-    /**
-     * get the index to the extended format record
-     *
-     * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-     * @return the index to the XF record
-     */
-
-    public short getXFIndex()
-    {
-        return (short)field_3_xf_index;
-    }
 
     /**
      * get the index to the string in the SSTRecord
@@ -110,46 +58,37 @@
      * @return index of string in the SST Table
      * @see org.apache.poi.hssf.record.SSTRecord
      */
-
-    public int getSSTIndex()
-    {
+    public int getSSTIndex() {
         return field_4_sst_index;
     }
+    
+    @Override
+    protected String getRecordName() {
+    	return "LABELSST";
+    }
 
-    public String toString()
-    {
-        StringBuffer sb = new StringBuffer();
-
-        sb.append("[LABELSST]\n");
-        sb.append("    .row     = ").append(HexDump.shortToHex(getRow())).append("\n");
-        sb.append("    .column  = ").append(HexDump.shortToHex(getColumn())).append("\n");
-        sb.append("    .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
-        sb.append("    .sstindex= ").append(HexDump.intToHex(getSSTIndex())).append("\n");
-        sb.append("[/LABELSST]\n");
-        return sb.toString();
-    }
-
-    public void serialize(LittleEndianOutput out) {
-        out.writeShort(getRow());
-        out.writeShort(getColumn());
-        out.writeShort(getXFIndex());
+    @Override
+    protected void appendValueText(StringBuilder sb) {
+		sb.append("  .sstIndex = ");
+    	sb.append(HexDump.shortToHex(getXFIndex()));
+    }
+    @Override
+    protected void serializeValue(LittleEndianOutput out) {
         out.writeInt(getSSTIndex());
     }
 
-    protected int getDataSize() {
-        return 10;
+    @Override
+    protected int getValueDataSize() {
+        return 4;
     }
 
-    public short getSid()
-    {
+    public short getSid() {
         return sid;
     }
 
     public Object clone() {
       LabelSSTRecord rec = new LabelSSTRecord();
-      rec.field_1_row = field_1_row;
-      rec.field_2_column = field_2_column;
-      rec.field_3_xf_index = field_3_xf_index;
+      copyBaseFields(rec);
       rec.field_4_sst_index = field_4_sst_index;
       return rec;
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NumberRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NumberRecord.java?rev=742785&r1=742784&r2=742785&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/NumberRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/NumberRecord.java Mon Feb  9 23:16:49 2009
@@ -17,134 +17,77 @@
 
 package org.apache.poi.hssf.record;
 
-import org.apache.poi.util.HexDump;
+import org.apache.poi.ss.util.NumberToTextConverter;
 import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.hssf.record.Record;
 
 /**
  * NUMBER (0x0203) Contains a numeric cell value. <P>
  * REFERENCE:  PG 334 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
- * @version 2.0-pre
  */
-public final class NumberRecord extends StandardRecord implements CellValueRecordInterface
{
+public final class NumberRecord extends CellRecord {
     public static final short sid = 0x0203;
-    private int field_1_row;
-    private int field_2_col;
-    private int field_3_xf;
     private double field_4_value;
 
     /** Creates new NumberRecord */
-    public NumberRecord()
-    {
+    public NumberRecord() {
+    	// fields uninitialised
     }
 
     /**
      * @param in the RecordInputstream to read the record from
      */
-    public NumberRecord(RecordInputStream in)
-    {
-        field_1_row   = in.readUShort();
-        field_2_col   = in.readUShort();
-        field_3_xf    = in.readUShort();
+    public NumberRecord(RecordInputStream in) {
+        super(in);
         field_4_value = in.readDouble();
     }
 
-    public void setRow(int row)
-    {
-        field_1_row = row;
-    }
-
-    public void setColumn(short col)
-    {
-        field_2_col = col;
-    }
-
-    /**
-     * set the index to the ExtendedFormat
-     * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-     * @param xf  index to the XF record
-     */
-    public void setXFIndex(short xf)
-    {
-        field_3_xf = xf;
-    }
-
     /**
      * set the value for the cell
      *
      * @param value  double representing the value
      */
-    public void setValue(double value)
-    {
+    public void setValue(double value){
         field_4_value = value;
     }
 
-    public int getRow()
-    {
-        return field_1_row;
-    }
-
-    public short getColumn()
-    {
-        return (short)field_2_col;
-    }
-
-    /**
-     * get the index to the ExtendedFormat
-     * @see org.apache.poi.hssf.record.ExtendedFormatRecord
-     * @return index to the XF record
-     */
-    public short getXFIndex()
-    {
-        return (short)field_3_xf;
-    }
-
     /**
      * get the value for the cell
      *
      * @return double representing the value
      */
-    public double getValue()
-    {
+    public double getValue(){
         return field_4_value;
     }
 
-    public String toString()
-    {
-        StringBuffer sb = new StringBuffer();
-
-        sb.append("[NUMBER]\n");
-        sb.append("    .row    = ").append(HexDump.shortToHex(getRow())).append("\n");
-        sb.append("    .col    = ").append(HexDump.shortToHex(getColumn())).append("\n");
-        sb.append("    .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
-        sb.append("    .value  = ").append(getValue()).append("\n");
-        sb.append("[/NUMBER]\n");
-        return sb.toString();
-    }
-
-    public void serialize(LittleEndianOutput out) {
-        out.writeShort(getRow());
-        out.writeShort(getColumn());
-        out.writeShort(getXFIndex());
+    @Override
+    protected String getRecordName() {
+    	return "NUMBER";
+    }
+
+    @Override
+    protected void appendValueText(StringBuilder sb) {
+    	sb.append("  .value= ").append(NumberToTextConverter.toText(field_4_value));
+    }
+
+    @Override
+    protected void serializeValue(LittleEndianOutput out) {
         out.writeDouble(getValue());
     }
 
-    protected int getDataSize() {
-        return 14;
+    @Override
+    protected int getValueDataSize() {
+    	return 8;
     }
 
-    public short getSid()
-    {
+    public short getSid() {
         return sid;
     }
 
     public Object clone() {
       NumberRecord rec = new NumberRecord();
-      rec.field_1_row = field_1_row;
-      rec.field_2_col = field_2_col;
-      rec.field_3_xf = field_3_xf;
+      copyBaseFields(rec);
       rec.field_4_value = field_4_value;
       return rec;
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java?rev=742785&r1=742784&r2=742785&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RKRecord.java Mon Feb  9 23:16:49 2009
@@ -18,7 +18,6 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.hssf.util.RKUtil;
-import org.apache.poi.util.HexDump;
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
@@ -37,65 +36,23 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  * @see org.apache.poi.hssf.record.NumberRecord
  */
-public final class RKRecord extends StandardRecord implements CellValueRecordInterface {
+public final class RKRecord extends CellRecord {
     public final static short sid                      = 0x027E;
     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 int field_1_row;
-    private int field_2_col;
-    private int field_3_xf_index;
     private int field_4_rk_number;
 
-    private RKRecord()
-    {
+    private RKRecord() {
+    	// fields uninitialised
     }
 
-    public RKRecord(RecordInputStream in)
-    {
-        field_1_row       = in.readUShort();
-        field_2_col       = in.readUShort();
-        field_3_xf_index  = in.readUShort();
+    public RKRecord(RecordInputStream in) {
+        super(in);
         field_4_rk_number = in.readInt();
     }
 
-    public int getRow()
-    {
-        return field_1_row;
-    }
-
-    public short getColumn()
-    {
-        return (short) field_2_col;
-    }
-
-    public short getXFIndex()
-    {
-        return (short) field_3_xf_index;
-    }
-
-    public int getRKField()
-    {
-        return field_4_rk_number;
-    }
-
-    /**
-     * Get the type of the number
-     *
-     * @return one of these values:
-     *         <OL START="0">
-     *             <LI>RK_IEEE_NUMBER</LI>
-     *             <LI>RK_IEEE_NUMBER_TIMES_100</LI>
-     *             <LI>RK_INTEGER</LI>
-     *             <LI>RK_INTEGER_TIMES_100</LI>
-     *         </OL>
-     */
-    public short getRKType()
-    {
-        return ( short ) (field_4_rk_number & 3);
-    }
-
     /**
      * Extract the value of the number
      * <P>
@@ -113,60 +70,37 @@
      * @return the value as a proper double (hey, it <B>could</B>
      *         happen)
      */
-    public double getRKNumber()
-    {
+    public double getRKNumber() {
         return RKUtil.decodeNumber(field_4_rk_number);
     }
 
-
-    public String toString()
-    {
-        StringBuffer sb = new StringBuffer();
-
-        sb.append("[RK]\n");
-        sb.append("    .row       = ").append(HexDump.shortToHex(getRow())).append("\n");
-        sb.append("    .col       = ").append(HexDump.shortToHex(getColumn())).append("\n");
-        sb.append("    .xfindex   = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
-        sb.append("    .rknumber  = ").append(HexDump.intToHex(getRKField())).append("\n");
-        sb.append("      .rktype  = ").append(HexDump.byteToHex(getRKType())).append("\n");
-        sb.append("      .rknumber= ").append(getRKNumber()).append("\n");
-        sb.append("[/RK]\n");
-        return sb.toString();
-    }
-
-	public void serialize(LittleEndianOutput out) {
-		throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
-	}
-	protected int getDataSize() {
-		throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
-	}
-
-    public short getSid()
-    {
-        return sid;
+    @Override
+    protected String getRecordName() {
+    	return "RK";
     }
 
-    public void setColumn(short col)
-    {
+    @Override
+    protected void appendValueText(StringBuilder sb) {
+    	sb.append("  .value= ").append(getRKNumber());
     }
 
-    public void setRow(int row)
-    {
+    @Override
+    protected void serializeValue(LittleEndianOutput out) {
+    	out.writeInt(field_4_rk_number);
     }
 
-    /**
-     * NO OP!
-     */
+    @Override
+    protected int getValueDataSize() {
+    	return 4;
+    }
 
-    public void setXFIndex(short xf)
-    {
+    public short getSid() {
+        return sid;
     }
 
     public Object clone() {
       RKRecord rec = new RKRecord();
-      rec.field_1_row = field_1_row;
-      rec.field_2_col = field_2_col;
-      rec.field_3_xf_index = field_3_xf_index;
+      copyBaseFields(rec);
       rec.field_4_rk_number = field_4_rk_number;
       return rec;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message