]> source.dussan.org Git - poi.git/commitdiff
Refactored common CellValueRecordInterface code into a new superclass CellRecord
authorJosh Micich <josh@apache.org>
Mon, 9 Feb 2009 23:16:49 +0000 (23:16 +0000)
committerJosh Micich <josh@apache.org>
Mon, 9 Feb 2009 23:16:49 +0000 (23:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@742785 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/BoolErrRecord.java
src/java/org/apache/poi/hssf/record/CellRecord.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/FormulaRecord.java
src/java/org/apache/poi/hssf/record/LabelSSTRecord.java
src/java/org/apache/poi/hssf/record/NumberRecord.java
src/java/org/apache/poi/hssf/record/RKRecord.java

index 5b8f9186d787468d64c5a9e82a222a8681b3c1b1..9aa862f7d277ee8e956c825f41a56859181c4a52 100644 (file)
@@ -27,47 +27,25 @@ import org.apache.poi.util.LittleEndianOutput;
  * @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 @@ public final class BoolErrRecord extends StandardRecord implements CellValueReco
                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 @@ public final class BoolErrRecord extends StandardRecord implements CellValueReco
                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;
diff --git a/src/java/org/apache/poi/hssf/record/CellRecord.java b/src/java/org/apache/poi/hssf/record/CellRecord.java
new file mode 100644 (file)
index 0000000..99ba1dd
--- /dev/null
@@ -0,0 +1,132 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hssf.record;\r
+\r
+import org.apache.poi.util.HexDump;\r
+import org.apache.poi.util.LittleEndianOutput;\r
+\r
+/**\r
+ * Base class for all cell value records (implementors of {@link CellValueRecordInterface}).\r
+ * Subclasses are expected to manage the cell data values (of various types). \r
+ * \r
+ * @author Josh Micich\r
+ */\r
+public abstract class CellRecord extends StandardRecord implements CellValueRecordInterface {\r
+       private int _rowIndex;\r
+       private int _columnIndex;\r
+       private int _formatIndex;\r
+\r
+       protected CellRecord() {\r
+               // fields uninitialised\r
+       }\r
+\r
+       protected CellRecord(RecordInputStream in) {\r
+               _rowIndex = in.readUShort();\r
+               _columnIndex = in.readUShort();\r
+               _formatIndex = in.readUShort();\r
+       }\r
+\r
+       public final void setRow(int row) {\r
+               _rowIndex = row;\r
+       }\r
+\r
+       public final void setColumn(short col) {\r
+               _columnIndex = col;\r
+       }\r
+\r
+       /**\r
+        * set the index to the ExtendedFormat\r
+        * \r
+        * @see org.apache.poi.hssf.record.ExtendedFormatRecord\r
+        * @param xf index to the XF record\r
+        */\r
+       public final void setXFIndex(short xf) {\r
+               _formatIndex = xf;\r
+       }\r
+\r
+       public final int getRow() {\r
+               return _rowIndex;\r
+       }\r
+\r
+       public final short getColumn() {\r
+               return (short) _columnIndex;\r
+       }\r
+\r
+       /**\r
+        * get the index to the ExtendedFormat\r
+        * \r
+        * @see org.apache.poi.hssf.record.ExtendedFormatRecord\r
+        * @return index to the XF record\r
+        */\r
+       public final short getXFIndex() {\r
+               return (short) _formatIndex;\r
+       }\r
+\r
+       public final String toString() {\r
+               StringBuilder sb = new StringBuilder();\r
+               String recordName = getRecordName();\r
+\r
+               sb.append("[").append(recordName).append("]\n");\r
+               sb.append("    .row    = ").append(HexDump.shortToHex(getRow())).append("\n");\r
+               sb.append("    .col    = ").append(HexDump.shortToHex(getColumn())).append("\n");\r
+               sb.append("    .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");\r
+               appendValueText(sb);\r
+               sb.append("\n");\r
+               sb.append("[/NUMBER]\n");\r
+               return sb.toString();\r
+       }\r
+\r
+       /**\r
+        * Append specific debug info (used by {@link #toString()} for the value\r
+        * contained in this record. Trailing new-line should not be appended\r
+        * (superclass does that).\r
+        */\r
+       protected abstract void appendValueText(StringBuilder sb);\r
+\r
+       /**\r
+        * Gets the debug info BIFF record type name (used by {@link #toString()}.\r
+        */\r
+       protected abstract String getRecordName();\r
+\r
+       /**\r
+        * writes out the value data for this cell record\r
+        */\r
+       protected abstract void serializeValue(LittleEndianOutput out);\r
+\r
+       /**\r
+        * @return the size (in bytes) of the value data for this cell record\r
+        */\r
+       protected abstract int getValueDataSize();\r
+\r
+       public final void serialize(LittleEndianOutput out) {\r
+               out.writeShort(getRow());\r
+               out.writeShort(getColumn());\r
+               out.writeShort(getXFIndex());\r
+               serializeValue(out);\r
+       }\r
+\r
+       protected final int getDataSize() {\r
+               return 6 + getValueDataSize();\r
+       }\r
+\r
+       protected final void copyBaseFields(CellRecord rec) {\r
+               rec._rowIndex = _rowIndex;\r
+               rec._columnIndex = _columnIndex;\r
+               rec._formatIndex = _formatIndex;\r
+       }\r
+}\r
index 53ad71a51d6762bed54e92d5e43bb8c721ef1bf9..cd38fefd522fcae70dad12af0db1d8f22f84eb60 100644 (file)
@@ -24,7 +24,6 @@ import org.apache.poi.ss.formula.Formula;
 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 @@ import org.apache.poi.util.LittleEndianOutput;
  * 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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                }
        }
 
