From 848f0563690baa22d3934dc7b63c2761baaaf3ff Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sat, 9 Jul 2016 18:52:26 +0000 Subject: [PATCH] javadocs fixes (jdk8) eclipse source clean-ups (final members, override annotations, for-each loops) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752037 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/ExtSSTRecord.java | 16 ++- .../poi/hssf/record/ExternSheetRecord.java | 34 ++++-- .../apache/poi/hssf/record/FontRecord.java | 6 + .../poi/hssf/record/FtPioGrbitSubRecord.java | 4 +- .../poi/hssf/record/HyperlinkRecord.java | 66 +++++++---- .../apache/poi/hssf/record/IndexRecord.java | 7 +- .../apache/poi/hssf/record/LabelRecord.java | 16 ++- .../poi/hssf/record/LabelSSTRecord.java | 6 +- .../poi/hssf/record/LbsDataSubRecord.java | 36 ++++-- .../poi/hssf/record/MergeCellsRecord.java | 8 +- .../apache/poi/hssf/record/MulRKRecord.java | 26 +++-- .../poi/hssf/record/NameCommentRecord.java | 2 + .../apache/poi/hssf/record/NameRecord.java | 21 ++-- .../apache/poi/hssf/record/NoteRecord.java | 8 ++ .../hssf/record/NoteStructureSubRecord.java | 8 +- .../apache/poi/hssf/record/OldCellRecord.java | 16 ++- .../poi/hssf/record/OldLabelRecord.java | 11 +- .../apache/poi/hssf/record/PaletteRecord.java | 20 +++- .../apache/poi/hssf/record/PaneRecord.java | 24 +++- .../apache/poi/hssf/record/RecordFactory.java | 38 ++++-- .../hssf/record/RecordFactoryInputStream.java | 5 +- .../poi/hssf/record/RecordInputStream.java | 108 +++++++++++------- .../org/apache/poi/hssf/record/SCLRecord.java | 16 ++- .../poi/hssf/record/SelectionRecord.java | 18 ++- .../record/aggregates/PageSettingsBlock.java | 62 ++++++---- 25 files changed, 411 insertions(+), 171 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java b/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java index d1885aa55a..3732fd52a5 100644 --- a/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java @@ -46,8 +46,12 @@ public final class ExtSSTRecord extends ContinuableRecord { /** unused - supposed to be zero */ private short field_3_zero; - /** Creates new ExtSSTInfoSubRecord */ - + /** + * Creates new ExtSSTInfoSubRecord + * + * @param streamPos stream pointer to the SST record + * @param bucketSstOffset ... don't really understand this yet + */ public InfoSubRecord(int streamPos, int bucketSstOffset) { field_1_stream_pos = streamPos; field_2_bucket_sst_offset = bucketSstOffset; @@ -155,7 +159,13 @@ public final class ExtSSTRecord extends ContinuableRecord { return infoRecs; } - /** Given a number of strings (in the sst), returns the size of the extsst record*/ + /** + * Given a number of strings (in the sst), returns the size of the extsst record + * + * @param numStrings the number of strings + * + * @return the size of the extsst record + */ public static final int getRecordSizeForStrings(int numStrings) { return 4 + 2 + getNumberOfInfoRecsForStrings(numStrings) * 8; } diff --git a/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java b/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java index 37d8c4daa5..343c1498ec 100644 --- a/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java @@ -29,13 +29,13 @@ import org.apache.poi.util.LittleEndianOutput; public class ExternSheetRecord extends StandardRecord { public final static short sid = 0x0017; - private List _list; + private final List _list; private static final class RefSubRecord { public static final int ENCODED_SIZE = 6; /** index to External Book Block (which starts with a EXTERNALBOOK record) */ - private int _extBookIndex; + private final int _extBookIndex; private int _firstSheetIndex; // may be -1 (0xFFFF) private int _lastSheetIndex; // may be -1 (0xFFFF) @@ -196,6 +196,8 @@ public class ExternSheetRecord extends StandardRecord { } /** + * @param extBookIndex external sheet reference index + * * @return -1 if not found */ public int findRefIndexFromExtBookIndex(int extBookIndex) { @@ -212,6 +214,12 @@ public class ExternSheetRecord extends StandardRecord { * Returns the first sheet that the reference applies to, or * -1 if the referenced sheet can't be found, or -2 if the * reference is workbook scoped. + * + * @param extRefIndex external sheet reference index + * + * @return the first sheet that the reference applies to, or + * -1 if the referenced sheet can't be found, or -2 if the + * reference is workbook scoped */ public int getFirstSheetIndexFromRefIndex(int extRefIndex) { return getRef(extRefIndex).getFirstSheetIndex(); @@ -223,6 +231,12 @@ public class ExternSheetRecord extends StandardRecord { * reference is workbook scoped. * For a single sheet reference, the first and last should be * the same. + * + * @param extRefIndex external sheet reference index + * + * @return the last sheet that the reference applies to, or + * -1 if the referenced sheet can't be found, or -2 if the + * reference is workbook scoped. */ public int getLastSheetIndexFromRefIndex(int extRefIndex) { return getRef(extRefIndex).getLastSheetIndex(); @@ -235,25 +249,24 @@ public class ExternSheetRecord extends StandardRecord { * DDE data source referencing, or OLE data source referencing, * then no scope is specified and this value MUST be -2. Otherwise, * the scope must be set as follows: - *
    + *
      *
    1. -2 Workbook-level reference that applies to the entire workbook.
    2. *
    3. -1 Sheet-level reference.
    4. *
    5. >=0 Sheet-level reference. This specifies the first sheet in the reference. - *

      - * If the SupBook type is unused or external workbook referencing, + *

      If the SupBook type is unused or external workbook referencing, * then this value specifies the zero-based index of an external sheet name, * see {@link org.apache.poi.hssf.record.SupBookRecord#getSheetNames()}. * This referenced string specifies the name of the first sheet within the external workbook that is in scope. - * This sheet MUST be a worksheet or macro sheet. - *

      - *

      - * If the supporting link type is self-referencing, then this value specifies the zero-based index of a + * This sheet MUST be a worksheet or macro sheet.

      + * + *

      If the supporting link type is self-referencing, then this value specifies the zero-based index of a * {@link org.apache.poi.hssf.record.BoundSheetRecord} record in the workbook stream that specifies * the first sheet within the scope of this reference. This sheet MUST be a worksheet or a macro sheet. *

      *
    6. *
    * + * @param extBookIndex the external book block index * @param firstSheetIndex the scope, must be -2 for add-in references * @param lastSheetIndex the scope, must be -2 for add-in references * @return index of newly added ref @@ -280,8 +293,7 @@ public class ExternSheetRecord extends StandardRecord { public static ExternSheetRecord combine(ExternSheetRecord[] esrs) { ExternSheetRecord result = new ExternSheetRecord(); - for (int i = 0; i < esrs.length; i++) { - ExternSheetRecord esr = esrs[i]; + for (ExternSheetRecord esr : esrs) { int nRefs = esr.getNumOfREFRecords(); for (int j=0; j 0 @@ -690,6 +710,8 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable { } /** * Based on the link options, is this a file? + * + * @return true, if this is a file link */ public boolean isFileLink() { return (_linkOpts & HLINK_URL) > 0 @@ -697,6 +719,8 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable { } /** * Based on the link options, is this a document? + * + * @return true, if this is a docment link */ public boolean isDocumentLink() { return (_linkOpts & HLINK_PLACE) > 0; diff --git a/src/java/org/apache/poi/hssf/record/IndexRecord.java b/src/java/org/apache/poi/hssf/record/IndexRecord.java index a54fb656ce..4eb000b55c 100644 --- a/src/java/org/apache/poi/hssf/record/IndexRecord.java +++ b/src/java/org/apache/poi/hssf/record/IndexRecord.java @@ -103,6 +103,7 @@ public final class IndexRecord extends StandardRecord implements Cloneable { return field_5_dbcells.get(cellnum); } + @Override public String toString() { StringBuffer buffer = new StringBuffer(); @@ -120,6 +121,7 @@ public final class IndexRecord extends StandardRecord implements Cloneable { return buffer.toString(); } + @Override public void serialize(LittleEndianOutput out) { out.writeInt(0); @@ -131,18 +133,21 @@ public final class IndexRecord extends StandardRecord implements Cloneable { } } + @Override protected int getDataSize() { return 16 // 4 ints + getNumDbcells() * 4; } /** - * @return the size of an INdexRecord when it needs to index the specified number of blocks + * @param blockCount the number of blocks to be indexed + * @return the size of an IndexRecord when it needs to index the specified number of blocks */ public static int getRecordSizeForBlockCount(int blockCount) { return 20 + 4 * blockCount; } + @Override public short getSid() { return sid; } diff --git a/src/java/org/apache/poi/hssf/record/LabelRecord.java b/src/java/org/apache/poi/hssf/record/LabelRecord.java index 68c42f8f27..bac8ce2b8c 100644 --- a/src/java/org/apache/poi/hssf/record/LabelRecord.java +++ b/src/java/org/apache/poi/hssf/record/LabelRecord.java @@ -22,9 +22,9 @@ import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; /** - * Label Record (0x0204) - read only support for strings stored directly in the cell.. Don't - * use this (except to read), use LabelSST instead

    - * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

    + * Label Record (0x0204) - read only support for strings stored directly in the cell... + * Don't use this (except to read), use LabelSST instead

    + * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) * * @see org.apache.poi.hssf.record.LabelSSTRecord */ @@ -76,16 +76,19 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac /* * READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! public */ + @Override public int getRow() { return field_1_row; } + @Override public short getColumn() { return field_2_column; } + @Override public short getXFIndex() { return field_3_xf_index; @@ -123,18 +126,22 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac /** * THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!! */ + @Override public int serialize(int offset, byte [] data) { throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST"); } + @Override public int getRecordSize() { throw new RecordFormatException("Label Records are supported READ ONLY...convert to LabelSST"); } + @Override public short getSid() { return sid; } + @Override public String toString() { StringBuffer sb = new StringBuffer(); @@ -152,6 +159,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac /** * NO-OP! */ + @Override public void setColumn(short col) { } @@ -159,6 +167,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac /** * NO-OP! */ + @Override public void setRow(int row) { } @@ -166,6 +175,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac /** * no op! */ + @Override public void setXFIndex(short xf) { } diff --git a/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java b/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java index ff7277d5ae..80bd99cfc1 100644 --- a/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java +++ b/src/java/org/apache/poi/hssf/record/LabelSSTRecord.java @@ -22,9 +22,8 @@ import org.apache.poi.util.LittleEndianOutput; /** * Title: Label SST Record

    - * Description: Refers to a string in the shared string table and is a column - * value.

    - * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

    + * Description: Refers to a string in the shared string table and is a column value.

    + * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) */ public final class LabelSSTRecord extends CellRecord implements Cloneable { public final static short sid = 0xfd; @@ -80,6 +79,7 @@ public final class LabelSSTRecord extends CellRecord implements Cloneable { return 4; } + @Override public short getSid() { return sid; } diff --git a/src/java/org/apache/poi/hssf/record/LbsDataSubRecord.java b/src/java/org/apache/poi/hssf/record/LbsDataSubRecord.java index 5e91b18e78..2e98cba55e 100644 --- a/src/java/org/apache/poi/hssf/record/LbsDataSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/LbsDataSubRecord.java @@ -270,12 +270,16 @@ public class LbsDataSubRecord extends SubRecord { sb.append("[ftLbsData]\n"); sb.append(" .unknownShort1 =").append(HexDump.shortToHex(_cbFContinued)).append("\n"); sb.append(" .formula = ").append('\n'); - if(_linkPtg != null) sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n'); + if(_linkPtg != null) { + sb.append(_linkPtg.toString()).append(_linkPtg.getRVAType()).append('\n'); + } sb.append(" .nEntryCount =").append(HexDump.shortToHex(_cLines)).append("\n"); sb.append(" .selEntryIx =").append(HexDump.shortToHex(_iSel)).append("\n"); sb.append(" .style =").append(HexDump.shortToHex(_flags)).append("\n"); sb.append(" .unknownShort10=").append(HexDump.shortToHex(_idEdit)).append("\n"); - if(_dropData != null) sb.append('\n').append(_dropData.toString()); + if(_dropData != null) { + sb.append('\n').append(_dropData.toString()); + } sb.append("[/ftLbsData]\n"); return sb.toString(); } @@ -354,14 +358,16 @@ public class LbsDataSubRecord extends SubRecord { } /** - * Set the style of this dropdown. + * Set the style of this dropdown.

    * * Possible values: - *

    - * 0 Combo dropdown control - * 1 Combo Edit dropdown control - * 2 Simple dropdown control (just the dropdown button) - * + *

      + *
    • 0: Combo dropdown control
    • + *
    • 1: Combo Edit dropdown control
    • + *
    • 2: Simple dropdown control (just the dropdown button)
    • + *
    + * + * @param style the style - see possible values */ public void setStyle(int style){ _wStyle = style; @@ -369,6 +375,8 @@ public class LbsDataSubRecord extends SubRecord { /** * Set the number of lines to be displayed in the dropdown. + * + * @param num the number of lines to be displayed in the dropdown */ public void setNumLines(int num){ _cLine = num; @@ -379,13 +387,17 @@ public class LbsDataSubRecord extends SubRecord { out.writeShort(_cLine); out.writeShort(_dxMin); StringUtil.writeUnicodeString(out, _str); - if(_unused != null) out.writeByte(_unused); + if(_unused != null) { + out.writeByte(_unused); + } } public int getDataSize() { int size = 6; size += StringUtil.getEncodedSize(_str); - if(_unused != null) size++; + if(_unused != null) { + size++; + } return size; } @@ -397,7 +409,9 @@ public class LbsDataSubRecord extends SubRecord { sb.append(" ._cLine: ").append(_cLine).append('\n'); sb.append(" ._dxMin: ").append(_dxMin).append('\n'); sb.append(" ._str: ").append(_str).append('\n'); - if(_unused != null) sb.append(" ._unused: ").append(_unused).append('\n'); + if(_unused != null) { + sb.append(" ._unused: ").append(_unused).append('\n'); + } sb.append("[/LbsDropData]\n"); return sb.toString(); diff --git a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java index 227a019ec5..f9ebfd34aa 100644 --- a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java +++ b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java @@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndianOutput; public final class MergeCellsRecord extends StandardRecord implements Cloneable { public final static short sid = 0x00E5; /** sometimes the regions array is shared with other MergedCellsRecords */ - private CellRangeAddress[] _regions; + private final CellRangeAddress[] _regions; private final int _startIndex; private final int _numberOfRegions; @@ -62,20 +62,25 @@ public final class MergeCellsRecord extends StandardRecord implements Cloneable } /** + * @param index the n-th MergedRegion + * * @return MergedRegion at the given index representing the area that is Merged (r1,c1 - r2,c2) */ public CellRangeAddress getAreaAt(int index) { return _regions[_startIndex + index]; } + @Override protected int getDataSize() { return CellRangeAddressList.getEncodedSize(_numberOfRegions); } + @Override public short getSid() { return sid; } + @Override public void serialize(LittleEndianOutput out) { int nItems = _numberOfRegions; out.writeShort(nItems); @@ -84,6 +89,7 @@ public final class MergeCellsRecord extends StandardRecord implements Cloneable } } + @Override public String toString() { StringBuffer retval = new StringBuffer(); diff --git a/src/java/org/apache/poi/hssf/record/MulRKRecord.java b/src/java/org/apache/poi/hssf/record/MulRKRecord.java index f0629ca2d4..99420144c0 100644 --- a/src/java/org/apache/poi/hssf/record/MulRKRecord.java +++ b/src/java/org/apache/poi/hssf/record/MulRKRecord.java @@ -33,10 +33,10 @@ import org.apache.poi.util.LittleEndianOutput; public final class MulRKRecord extends StandardRecord { public final static short sid = 0x00BD; - private int field_1_row; - private short field_2_first_col; - private RkRec[] field_3_rks; - private short field_4_last_col; + private final int field_1_row; + private final short field_2_first_col; + private final RkRec[] field_3_rks; + private final short field_4_last_col; public int getRow() { return field_1_row; @@ -68,6 +68,9 @@ public final class MulRKRecord extends StandardRecord { /** * returns the xf index for column (coffset = column - field_2_first_col) + * + * @param coffset the coffset = column - field_2_first_col + * * @return the XF index for the column */ public short getXFAt(int coffset) { @@ -76,6 +79,9 @@ public final class MulRKRecord extends StandardRecord { /** * returns the rk number for column (coffset = column - field_2_first_col) + * + * @param coffset the coffset = column - field_2_first_col + * * @return the value (decoded into a double) */ public double getRKNumberAt(int coffset) { @@ -93,7 +99,8 @@ public final class MulRKRecord extends StandardRecord { } - public String toString() { + @Override + public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[MULRK]\n"); @@ -109,15 +116,18 @@ public final class MulRKRecord extends StandardRecord { return buffer.toString(); } - public short getSid() + @Override + public short getSid() { return sid; } - public void serialize(LittleEndianOutput out) { + @Override + public void serialize(LittleEndianOutput out) { throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release"); } - protected int getDataSize() { + @Override + protected int getDataSize() { throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release"); } diff --git a/src/java/org/apache/poi/hssf/record/NameCommentRecord.java b/src/java/org/apache/poi/hssf/record/NameCommentRecord.java index dc7a9b3c34..0a3323f886 100644 --- a/src/java/org/apache/poi/hssf/record/NameCommentRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameCommentRecord.java @@ -138,6 +138,8 @@ public final class NameCommentRecord extends StandardRecord { /** * Updates the name we're associated with, normally used * when renaming that Name + * + * @param newName the new name */ public void setNameText(String newName) { field_6_name_text = newName; diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index 1e44ed651b..613239bd53 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -101,13 +101,15 @@ public final class NameRecord extends ContinuableRecord { /** * Constructor to create a built-in named region * @param builtin Built-in byte representation for the name record, use the public constants + * @param sheetNumber the sheet which the name applies to */ public NameRecord(byte builtin, int sheetNumber) { this(); field_12_built_in_code = builtin; setOptionFlag((short)(field_1_option_flag | Option.OPT_BUILTIN)); - field_6_sheetNumber = sheetNumber; //the extern sheets are set through references + // the extern sheets are set through references + field_6_sheetNumber = sheetNumber; } /** sets the option flag for the named range @@ -272,7 +274,10 @@ public final class NameRecord extends ContinuableRecord { return (field_1_option_flag & Option.OPT_COMPLEX) != 0; } - /**Convenience Function to determine if the name is a built-in name + /** + * Convenience Function to determine if the name is a built-in name + * + * @return true, if the name is a built-in name */ public boolean isBuiltInName() { @@ -341,7 +346,8 @@ public final class NameRecord extends ContinuableRecord { * * @param out a data output stream */ - public void serialize(ContinuableRecordOutput out) { + @Override + public void serialize(ContinuableRecordOutput out) { int field_7_length_custom_menu = field_14_custom_menu_text.length(); int field_8_length_description_text = field_15_description_text.length(); @@ -473,7 +479,8 @@ public final class NameRecord extends ContinuableRecord { /** * return the non static version of the id for this record. */ - public short getSid() { + @Override + public short getSid() { return sid; } /* @@ -527,7 +534,8 @@ public final class NameRecord extends ContinuableRecord { 3B 00 00 07 00 07 00 00 00 FF 00 ] */ - public String toString() { + @Override + public String toString() { StringBuffer sb = new StringBuffer(); sb.append("[NAME]\n"); @@ -544,8 +552,7 @@ public final class NameRecord extends ContinuableRecord { sb.append(" .Name (Unicode text) = ").append( getNameText() ).append("\n"); Ptg[] ptgs = field_13_name_definition.getTokens(); sb.append(" .Formula (nTokens=").append(ptgs.length).append("):") .append("\n"); - for (int i = 0; i < ptgs.length; i++) { - Ptg ptg = ptgs[i]; + for (Ptg ptg : ptgs) { sb.append(" " + ptg.toString()).append(ptg.getRVAType()).append("\n"); } diff --git a/src/java/org/apache/poi/hssf/record/NoteRecord.java b/src/java/org/apache/poi/hssf/record/NoteRecord.java index 6fadf861d3..1717444a70 100644 --- a/src/java/org/apache/poi/hssf/record/NoteRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteRecord.java @@ -73,6 +73,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable { /** * Read the record data from the supplied RecordInputStream + * + * @param in the RecordInputStream to read from */ public NoteRecord(RecordInputStream in) { field_1_row = in.readUShort(); @@ -195,6 +197,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable { /** * For unit testing only! + * + * @return true, if author element uses multi byte */ protected boolean authorIsMultibyte() { return field_5_hasMultibyte; @@ -202,6 +206,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable { /** * Object id for OBJ record that contains the comment + * + * @return the Object id for OBJ record that contains the comment */ public int getShapeId() { return field_4_shapeid; @@ -209,6 +215,8 @@ public final class NoteRecord extends StandardRecord implements Cloneable { /** * Object id for OBJ record that contains the comment + * + * @param id the Object id for OBJ record that contains the comment */ public void setShapeId(int id) { field_4_shapeid = id; diff --git a/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java b/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java index 7780b15834..b2c18781e1 100644 --- a/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java @@ -45,6 +45,9 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable /** * Read the record data from the supplied RecordInputStream + * + * @param in the input to read from + * @param size the provided size - must be 22 */ public NoteStructureSubRecord(LittleEndianInput in, int size) { if (size != ENCODED_SIZE) { @@ -60,6 +63,7 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable * Convert this record to string. * Used by BiffViewer and other utilities. */ + @Override public String toString() { StringBuffer buffer = new StringBuffer(); @@ -76,13 +80,15 @@ public final class NoteStructureSubRecord extends SubRecord implements Cloneable * * @param out the stream to serialize into */ + @Override public void serialize(LittleEndianOutput out) { out.writeShort(sid); out.writeShort(reserved.length); out.write(reserved); } - protected int getDataSize() { + @Override + protected int getDataSize() { return reserved.length; } diff --git a/src/java/org/apache/poi/hssf/record/OldCellRecord.java b/src/java/org/apache/poi/hssf/record/OldCellRecord.java index 06a6b4d530..76f2dd300d 100644 --- a/src/java/org/apache/poi/hssf/record/OldCellRecord.java +++ b/src/java/org/apache/poi/hssf/record/OldCellRecord.java @@ -25,10 +25,10 @@ import org.apache.poi.util.HexDump; * Subclasses are expected to manage the cell data values (of various types). */ public abstract class OldCellRecord { - private short sid; - private boolean isBiff2; - private int field_1_row; - private short field_2_column; + private final short sid; + private final boolean isBiff2; + private final int field_1_row; + private final short field_2_column; private int field_3_cell_attrs; // Biff 2 private short field_3_xf_index; // Biff 3+ @@ -63,6 +63,7 @@ public abstract class OldCellRecord { public final short getXFIndex() { return field_3_xf_index; } + public int getCellAttrs() { return field_3_cell_attrs; @@ -70,10 +71,13 @@ public abstract class OldCellRecord { /** * Is this a Biff2 record, or newer? + * + * @return true, if this is a Biff2 record or newer */ public boolean isBiff2() { return isBiff2; } + public short getSid() { return sid; } @@ -101,11 +105,15 @@ public abstract class OldCellRecord { * 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). + * + * @param sb the StringBuilder to append to */ protected abstract void appendValueText(StringBuilder sb); /** * Gets the debug info BIFF record type name (used by {@link #toString()}. + * + * @return the debug info BIFF record type name */ protected abstract String getRecordName(); } diff --git a/src/java/org/apache/poi/hssf/record/OldLabelRecord.java b/src/java/org/apache/poi/hssf/record/OldLabelRecord.java index ad6772382f..c123749338 100644 --- a/src/java/org/apache/poi/hssf/record/OldLabelRecord.java +++ b/src/java/org/apache/poi/hssf/record/OldLabelRecord.java @@ -33,7 +33,7 @@ public final class OldLabelRecord extends OldCellRecord { public final static short biff345_sid = 0x0204; private short field_4_string_len; - private byte[] field_5_bytes; + private final byte[] field_5_bytes; private CodepageRecord codepage; /** @@ -76,6 +76,8 @@ public final class OldLabelRecord extends OldCellRecord { /** * Get the String of the cell + * + * @return the String of the cell */ public String getValue() { @@ -84,19 +86,26 @@ public final class OldLabelRecord extends OldCellRecord { /** * Not supported + * + * @param offset not supported + * @param data not supported + * @return not supported */ public int serialize(int offset, byte [] data) { throw new RecordFormatException("Old Label Records are supported READ ONLY"); } + public int getRecordSize() { throw new RecordFormatException("Old Label Records are supported READ ONLY"); } + @Override protected void appendValueText(StringBuilder sb) { sb.append(" .string_len= ").append(HexDump.shortToHex(field_4_string_len)).append("\n"); sb.append(" .value = ").append(getValue()).append("\n"); } + @Override protected String getRecordName() { return "OLD LABEL"; } diff --git a/src/java/org/apache/poi/hssf/record/PaletteRecord.java b/src/java/org/apache/poi/hssf/record/PaletteRecord.java index 2f222465b6..5fa318b8d0 100644 --- a/src/java/org/apache/poi/hssf/record/PaletteRecord.java +++ b/src/java/org/apache/poi/hssf/record/PaletteRecord.java @@ -40,8 +40,8 @@ public final class PaletteRecord extends StandardRecord { public PaletteRecord() { PColor[] defaultPalette = createDefaultPalette(); _colors = new ArrayList(defaultPalette.length); - for (int i = 0; i < defaultPalette.length; i++) { - _colors.add(defaultPalette[i]); + for (PColor element : defaultPalette) { + _colors.add(element); } } @@ -53,6 +53,7 @@ public final class PaletteRecord extends StandardRecord { } } + @Override public String toString() { StringBuffer buffer = new StringBuffer(); @@ -68,6 +69,7 @@ public final class PaletteRecord extends StandardRecord { return buffer.toString(); } + @Override public void serialize(LittleEndianOutput out) { out.writeShort(_colors.size()); for (int i = 0; i < _colors.size(); i++) { @@ -75,16 +77,20 @@ public final class PaletteRecord extends StandardRecord { } } + @Override protected int getDataSize() { return 2 + _colors.size() * PColor.ENCODED_SIZE; } + @Override public short getSid() { return sid; } /** * Returns the color value at a given index + * + * @param byteIndex palette index, must be >= 0x8 * * @return the RGB triplet for the color, or null if the specified index * does not exist @@ -105,6 +111,9 @@ public final class PaletteRecord extends StandardRecord { * * @param byteIndex the index to set; if this index is less than 0x8 or greater than * 0x40, then no modification is made + * @param red the red color part + * @param green the green color part + * @param blue the blue color part */ public void setColor(short byteIndex, byte red, byte green, byte blue) { @@ -195,9 +204,9 @@ public final class PaletteRecord extends StandardRecord { */ private static final class PColor { public static final short ENCODED_SIZE = 4; - private int _red; - private int _green; - private int _blue; + private final int _red; + private final int _green; + private final int _blue; public PColor(int red, int green, int blue) { _red = red; @@ -223,6 +232,7 @@ public final class PaletteRecord extends StandardRecord { out.writeByte(0); } + @Override public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(" red = ").append(_red & 0xff).append('\n'); diff --git a/src/java/org/apache/poi/hssf/record/PaneRecord.java b/src/java/org/apache/poi/hssf/record/PaneRecord.java index 5bff223b22..b33b48fba6 100644 --- a/src/java/org/apache/poi/hssf/record/PaneRecord.java +++ b/src/java/org/apache/poi/hssf/record/PaneRecord.java @@ -51,6 +51,7 @@ public final class PaneRecord extends StandardRecord { field_5_activePane = in.readShort(); } + @Override public String toString() { StringBuffer buffer = new StringBuffer(); @@ -81,6 +82,7 @@ public final class PaneRecord extends StandardRecord { return buffer.toString(); } + @Override public void serialize(LittleEndianOutput out) { out.writeShort(field_1_x); out.writeShort(field_2_y); @@ -89,15 +91,18 @@ public final class PaneRecord extends StandardRecord { out.writeShort(field_5_activePane); } + @Override protected int getDataSize() { return 2 + 2 + 2 + 2 + 2; } + @Override public short getSid() { return sid; } + @Override public Object clone() { PaneRecord rec = new PaneRecord(); @@ -109,11 +114,10 @@ public final class PaneRecord extends StandardRecord { return rec; } - - - /** * Get the x field for the Pane record. + * + * @param the x value */ public short getX() { @@ -122,6 +126,8 @@ public final class PaneRecord extends StandardRecord { /** * Set the x field for the Pane record. + * + * @param field_1_x the x value */ public void setX(short field_1_x) { @@ -130,6 +136,8 @@ public final class PaneRecord extends StandardRecord { /** * Get the y field for the Pane record. + * + * @return the y value */ public short getY() { @@ -138,6 +146,8 @@ public final class PaneRecord extends StandardRecord { /** * Set the y field for the Pane record. + * + * @param field_2_y the y value */ public void setY(short field_2_y) { @@ -146,6 +156,8 @@ public final class PaneRecord extends StandardRecord { /** * Get the top row field for the Pane record. + * + * @return the top row */ public short getTopRow() { @@ -154,6 +166,8 @@ public final class PaneRecord extends StandardRecord { /** * Set the top row field for the Pane record. + * + * @param field_3_topRow the top row */ public void setTopRow(short field_3_topRow) { @@ -162,6 +176,8 @@ public final class PaneRecord extends StandardRecord { /** * Get the left column field for the Pane record. + * + * @return the left column */ public short getLeftColumn() { @@ -170,6 +186,8 @@ public final class PaneRecord extends StandardRecord { /** * Set the left column field for the Pane record. + * + * @param field_4_leftColumn the left column */ public void setLeftColumn(short field_4_leftColumn) { diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index d56eec0c29..3a99291952 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -78,6 +77,7 @@ public final class RecordFactory { public ReflectionConstructorRecordCreator(Constructor c) { _c = c; } + @Override public Record create(RecordInputStream in) { Object[] args = { in, }; try { @@ -99,6 +99,7 @@ public final class RecordFactory { } } } + @Override public Class getRecordClass() { return _c.getDeclaringClass(); } @@ -112,6 +113,7 @@ public final class RecordFactory { public ReflectionMethodRecordCreator(Method m) { _m = m; } + @Override public Record create(RecordInputStream in) { Object[] args = { in, }; try { @@ -124,6 +126,7 @@ public final class RecordFactory { throw new RecordFormatException("Unable to construct record instance" , e.getTargetException()); } } + @Override @SuppressWarnings("unchecked") public Class getRecordClass() { return (Class) _m.getDeclaringClass(); @@ -292,9 +295,13 @@ public final class RecordFactory { /** * Debug / diagnosis method

    - * Gets the POI implementation class for a given {@code sid}. Only a subset of the any BIFF + * + * Gets the POI implementation class for a given {@code sid}. Only a subset of the BIFF * records are actually interpreted by POI. A few others are known but not interpreted * (see {@link UnknownRecord#getBiffName(int)}). + * + * @param sid the record sid + * * @return the POI implementation class for the specified record {@code sid}. * {@code null} if the specified record is not interpreted by POI. */ @@ -305,9 +312,13 @@ public final class RecordFactory { } return rc.getRecordClass(); } + /** * create a record, if there are MUL records than multiple records * are returned digested into the non-mul form. + * + * @param in the RecordInputStream to read from + * @return the extracted records */ public static Record [] createRecord(RecordInputStream in) { Record record = createSingleRecord(in); @@ -337,6 +348,9 @@ public final class RecordFactory { /** * RK record is a slightly smaller alternative to NumberRecord * POI likes NumberRecord better + * + * @param the RK record to convert + * @return the NumberRecord */ public static NumberRecord convertToNumberRecord(RKRecord rk) { NumberRecord num = new NumberRecord(); @@ -349,7 +363,10 @@ public final class RecordFactory { } /** - * Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord}s + * Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord NumberRecords} + * + * @param mrk the MulRKRecord to convert + * @return the equivalent array of {@link NumberRecord NumberRecords} */ public static NumberRecord[] convertRKRecords(MulRKRecord mrk) { NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()]; @@ -366,7 +383,10 @@ public final class RecordFactory { } /** - * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord}s + * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord BlankRecords} + * + * @param mbk the MulBlankRecord to convert + * @return the equivalent array of {@link BlankRecord BlankRecords} */ public static BlankRecord[] convertBlankRecords(MulBlankRecord mbk) { BlankRecord[] mulRecs = new BlankRecord[mbk.getNumColumns()]; @@ -389,9 +409,7 @@ public final class RecordFactory { short[] results = new short[ _recordCreatorsById.size() ]; int i = 0; - for (Iterator iterator = _recordCreatorsById.keySet().iterator(); iterator.hasNext(); ) { - Integer sid = iterator.next(); - + for (Integer sid : _recordCreatorsById.keySet()) { results[i++] = sid.shortValue(); } Arrays.sort(results); @@ -410,9 +428,7 @@ public final class RecordFactory { Map result = new HashMap(); Set> uniqueRecClasses = new HashSet>(records.length * 3 / 2); - for (int i = 0; i < records.length; i++) { - - Class recClass = records[ i ]; + for (Class recClass : records) { if(!Record.class.isAssignableFrom(recClass)) { throw new RuntimeException("Invalid record sub-class (" + recClass.getName() + ")"); } @@ -433,7 +449,7 @@ public final class RecordFactory { Integer key = Integer.valueOf(sid); if (result.containsKey(key)) { Class prevClass = result.get(key).getRecordClass(); - throw new RuntimeException("duplicate record sid 0x" + + throw new RuntimeException("duplicate record sid 0x" + Integer.toHexString(sid).toUpperCase(Locale.ROOT) + " for classes (" + recClass.getName() + ") and (" + prevClass.getName() + ")"); diff --git a/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java b/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java index 3f6a9c4691..c7480147b3 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java @@ -193,6 +193,8 @@ public final class RecordFactoryInputStream { /** + * @param in the InputStream to read from + * * @param shouldIncludeContinueRecords caller can pass false if loose * {@link ContinueRecord}s should be skipped (this is sometimes useful in event based * processing). @@ -238,8 +240,7 @@ public final class RecordFactoryInputStream { } /** - * Returns the next (complete) record from the - * stream, or null if there are no more. + * @return the next (complete) record from the stream, or null if there are no more. */ public Record nextRecord() { Record r; diff --git a/src/java/org/apache/poi/hssf/record/RecordInputStream.java b/src/java/org/apache/poi/hssf/record/RecordInputStream.java index 81ec0776b3..f9212c7986 100644 --- a/src/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -25,6 +25,7 @@ import org.apache.poi.hssf.dev.BiffViewer; import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInputStream; @@ -98,13 +99,16 @@ public final class RecordInputStream implements LittleEndianInput { public SimpleHeaderInput(InputStream in) { _lei = getLEI(in); } - public int available() { + @Override + public int available() { return _lei.available(); } - public int readDataSize() { + @Override + public int readDataSize() { return _lei.readUShort(); } - public int readRecordSID() { + @Override + public int readRecordSID() { return _lei.readUShort(); } } @@ -138,7 +142,8 @@ public final class RecordInputStream implements LittleEndianInput { * @return the number of bytes available in the current BIFF record * @see #remaining() */ - public int available() { + @Override + public int available() { return remaining(); } @@ -158,6 +163,9 @@ public final class RecordInputStream implements LittleEndianInput { /** * Note - this method is expected to be called only when completed reading the current BIFF * record. + * + * @return true, if there's another record in the stream + * * @throws LeftoverDataException if this method is called before reaching the end of the * current record. */ @@ -230,56 +238,63 @@ public final class RecordInputStream implements LittleEndianInput { /** * Reads an 8 bit, signed value */ - public byte readByte() { - checkRecordPosition(LittleEndian.BYTE_SIZE); - _currentDataOffset += LittleEndian.BYTE_SIZE; + @Override + public byte readByte() { + checkRecordPosition(LittleEndianConsts.BYTE_SIZE); + _currentDataOffset += LittleEndianConsts.BYTE_SIZE; return _dataInput.readByte(); } /** * Reads a 16 bit, signed value */ - public short readShort() { - checkRecordPosition(LittleEndian.SHORT_SIZE); - _currentDataOffset += LittleEndian.SHORT_SIZE; + @Override + public short readShort() { + checkRecordPosition(LittleEndianConsts.SHORT_SIZE); + _currentDataOffset += LittleEndianConsts.SHORT_SIZE; return _dataInput.readShort(); } /** * Reads a 32 bit, signed value */ - public int readInt() { - checkRecordPosition(LittleEndian.INT_SIZE); - _currentDataOffset += LittleEndian.INT_SIZE; + @Override + public int readInt() { + checkRecordPosition(LittleEndianConsts.INT_SIZE); + _currentDataOffset += LittleEndianConsts.INT_SIZE; return _dataInput.readInt(); } /** * Reads a 64 bit, signed value */ - public long readLong() { - checkRecordPosition(LittleEndian.LONG_SIZE); - _currentDataOffset += LittleEndian.LONG_SIZE; + @Override + public long readLong() { + checkRecordPosition(LittleEndianConsts.LONG_SIZE); + _currentDataOffset += LittleEndianConsts.LONG_SIZE; return _dataInput.readLong(); } /** * Reads an 8 bit, unsigned value */ - public int readUByte() { + @Override + public int readUByte() { return readByte() & 0x00FF; } /** * Reads a 16 bit, unsigned value. */ - public int readUShort() { - checkRecordPosition(LittleEndian.SHORT_SIZE); - _currentDataOffset += LittleEndian.SHORT_SIZE; + @Override + public int readUShort() { + checkRecordPosition(LittleEndianConsts.SHORT_SIZE); + _currentDataOffset += LittleEndianConsts.SHORT_SIZE; return _dataInput.readUShort(); } - public double readDouble() { + @Override + public double readDouble() { long valueLongBits = readLong(); double result = Double.longBitsToDouble(valueLongBits); if (Double.isNaN(result)) { @@ -290,11 +305,13 @@ public final class RecordInputStream implements LittleEndianInput { } return result; } - public void readFully(byte[] buf) { + @Override + public void readFully(byte[] buf) { readFully(buf, 0, buf.length); } - public void readFully(byte[] buf, int off, int len) { + @Override + public void readFully(byte[] buf, int off, int len) { int origLen = len; if (buf == null) { throw new NullPointerException(); @@ -355,7 +372,7 @@ public final class RecordInputStream implements LittleEndianInput { boolean isCompressedEncoding = pIsCompressedEncoding; int curLen = 0; while(true) { - int availableChars =isCompressedEncoding ? remaining() : remaining() / LittleEndian.SHORT_SIZE; + int availableChars =isCompressedEncoding ? remaining() : remaining() / LittleEndianConsts.SHORT_SIZE; if (requestedLength - curLen <= availableChars) { // enough space in current record, so just read it out while(curLen < requestedLength) { @@ -412,27 +429,30 @@ public final class RecordInputStream implements LittleEndianInput { return result; } - /** Reads all byte data for the current record, including any - * that overlaps into any following continue records. - * - * @deprecated POI 2.0 Best to write a input stream that wraps this one where there is - * special sub record that may overlap continue records. - */ - public byte[] readAllContinuedRemainder() { - //Using a ByteArrayOutputStream is just an easy way to get a - //growable array of the data. - ByteArrayOutputStream out = new ByteArrayOutputStream(2*MAX_RECORD_DATA_SIZE); - - while (true) { - byte[] b = readRemainder(); - out.write(b, 0, b.length); - if (!isContinueNext()) { - break; - } - nextRecord(); + /** + * Reads all byte data for the current record, including any that overlaps + * into any following continue records. + * + * @return all byte data for the current record + * + * @deprecated POI 2.0 Best to write a input stream that wraps this one + * where there is special sub record that may overlap continue + * records. + */ + @Deprecated + public byte[] readAllContinuedRemainder() { + ByteArrayOutputStream out = new ByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE); + + while (true) { + byte[] b = readRemainder(); + out.write(b, 0, b.length); + if (!isContinueNext()) { + break; + } + nextRecord(); + } + return out.toByteArray(); } - return out.toByteArray(); - } /** The remaining number of bytes in the current record. * diff --git a/src/java/org/apache/poi/hssf/record/SCLRecord.java b/src/java/org/apache/poi/hssf/record/SCLRecord.java index 6ef6aae908..5b360937f8 100644 --- a/src/java/org/apache/poi/hssf/record/SCLRecord.java +++ b/src/java/org/apache/poi/hssf/record/SCLRecord.java @@ -41,6 +41,7 @@ public final class SCLRecord extends StandardRecord { field_2_denominator = in.readShort(); } + @Override public String toString() { StringBuffer buffer = new StringBuffer(); @@ -59,20 +60,24 @@ public final class SCLRecord extends StandardRecord { return buffer.toString(); } + @Override public void serialize(LittleEndianOutput out) { out.writeShort(field_1_numerator); out.writeShort(field_2_denominator); } + @Override protected int getDataSize() { return 2 + 2; } + @Override public short getSid() { return sid; } + @Override public Object clone() { SCLRecord rec = new SCLRecord(); @@ -81,11 +86,10 @@ public final class SCLRecord extends StandardRecord { return rec; } - - - /** * Get the numerator field for the SCL record. + * + * @return the numerator */ public short getNumerator() { @@ -94,6 +98,8 @@ public final class SCLRecord extends StandardRecord { /** * Set the numerator field for the SCL record. + * + * @param field_1_numerator the numerator */ public void setNumerator(short field_1_numerator) { @@ -102,6 +108,8 @@ public final class SCLRecord extends StandardRecord { /** * Get the denominator field for the SCL record. + * + * @return the denominator */ public short getDenominator() { @@ -110,6 +118,8 @@ public final class SCLRecord extends StandardRecord { /** * Set the denominator field for the SCL record. + * + * @param field_2_denominator the denominator */ public void setDenominator(short field_2_denominator) { diff --git a/src/java/org/apache/poi/hssf/record/SelectionRecord.java b/src/java/org/apache/poi/hssf/record/SelectionRecord.java index 3539ba57d5..12928b95f5 100644 --- a/src/java/org/apache/poi/hssf/record/SelectionRecord.java +++ b/src/java/org/apache/poi/hssf/record/SelectionRecord.java @@ -26,10 +26,7 @@ import org.apache.poi.util.LittleEndianOutput; * Description: shows the user's selection on the sheet * for write set num refs to 0

    * - * REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

    - * @author Andrew C. Oliver (acoliver at apache dot org) - * @author Jason Height (jheight at chariot dot net dot au) - * @author Glen Stampoultzis (glens at apache.org) + * REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) */ public final class SelectionRecord extends StandardRecord { public final static short sid = 0x001D; @@ -41,6 +38,9 @@ public final class SelectionRecord extends StandardRecord { /** * Creates a default selection record (cell A1, in pane ID 3) + * + * @param activeCellRow the active cells row index + * @param activeCellCol the active cells column index */ public SelectionRecord(int activeCellRow, int activeCellCol) { field_1_pane = 3; // pane id 3 is always present. see OOO sec 5.75 'PANE' @@ -67,6 +67,7 @@ public final class SelectionRecord extends StandardRecord { /** * set which window pane this is for + * @param pane the window pane */ public void setPane(byte pane) { field_1_pane = pane; @@ -127,6 +128,7 @@ public final class SelectionRecord extends StandardRecord { return field_4_active_cell_ref_index; } + @Override public String toString() { StringBuffer sb = new StringBuffer(); @@ -139,10 +141,12 @@ public final class SelectionRecord extends StandardRecord { sb.append("[/SELECTION]\n"); return sb.toString(); } + @Override protected int getDataSize() { return 9 // 1 byte + 4 shorts + CellRangeAddress8Bit.getEncodedSize(field_6_refs.length); } + @Override public void serialize(LittleEndianOutput out) { out.writeByte(getPane()); out.writeShort(getActiveCellRow()); @@ -150,15 +154,17 @@ public final class SelectionRecord extends StandardRecord { out.writeShort(getActiveCellRef()); int nRefs = field_6_refs.length; out.writeShort(nRefs); - for (int i = 0; i < field_6_refs.length; i++) { - field_6_refs[i].serialize(out); + for (CellRangeAddress8Bit field_6_ref : field_6_refs) { + field_6_ref.serialize(out); } } + @Override public short getSid() { return sid; } + @Override public Object clone() { SelectionRecord rec = new SelectionRecord(field_2_row_active_cell, field_3_col_active_cell); rec.field_1_pane = field_1_pane; diff --git a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java index 3506179724..b42f09b47f 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java @@ -66,8 +66,8 @@ public final class PageSettingsBlock extends RecordAggregate { @Override public void visitContainedRecords(RecordVisitor rv) { rv.visitRecord(_pls); - for (int i = 0; i < _plsContinues.length; i++) { - rv.visitRecord(_plsContinues[i]); + for (ContinueRecord _plsContinue : _plsContinues) { + rv.visitRecord(_plsContinue); } } } @@ -93,7 +93,7 @@ public final class PageSettingsBlock extends RecordAggregate { * The indicator of such records is a non-zero GUID, * see {@link org.apache.poi.hssf.record.HeaderFooterRecord#getGuid()} */ - private List _sviewHeaderFooters = new ArrayList(); + private final List _sviewHeaderFooters = new ArrayList(); private Record _printSize; public PageSettingsBlock(RecordStream rs) { @@ -120,6 +120,8 @@ public final class PageSettingsBlock extends RecordAggregate { } /** + * @param sid the record sid + * * @return true if the specified Record sid is one belonging to the * 'Page Settings Block'. */ @@ -205,8 +207,9 @@ public final class PageSettingsBlock extends RecordAggregate { case HeaderFooterRecord.sid: //there can be multiple HeaderFooterRecord records belonging to different sheet views HeaderFooterRecord hf = (HeaderFooterRecord)rs.getNext(); - if(hf.isCurrentSheet()) _headerFooter = hf; - else { + if(hf.isCurrentSheet()) { + _headerFooter = hf; + } else { _sviewHeaderFooters.add(hf); } break; @@ -242,6 +245,9 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Sets a page break at the indicated column * + * @param column the column to add page breaks to + * @param fromRow the starting row + * @param toRow the ending row */ public void setColumnBreak(short column, short fromRow, short toRow) { getColumnBreaksRecord().addBreak(column, fromRow, toRow); @@ -250,6 +256,7 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Removes a page break at the indicated column * + * @param column the column to check for page breaks */ public void removeColumnBreak(int column) { getColumnBreaksRecord().removeBreak(column); @@ -258,6 +265,7 @@ public final class PageSettingsBlock extends RecordAggregate { + @Override public void visitContainedRecords(RecordVisitor rv) { // Replicates record order from Excel 2007, though this is not critical @@ -481,8 +489,9 @@ public final class PageSettingsBlock extends RecordAggregate { int breakLocation = breakItem.main; boolean inStart = (breakLocation >= start); boolean inEnd = (breakLocation <= stop); - if(inStart && inEnd) + if(inStart && inEnd) { shiftedBreak.add(breakItem); + } } iterator = shiftedBreak.iterator(); @@ -496,7 +505,9 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Sets a page break at the indicated row - * @param row + * @param row the row + * @param fromCol the starting column + * @param toCol the ending column */ public void setRowBreak(int row, short fromCol, short toCol) { getRowBreaksRecord().addBreak((short)row, fromCol, toCol); @@ -504,17 +515,20 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Removes a page break at the indicated row - * @param row + * @param row the row */ public void removeRowBreak(int row) { - if (getRowBreaksRecord().getBreaks().length < 1) + if (getRowBreaksRecord().getBreaks().length < 1) { throw new IllegalArgumentException("Sheet does not define any row breaks"); + } getRowBreaksRecord().removeBreak((short)row); } /** * Queries if the specified row has a page break - * @param row + * + * @param row the row to check for + * * @return true if the specified row has a page break */ public boolean isRowBroken(int row) { @@ -524,6 +538,8 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Queries if the specified column has a page break + * + * @param column the column to check for * * @return true if the specified column has a page break */ @@ -533,9 +549,9 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Shifts the horizontal page breaks for the indicated count - * @param startingRow - * @param endingRow - * @param count + * @param startingRow the starting row + * @param endingRow the ending row + * @param count the number of rows to shift by */ public void shiftRowBreaks(int startingRow, int endingRow, int count) { shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count); @@ -543,9 +559,9 @@ public final class PageSettingsBlock extends RecordAggregate { /** * Shifts the vertical page breaks for the indicated count - * @param startingCol - * @param endingCol - * @param count + * @param startingCol the starting column + * @param endingCol the ending column + * @param count the number of columns to shift by */ public void shiftColumnBreaks(short startingCol, short endingCol, short count) { shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count); @@ -590,6 +606,8 @@ public final class PageSettingsBlock extends RecordAggregate { /** * HEADERFOOTER is new in 2007. Some apps seem to have scattered this record long after * the {@link PageSettingsBlock} where it belongs. + * + * @param rec the HeaderFooterRecord to set */ public void addLateHeaderFooter(HeaderFooterRecord rec) { if (_headerFooter != null) { @@ -604,10 +622,11 @@ public final class PageSettingsBlock extends RecordAggregate { /** * This method reads PageSettingsBlock records from the supplied RecordStream until the first * non-PageSettingsBlock record is encountered. As each record is read, it is incorporated - * into this PageSettingsBlock. - *

    + * into this PageSettingsBlock.

    + * * The latest Excel version seems to write the PageSettingsBlock uninterrupted. However there * are several examples (that Excel reads OK) where these records are not written together: + * *

      *
    • HEADER_FOOTER(0x089C) after WINDOW2 - This record is new in 2007. Some apps * seem to have scattered this record long after the PageSettingsBlock where it belongs @@ -616,16 +635,18 @@ public final class PageSettingsBlock extends RecordAggregate { * This happens in the test sample file "NoGutsRecords.xls" and "WORKBOOK_in_capitals.xls"
    • *
    • Margins after DIMENSION - All of PSB should be before DIMENSION. (Bug-47199)
    • *
    + * * These were probably written by other applications (or earlier versions of Excel). It was * decided to not write specific code for detecting each of these cases. POI now tolerates * PageSettingsBlock records scattered all over the sheet record stream, and in any order, but - * does not allow duplicates of any of those records. + * does not allow duplicates of any of those records.

    * - *

    * Note - when POI writes out this PageSettingsBlock, the records will always be written * in one consolidated block (in the standard ordering) regardless of how scattered the records * were when they were originally read. * + * @param rs the RecordStream to read from + * * @throws RecordFormatException if any PSB record encountered has the same type (sid) as * a record that is already part of this PageSettingsBlock */ @@ -665,6 +686,7 @@ public final class PageSettingsBlock extends RecordAggregate { if (rb instanceof CustomViewSettingsRecordAggregate) { final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb; cv.visitContainedRecords(new RecordVisitor() { + @Override public void visitRecord(Record r) { if (r.getSid() == UserSViewBegin.sid) { String guid = HexDump.toHex(((UserSViewBegin) r).getGuid()); -- 2.39.5