-
-
-       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 final class FormulaRecord extends StandardRecord implements CellValueReco
        }
 
        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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                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 @@ public final class FormulaRecord extends StandardRecord implements CellValueReco
                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;
index ee371b520345d32a3df16d76f2c176660732e64f..83667ef55f027a89001d6bdefb2342991e9e841c 100644 (file)
@@ -27,82 +27,30 @@ import org.apache.poi.util.LittleEndianOutput;
  * 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 @@ public final class LabelSSTRecord extends StandardRecord implements CellValueRec
      * @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;
     }
-
-    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();
+    
+    @Override
+    protected String getRecordName() {
+       return "LABELSST";
     }
 
-    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;
     }
index 5724b41a7c0cba224e36a80330c0a4f447b3fcfa..7380165c91d4d6f483b69c227eb8a1eaad0ab4de 100644 (file)
 
 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();
+    @Override
+    protected String getRecordName() {
+       return "NUMBER";
+    }
 
-        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();
+    @Override
+    protected void appendValueText(StringBuilder sb) {
+       sb.append("  .value= ").append(NumberToTextConverter.toText(field_4_value));
     }
 
-    public void serialize(LittleEndianOutput out) {
-        out.writeShort(getRow());
-        out.writeShort(getColumn());
-        out.writeShort(getXFIndex());
+    @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;
     }
index 966aaf219cc9653ff07e4a7cd402bdcc29649e1b..4ad30d915fa5df99133104f009c68853f73177e0 100644 (file)
@@ -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 @@ import org.apache.poi.util.LittleEndianOutput;
  * @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 @@ public final class RKRecord extends StandardRecord implements CellValueRecordInt
      * @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();
+    @Override
+    protected String getRecordName() {
+       return "RK";
     }
 
-       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 void appendValueText(StringBuilder sb) {
+       sb.append("  .value= ").append(getRKNumber());
     }
 
-    public void setColumn(short col)
-    {
+    @Override
+    protected void serializeValue(LittleEndianOutput out) {
+       out.writeInt(field_4_rk_number);
     }
 
-    public void setRow(int row)
-    {
+    @Override
+    protected int getValueDataSize() {
+       return 4;
     }
 
-    /**
-     * NO OP!
-     */
-
-    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;
     }