Modified: poi/trunk/src/java/org/apache/poi/hssf/record/LeftMarginRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/LeftMarginRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/LeftMarginRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/LeftMarginRecord.java Sun Dec 22 21:44:45 2019 @@ -18,18 +18,23 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** * Record for the left margin. */ -public final class LeftMarginRecord extends StandardRecord implements Margin, Cloneable { - public final static short sid = 0x0026; +public final class LeftMarginRecord extends StandardRecord implements Margin { + public static final short sid = 0x0026; private double field_1_margin; - public LeftMarginRecord() { } + public LeftMarginRecord() {} - public LeftMarginRecord(RecordInputStream in) - { + public LeftMarginRecord(LeftMarginRecord other) { + super(other); + field_1_margin = other.field_1_margin; + } + + public LeftMarginRecord(RecordInputStream in) { field_1_margin = in.readDouble(); } @@ -70,9 +75,15 @@ public final class LeftMarginRecord exte } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public LeftMarginRecord clone() { - LeftMarginRecord rec = new LeftMarginRecord(); - rec.field_1_margin = this.field_1_margin; - return rec; + return copy(); + } + + @Override + public LeftMarginRecord copy() { + return new LeftMarginRecord(this); } -} \ No newline at end of file +} \ No newline at end of file
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MMSRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MMSRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/MMSRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/MMSRecord.java Sun Dec 22 21:44:45 2019 @@ -15,38 +15,36 @@ 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.LittleEndianOutput; /** - * Title: MMS Record<P> - * Description: defines how many add menu and del menu options are stored - * in the file. Should always be set to 0 for HSSF workbooks<P> - * REFERENCE: PG 328 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> - * @author Andrew C. Oliver (acoliver at apache dot org) + * defines how many add menu and del menu options are stored in the file. + * Should always be set to 0 for HSSF workbooks. + * * @version 2.0-pre */ -public final class MMSRecord - extends StandardRecord -{ - public final static short sid = 0xC1; - private byte field_1_addMenuCount; // = 0; - private byte field_2_delMenuCount; // = 0; +public final class MMSRecord extends StandardRecord { + public static final short sid = 0xC1; + private byte field_1_addMenuCount; + private byte field_2_delMenuCount; - public MMSRecord() - { + public MMSRecord() {} + + public MMSRecord(MMSRecord other) { + field_1_addMenuCount = other.field_1_addMenuCount; + field_2_delMenuCount = other.field_2_delMenuCount; } - public MMSRecord(RecordInputStream in) - { + public MMSRecord(RecordInputStream in) { if (in.remaining()==0) { return; } - + field_1_addMenuCount = in.readByte(); field_2_delMenuCount = in.readByte(); } @@ -117,4 +115,9 @@ public final class MMSRecord { return sid; } + + @Override + public MMSRecord copy() { + return new MMSRecord(this); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java Sun Dec 22 21:44:45 2019 @@ -17,22 +17,33 @@ package org.apache.poi.hssf.record; +import java.util.stream.Stream; + import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Merged Cells Record (0x00E5)<p> - * - * Description: Optional record defining a square area of cells to "merged" into one cell. + * Optional record defining a square area of cells to "merged" into one cell. */ -public final class MergeCellsRecord extends StandardRecord implements Cloneable { - public final static short sid = 0x00E5; - /** sometimes the regions array is shared with other MergedCellsRecords */ +public final class MergeCellsRecord extends StandardRecord { + public static final short sid = 0x00E5; + + /** sometimes the regions array is shared with other MergedCellsRecords */ private final CellRangeAddress[] _regions; private final int _startIndex; private final int _numberOfRegions; + public MergeCellsRecord(MergeCellsRecord other) { + super(other); + _regions = (other._regions == null) ? null + : Stream.of(other._regions).map(CellRangeAddress::copy).toArray(CellRangeAddress[]::new); + _startIndex = other._startIndex; + _numberOfRegions = other._numberOfRegions; + } + + public MergeCellsRecord(CellRangeAddress[] regions, int startIndex, int numberOfRegions) { _regions = regions; _startIndex = startIndex; @@ -63,7 +74,7 @@ public final class MergeCellsRecord exte /** * @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) { @@ -107,12 +118,15 @@ public final class MergeCellsRecord exte } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public MergeCellsRecord clone() { - int nRegions = _numberOfRegions; - CellRangeAddress[] clonedRegions = new CellRangeAddress[nRegions]; - for (int i = 0; i < clonedRegions.length; i++) { - clonedRegions[i] = _regions[_startIndex + i].copy(); - } - return new MergeCellsRecord(clonedRegions, 0, nRegions); + return copy(); + } + + @Override + public MergeCellsRecord copy() { + return new MergeCellsRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java Sun Dec 22 21:44:45 2019 @@ -18,17 +18,15 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Multiple Blank cell record(0x00BE)<p> - * Description: Represents a set of columns in a row with no value but with styling.<p> + * Represents a set of columns in a row with no value but with styling. * - * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) - * * @see BlankRecord */ public final class MulBlankRecord extends StandardRecord { - public final static short sid = 0x00BE; + public static final short sid = 0x00BE; private final int _row; private final int _firstCol; @@ -55,7 +53,7 @@ public final class MulBlankRecord extend public int getFirstColumn() { return _firstCol; } - + /** * @return ending column (last cell this holds in the row). Zero based */ @@ -122,8 +120,8 @@ public final class MulBlankRecord extend out.writeShort(_row); out.writeShort(_firstCol); int nItems = _xfs.length; - for (int i = 0; i < nItems; i++) { - out.writeShort(_xfs[i]); + for (short xf : _xfs) { + out.writeShort(xf); } out.writeShort(_lastCol); } @@ -134,7 +132,15 @@ public final class MulBlankRecord extend } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public MulBlankRecord clone() { + return copy(); + } + + @Override + public MulBlankRecord copy() { // immutable - so OK to return this return this; } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/MulRKRecord.java Sun Dec 22 21:44:45 2019 @@ -23,18 +23,15 @@ import org.apache.poi.util.LittleEndianO import org.apache.poi.util.RecordFormatException; /** - * MULRK (0x00BD)<p> - * * Used to store multiple RK numbers on a row. 1 MulRk = Multiple Cell values. - * HSSF just converts this into multiple NUMBER records. READ-ONLY SUPPORT!<P> - * REFERENCE: PG 330 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) - * + * HSSF just converts this into multiple NUMBER records. READ-ONLY SUPPORT! + * * @since 2.0-pre */ public final class MulRKRecord extends StandardRecord { - public final static short sid = 0x00BD; + public static final short sid = 0x00BD; - private final int field_1_row; + 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; @@ -69,9 +66,9 @@ public final class MulRKRecord extends S /** * 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) { @@ -80,9 +77,9 @@ public final class MulRKRecord extends S /** * 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) { @@ -151,4 +148,10 @@ public final class MulRKRecord extends S return retval; } } + + @Override + public MulRKRecord copy() { + // immutable - so OK to return this + return this; + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java Sun Dec 22 21:44:45 2019 @@ -18,145 +18,154 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.HexDump; -import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.StringUtil; /** - * Title: NAMECMT Record (0x0894)<p> - * - * Description: Defines a comment associated with a specified name. + * Defines a comment associated with a specified name. */ public final class NameCommentRecord extends StandardRecord { - public final static short sid = 0x0894; + public static final short sid = 0x0894; - private final short field_1_record_type; - private final short field_2_frt_cell_ref_flag; - private final long field_3_reserved; - //private short field_4_name_length; - //private short field_5_comment_length; - private String field_6_name_text; - private String field_7_comment_text; - - public NameCommentRecord(final String name, final String comment) { - field_1_record_type = 0; - field_2_frt_cell_ref_flag = 0; - field_3_reserved = 0; - field_6_name_text = name; - field_7_comment_text = comment; - } - - @Override - public void serialize(final LittleEndianOutput out) { - final int field_4_name_length = field_6_name_text.length(); - final int field_5_comment_length = field_7_comment_text.length(); - - out.writeShort(field_1_record_type); - out.writeShort(field_2_frt_cell_ref_flag); - out.writeLong(field_3_reserved); - out.writeShort(field_4_name_length); - out.writeShort(field_5_comment_length); - - boolean isNameMultiByte = StringUtil.hasMultibyte(field_6_name_text); - out.writeByte(isNameMultiByte ? 1 : 0); - if (isNameMultiByte) { - StringUtil.putUnicodeLE(field_6_name_text, out); - } else { - StringUtil.putCompressedUnicode(field_6_name_text, out); - } - boolean isCommentMultiByte = StringUtil.hasMultibyte(field_7_comment_text); - out.writeByte(isCommentMultiByte ? 1 : 0); - if (isCommentMultiByte) { - StringUtil.putUnicodeLE(field_7_comment_text, out); - } else { - StringUtil.putCompressedUnicode(field_7_comment_text, out); - } - } - - @Override - protected int getDataSize() { - return 18 // 4 shorts + 1 long + 2 spurious 'nul's - + (StringUtil.hasMultibyte(field_6_name_text) ? field_6_name_text.length()*2 : field_6_name_text.length()) - + (StringUtil.hasMultibyte(field_7_comment_text) ? field_7_comment_text.length()*2 : field_7_comment_text.length()); - } - - /** - * @param ris the RecordInputstream to read the record from - */ - public NameCommentRecord(final RecordInputStream ris) { - field_1_record_type = ris.readShort(); - field_2_frt_cell_ref_flag = ris.readShort(); - field_3_reserved = ris.readLong(); - final int field_4_name_length = ris.readShort(); - final int field_5_comment_length = ris.readShort(); - - if (ris.readByte() == 0) { - field_6_name_text = StringUtil.readCompressedUnicode(ris, field_4_name_length); - } else { - field_6_name_text = StringUtil.readUnicodeLE(ris, field_4_name_length); - } - if (ris.readByte() == 0) { - field_7_comment_text = StringUtil.readCompressedUnicode(ris, field_5_comment_length); - } else { - field_7_comment_text = StringUtil.readUnicodeLE(ris, field_5_comment_length); - } - } - - /** - * return the non static version of the id for this record. - */ - @Override - public short getSid() { - return sid; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - - sb.append("[NAMECMT]\n"); - sb.append(" .record type = ").append(HexDump.shortToHex(field_1_record_type)).append("\n"); - sb.append(" .frt cell ref flag = ").append(HexDump.byteToHex(field_2_frt_cell_ref_flag)).append("\n"); - sb.append(" .reserved = ").append(field_3_reserved).append("\n"); - sb.append(" .name length = ").append(field_6_name_text.length()).append("\n"); - sb.append(" .comment length = ").append(field_7_comment_text.length()).append("\n"); - sb.append(" .name = ").append(field_6_name_text).append("\n"); - sb.append(" .comment = ").append(field_7_comment_text).append("\n"); - sb.append("[/NAMECMT]\n"); - - return sb.toString(); - } - - /** - * @return the name of the NameRecord to which this comment applies. - */ - public String getNameText() { - return field_6_name_text; - } - - /** - * 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; - } - - /** - * @return the text of the comment. - */ - public String getCommentText() { - return field_7_comment_text; - } - - public void setCommentText(String comment) { - field_7_comment_text = comment; - } - - public short getRecordType() { - return field_1_record_type; - } + private final short field_1_record_type; + private final short field_2_frt_cell_ref_flag; + private final long field_3_reserved; + //private short field_4_name_length; + //private short field_5_comment_length; + private String field_6_name_text; + private String field_7_comment_text; + + public NameCommentRecord(NameCommentRecord other) { + field_1_record_type = other.field_1_record_type; + field_2_frt_cell_ref_flag = other.field_2_frt_cell_ref_flag; + field_3_reserved = other.field_3_reserved; + field_6_name_text = other.field_6_name_text; + field_7_comment_text = other.field_7_comment_text; + } + + public NameCommentRecord(final String name, final String comment) { + field_1_record_type = 0; + field_2_frt_cell_ref_flag = 0; + field_3_reserved = 0; + field_6_name_text = name; + field_7_comment_text = comment; + } + + /** + * @param ris the RecordInputstream to read the record from + */ + public NameCommentRecord(final RecordInputStream ris) { + field_1_record_type = ris.readShort(); + field_2_frt_cell_ref_flag = ris.readShort(); + field_3_reserved = ris.readLong(); + final int field_4_name_length = ris.readShort(); + final int field_5_comment_length = ris.readShort(); + + if (ris.readByte() == 0) { + field_6_name_text = StringUtil.readCompressedUnicode(ris, field_4_name_length); + } else { + field_6_name_text = StringUtil.readUnicodeLE(ris, field_4_name_length); + } + if (ris.readByte() == 0) { + field_7_comment_text = StringUtil.readCompressedUnicode(ris, field_5_comment_length); + } else { + field_7_comment_text = StringUtil.readUnicodeLE(ris, field_5_comment_length); + } + } + + @Override + public void serialize(final LittleEndianOutput out) { + final int field_4_name_length = field_6_name_text.length(); + final int field_5_comment_length = field_7_comment_text.length(); + + out.writeShort(field_1_record_type); + out.writeShort(field_2_frt_cell_ref_flag); + out.writeLong(field_3_reserved); + out.writeShort(field_4_name_length); + out.writeShort(field_5_comment_length); + + boolean isNameMultiByte = StringUtil.hasMultibyte(field_6_name_text); + out.writeByte(isNameMultiByte ? 1 : 0); + if (isNameMultiByte) { + StringUtil.putUnicodeLE(field_6_name_text, out); + } else { + StringUtil.putCompressedUnicode(field_6_name_text, out); + } + boolean isCommentMultiByte = StringUtil.hasMultibyte(field_7_comment_text); + out.writeByte(isCommentMultiByte ? 1 : 0); + if (isCommentMultiByte) { + StringUtil.putUnicodeLE(field_7_comment_text, out); + } else { + StringUtil.putCompressedUnicode(field_7_comment_text, out); + } + } + @Override + protected int getDataSize() { + return 18 // 4 shorts + 1 long + 2 spurious 'nul's + + (StringUtil.hasMultibyte(field_6_name_text) ? field_6_name_text.length() * 2 : field_6_name_text.length()) + + (StringUtil.hasMultibyte(field_7_comment_text) ? field_7_comment_text.length() * 2 : field_7_comment_text.length()); + } + + /** + * return the non static version of the id for this record. + */ + @Override + public short getSid() { + return sid; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + + sb.append("[NAMECMT]\n"); + sb.append(" .record type = ").append(HexDump.shortToHex(field_1_record_type)).append("\n"); + sb.append(" .frt cell ref flag = ").append(HexDump.byteToHex(field_2_frt_cell_ref_flag)).append("\n"); + sb.append(" .reserved = ").append(field_3_reserved).append("\n"); + sb.append(" .name length = ").append(field_6_name_text.length()).append("\n"); + sb.append(" .comment length = ").append(field_7_comment_text.length()).append("\n"); + sb.append(" .name = ").append(field_6_name_text).append("\n"); + sb.append(" .comment = ").append(field_7_comment_text).append("\n"); + sb.append("[/NAMECMT]\n"); + + return sb.toString(); + } + + /** + * @return the name of the NameRecord to which this comment applies. + */ + public String getNameText() { + return field_6_name_text; + } + + /** + * 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; + } + + /** + * @return the text of the comment. + */ + public String getCommentText() { + return field_7_comment_text; + } + + public void setCommentText(String comment) { + field_7_comment_text = comment; + } + + public short getRecordType() { + return field_1_record_type; + } + + @Override + public NameCommentRecord copy() { + return new NameCommentRecord(this); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java Sun Dec 22 21:44:45 2019 @@ -19,44 +19,46 @@ package org.apache.poi.hssf.record; import org.apache.poi.hssf.record.cont.ContinuableRecord; import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; +import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ref3DPtg; -import org.apache.poi.ss.formula.Formula; -import org.apache.poi.util.*; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.LittleEndianByteArrayInputStream; +import org.apache.poi.util.LittleEndianInput; +import org.apache.poi.util.StringUtil; /** - * Title: DEFINEDNAME Record (0x0018)<p> - * Description: Defines a named range within a workbook. + * Defines a named range within a workbook. */ public final class NameRecord extends ContinuableRecord { - public final static short sid = 0x0018; + public static final short sid = 0x0018; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_CONSOLIDATE_AREA = 1; + public static final byte BUILTIN_CONSOLIDATE_AREA = 1; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_AUTO_OPEN = 2; + public static final byte BUILTIN_AUTO_OPEN = 2; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_AUTO_CLOSE = 3; + public static final byte BUILTIN_AUTO_CLOSE = 3; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_DATABASE = 4; + public static final byte BUILTIN_DATABASE = 4; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_CRITERIA = 5; + public static final byte BUILTIN_CRITERIA = 5; - public final static byte BUILTIN_PRINT_AREA = 6; - public final static byte BUILTIN_PRINT_TITLE = 7; + public static final byte BUILTIN_PRINT_AREA = 6; + public static final byte BUILTIN_PRINT_TITLE = 7; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_RECORDER = 8; + public static final byte BUILTIN_RECORDER = 8; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_DATA_FORM = 9; + public static final byte BUILTIN_DATA_FORM = 9; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_AUTO_ACTIVATE = 10; + public static final byte BUILTIN_AUTO_ACTIVATE = 10; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_AUTO_DEACTIVATE = 11; + public static final byte BUILTIN_AUTO_DEACTIVATE = 11; /**Included for completeness sake, not implemented */ - public final static byte BUILTIN_SHEET_TITLE = 12; + public static final byte BUILTIN_SHEET_TITLE = 12; - public final static byte BUILTIN_FILTER_DB = 13; + public static final byte BUILTIN_FILTER_DB = 13; private static final class Option { public static final int OPT_HIDDEN_NAME = 0x0001; @@ -98,10 +100,26 @@ public final class NameRecord extends Co field_17_status_bar_text = ""; } + public NameRecord(NameRecord other) { + super(other); + field_1_option_flag = other.field_1_option_flag; + field_2_keyboard_shortcut = other.field_2_keyboard_shortcut; + field_5_externSheetIndex_plus1 = other.field_5_externSheetIndex_plus1; + field_6_sheetNumber = other.field_6_sheetNumber; + field_11_nameIsMultibyte = other.field_11_nameIsMultibyte; + field_12_built_in_code = other.field_12_built_in_code; + field_12_name_text = other.field_12_name_text; + field_13_name_definition = other.field_13_name_definition; + field_14_custom_menu_text = other.field_14_custom_menu_text; + field_15_description_text = other.field_15_description_text; + field_16_help_topic_text = other.field_16_help_topic_text; + field_17_status_bar_text = other.field_17_status_bar_text; + } + /** * 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 + * @param sheetNumber the sheet which the name applies to */ public NameRecord(byte builtin, int sheetNumber) { @@ -276,7 +294,7 @@ public final class NameRecord extends Co /** * 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() @@ -590,4 +608,9 @@ public final class NameRecord extends Co return "Unknown"; } + + @Override + public NameRecord copy() { + return new NameRecord(this); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NoteRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NoteRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/NoteRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/NoteRecord.java Sun Dec 22 21:44:45 2019 @@ -18,27 +18,28 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; /** * NOTE: Comment Associated with a Cell (0x001C) */ -public final class NoteRecord extends StandardRecord implements Cloneable { - public final static short sid = 0x001C; +public final class NoteRecord extends StandardRecord { + public static final short sid = 0x001C; public static final NoteRecord[] EMPTY_ARRAY = { }; /** * Flag indicating that the comment is hidden (default) */ - public final static short NOTE_HIDDEN = 0x0; + public static final short NOTE_HIDDEN = 0x0; /** * Flag indicating that the comment is visible */ - public final static short NOTE_VISIBLE = 0x2; + public static final short NOTE_VISIBLE = 0x2; - private static final Byte DEFAULT_PADDING = Byte.valueOf((byte)0); + private static final Byte DEFAULT_PADDING = (byte) 0; private int field_1_row; private int field_2_col; @@ -46,6 +47,7 @@ public final class NoteRecord extends St private int field_4_shapeid; private boolean field_5_hasMultibyte; private String field_6_author; + /** * Saves padding byte value to reduce delta during round-trip serialization.<br> * @@ -64,6 +66,17 @@ public final class NoteRecord extends St field_7_padding = DEFAULT_PADDING; // seems to be always present regardless of author text } + public NoteRecord(NoteRecord other) { + super(other); + field_1_row = other.field_1_row; + field_2_col = other.field_2_col; + field_3_flags = other.field_3_flags; + field_4_shapeid = other.field_4_shapeid; + field_5_hasMultibyte = other.field_5_hasMultibyte; + field_6_author = other.field_6_author; + field_7_padding = other.field_7_padding; + } + /** * @return id of this record. */ @@ -73,7 +86,7 @@ public final class NoteRecord extends St /** * Read the record data from the supplied <code>RecordInputStream</code> - * + * * @param in the RecordInputStream to read from */ public NoteRecord(RecordInputStream in) { @@ -194,10 +207,10 @@ public final class NoteRecord extends St public void setFlags(short flags) { field_3_flags = flags; } - + /** * For unit testing only! - * + * * @return true, if author element uses multi byte */ protected boolean authorIsMultibyte() { @@ -206,7 +219,7 @@ public final class NoteRecord extends St /** * Object id for OBJ record that contains the comment - * + * * @return the Object id for OBJ record that contains the comment */ public int getShapeId() { @@ -215,7 +228,7 @@ public final class NoteRecord extends St /** * 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) { @@ -242,13 +255,15 @@ public final class NoteRecord extends St } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public NoteRecord clone() { - NoteRecord rec = new NoteRecord(); - rec.field_1_row = field_1_row; - rec.field_2_col = field_2_col; - rec.field_3_flags = field_3_flags; - rec.field_4_shapeid = field_4_shapeid; - rec.field_6_author = field_6_author; - return rec; + return copy(); + } + + @Override + public NoteRecord copy() { + return new NoteRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/NoteStructureSubRecord.java Sun Dec 22 21:44:45 2019 @@ -22,6 +22,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.RecordFormatException; +import org.apache.poi.util.Removal; /** * ftNts (0x000D)<p> @@ -29,25 +30,30 @@ import org.apache.poi.util.RecordFormatE * * The docs say nothing about it. The length of this record is always 26 bytes. */ -public final class NoteStructureSubRecord extends SubRecord implements Cloneable { - public final static short sid = 0x0D; +public final class NoteStructureSubRecord extends SubRecord { + public static final short sid = 0x0D; private static final int ENCODED_SIZE = 22; - private byte[] reserved; + private final byte[] reserved; /** * Construct a new <code>NoteStructureSubRecord</code> and * fill its data with the default values */ - public NoteStructureSubRecord() - { + public NoteStructureSubRecord() { //all we know is that the the length of <code>NoteStructureSubRecord</code> is always 22 bytes reserved = new byte[ENCODED_SIZE]; } + public NoteStructureSubRecord(NoteStructureSubRecord other) { + super(other); + reserved = other.reserved.clone(); + } + + /** * Read the record data from the supplied <code>RecordInputStream</code> - * + * * @param in the input to read from * @param size the provided size - must be 22 */ @@ -103,12 +109,16 @@ public final class NoteStructureSubRecor } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public NoteStructureSubRecord clone() { - NoteStructureSubRecord rec = new NoteStructureSubRecord(); - byte[] recdata = new byte[reserved.length]; - System.arraycopy(reserved, 0, recdata, 0, recdata.length); - rec.reserved = recdata; - return rec; + return copy(); + } + + @Override + public NoteStructureSubRecord copy() { + return new NoteStructureSubRecord(this); } } 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=1871911&r1=1871910&r2=1871911&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 Sun Dec 22 21:44:45 2019 @@ -19,20 +19,22 @@ package org.apache.poi.hssf.record; import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * 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) + * NUMBER (0x0203) Contains a numeric cell value. */ -public final class NumberRecord extends CellRecord implements Cloneable { +public final class NumberRecord extends CellRecord { public static final short sid = 0x0203; + private double field_4_value; /** Creates new NumberRecord */ - public NumberRecord() { - // fields uninitialised + public NumberRecord() {} + + public NumberRecord(NumberRecord other) { + super(other); + field_4_value = other.field_4_value; } /** @@ -87,10 +89,15 @@ public final class NumberRecord extends } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public NumberRecord clone() { - NumberRecord rec = new NumberRecord(); - copyBaseFields(rec); - rec.field_4_value = field_4_value; - return rec; + return copy(); + } + + @Override + public NumberRecord copy() { + return new NumberRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ObjRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ObjRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ObjRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ObjRecord.java Sun Dec 22 21:44:45 2019 @@ -26,20 +26,23 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.RecordFormatException; +import org.apache.poi.util.Removal; /** * OBJRECORD (0x005D)<p> * * The obj record is used to hold various graphic objects and controls. */ -public final class ObjRecord extends Record implements Cloneable { - public final static short sid = 0x005D; +public final class ObjRecord extends Record { + public static final short sid = 0x005D; private static final int NORMAL_PAD_ALIGNMENT = 2; private static int MAX_PAD_ALIGNMENT = 4; - private List<SubRecord> subrecords; - /** used when POI has no idea what is going on */ + private final List<SubRecord> subrecords = new ArrayList<>(); + /** + * used when POI has no idea what is going on + */ private final byte[] _uninterpretedData; /** * Excel seems to tolerate padding to quad or double byte length @@ -51,11 +54,16 @@ public final class ObjRecord extends Rec public ObjRecord() { - subrecords = new ArrayList<>(2); // TODO - ensure 2 sub-records (ftCmo 15h, and ftEnd 00h) are always created _uninterpretedData = null; } + public ObjRecord(ObjRecord other) { + other.subrecords.stream().map(SubRecord::copy).forEach(subrecords::add); + _uninterpretedData = (other._uninterpretedData == null) ? null : other._uninterpretedData.clone(); + _isPaddedToQuadByteMultiple = other._isPaddedToQuadByteMultiple; + } + public ObjRecord(RecordInputStream in) { // TODO - problems with OBJ sub-records stream // MS spec says first sub-record is always CommonObjectDataSubRecord, @@ -72,7 +80,6 @@ public final class ObjRecord extends Rec // Excel tolerates the funny ObjRecord, and replaces it with a corrected version // The exact logic/reasoning is not yet understood _uninterpretedData = subRecordData; - subrecords = null; return; } @@ -84,7 +91,6 @@ public final class ObjRecord extends Rec } */ - subrecords = new ArrayList<>(); LittleEndianByteArrayInputStream subRecStream = new LittleEndianByteArrayInputStream(subRecordData); CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)SubRecord.createSubRecord(subRecStream, 0); subrecords.add(cmo); @@ -138,10 +144,8 @@ public final class ObjRecord extends Rec StringBuilder sb = new StringBuilder(); sb.append("[OBJ]\n"); - if(subrecords != null) { // there are special cases where this can be, see comments in constructor above - for (final SubRecord record : subrecords) { - sb.append("SUBRECORD: ").append(record); - } + for (final SubRecord record : subrecords) { + sb.append("SUBRECORD: ").append(record); } sb.append("[/OBJ]\n"); return sb.toString(); @@ -221,12 +225,15 @@ public final class ObjRecord extends Rec } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public ObjRecord clone() { - ObjRecord rec = new ObjRecord(); + return copy(); + } - for (SubRecord record : subrecords) { - rec.addSubRecord(record.clone()); - } - return rec; + @Override + public ObjRecord copy() { + return new ObjRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ObjectProtectRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ObjectProtectRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ObjectProtectRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ObjectProtectRecord.java Sun Dec 22 21:44:45 2019 @@ -15,32 +15,32 @@ 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.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Object Protect Record<P> - * Description: Protect embedded object with the lamest "security" ever invented. - * This record tells "I want to protect my objects" with lame security. It - * appears in conjunction with the PASSWORD and PROTECT records as well as its - * scenario protect cousin.<P> - * REFERENCE: PG 368 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> - * @author Andrew C. Oliver (acoliver at apache dot org) + * Protect embedded object with the lamest "security" ever invented. + * This record tells "I want to protect my objects" with lame security. + * It appears in conjunction with the PASSWORD and PROTECT records as well as its scenario protect cousin. */ -public final class ObjectProtectRecord extends StandardRecord implements Cloneable { - public final static short sid = 0x63; - private short field_1_protect; +public final class ObjectProtectRecord extends StandardRecord { + public static final short sid = 0x63; - public ObjectProtectRecord() - { + private short field_1_protect; + + public ObjectProtectRecord() {} + + public ObjectProtectRecord(ObjectProtectRecord other) { + super(other); + field_1_protect = other.field_1_protect; } - public ObjectProtectRecord(RecordInputStream in) - { + public ObjectProtectRecord(RecordInputStream in) { field_1_protect = in.readShort(); } @@ -51,14 +51,7 @@ public final class ObjectProtectRecord e public void setProtect(boolean protect) { - if (protect) - { - field_1_protect = 1; - } - else - { - field_1_protect = 0; - } + field_1_protect = (short) (protect ? 1 : 0); } /** @@ -96,9 +89,15 @@ public final class ObjectProtectRecord e } @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") public ObjectProtectRecord clone() { - ObjectProtectRecord rec = new ObjectProtectRecord(); - rec.field_1_protect = field_1_protect; - return rec; + return copy(); + } + + @Override + public ObjectProtectRecord copy() { + return new ObjectProtectRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java Sun Dec 22 21:44:45 2019 @@ -17,7 +17,6 @@ package org.apache.poi.hssf.record; -import org.apache.poi.hssf.record.FormulaRecord.SpecialCachedValue; import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.CellType; @@ -27,12 +26,12 @@ import org.apache.poi.ss.usermodel.CellT * encoded form, along with the value if a number */ public final class OldFormulaRecord extends OldCellRecord { - public final static short biff2_sid = 0x0006; - public final static short biff3_sid = 0x0206; - public final static short biff4_sid = 0x0406; - public final static short biff5_sid = 0x0006; + public static final short biff2_sid = 0x0006; + public static final short biff3_sid = 0x0206; + public static final short biff4_sid = 0x0406; + public static final short biff5_sid = 0x0006; - private SpecialCachedValue specialCachedValue; + private FormulaSpecialCachedValue specialCachedValue; private double field_4_value; private short field_5_options; private Formula field_6_parsed_expr; @@ -44,7 +43,7 @@ public final class OldFormulaRecord exte field_4_value = ris.readDouble(); } else { long valueLongBits = ris.readLong(); - specialCachedValue = SpecialCachedValue.create(valueLongBits); + specialCachedValue = FormulaSpecialCachedValue.create(valueLongBits); if (specialCachedValue == null) { field_4_value = Double.longBitsToDouble(valueLongBits); } @@ -67,14 +66,14 @@ public final class OldFormulaRecord exte } return specialCachedValue.getValueType(); } - + public boolean getCachedBooleanValue() { return specialCachedValue.getBooleanValue(); } public int getCachedErrorValue() { return specialCachedValue.getErrorValue(); } - + /** * get the calculated value of the formula * Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldLabelRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldLabelRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/OldLabelRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/OldLabelRecord.java Sun Dec 22 21:44:45 2019 @@ -24,17 +24,17 @@ import org.apache.poi.util.POILogger; import org.apache.poi.util.RecordFormatException; /** - * Biff2 - Biff 4 Label Record (0x0004 / 0x0204) - read only support for + * Biff2 - Biff 4 Label Record (0x0004 / 0x0204) - read only support for * strings stored directly in the cell, from the older file formats that * didn't use {@link LabelSSTRecord} */ public final class OldLabelRecord extends OldCellRecord { - private final static POILogger logger = POILogFactory.getLogger(OldLabelRecord.class); + private static final POILogger logger = POILogFactory.getLogger(OldLabelRecord.class); //arbitrarily set, may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - public final static short biff2_sid = 0x0004; - public final static short biff345_sid = 0x0204; + public static final short biff2_sid = 0x0004; + public static final short biff345_sid = 0x0204; private short field_4_string_len; private final byte[] field_5_bytes; @@ -68,7 +68,7 @@ public final class OldLabelRecord extend public void setCodePage(CodepageRecord codepage) { this.codepage = codepage; } - + /** * get the number of characters this string contains * @return number of characters @@ -80,7 +80,7 @@ public final class OldLabelRecord extend /** * Get the String of the cell - * + * * @return the String of the cell */ public String getValue() @@ -90,7 +90,7 @@ public final class OldLabelRecord extend /** * Not supported - * + * * @param offset not supported * @param data not supported * @return not supported @@ -98,7 +98,7 @@ public final class OldLabelRecord extend 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"); } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldSheetRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldSheetRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/OldSheetRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/OldSheetRecord.java Sun Dec 22 21:44:45 2019 @@ -31,7 +31,7 @@ public final class OldSheetRecord { //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - public final static short sid = 0x0085; + public static final short sid = 0x0085; private int field_1_position_of_BOF; private int field_2_visibility; Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldStringRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldStringRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/OldStringRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/OldStringRecord.java Sun Dec 22 21:44:45 2019 @@ -25,7 +25,7 @@ import org.apache.poi.util.IOUtils; /** - * Biff2 - Biff 4 Label Record (0x0007 / 0x0207) - read only support for + * Biff2 - Biff 4 Label Record (0x0007 / 0x0207) - read only support for * formula string results. */ public final class OldStringRecord { @@ -33,8 +33,8 @@ public final class OldStringRecord { //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - public final static short biff2_sid = 0x0007; - public final static short biff345_sid = 0x0207; + public static final short biff2_sid = 0x0007; + public static final short biff345_sid = 0x0207; private short sid; private short field_1_string_len; @@ -46,7 +46,7 @@ public final class OldStringRecord { */ public OldStringRecord(RecordInputStream in) { sid = in.getSid(); - + if (in.getSid() == biff2_sid) { field_1_string_len = (short)in.readUByte(); } else { @@ -65,7 +65,7 @@ public final class OldStringRecord { public short getSid() { return sid; } - + public void setCodePage(CodepageRecord codepage) { this.codepage = codepage; } @@ -77,7 +77,7 @@ public final class OldStringRecord { { return getString(field_2_bytes, codepage); } - + protected static String getString(byte[] data, CodepageRecord codepage) { int cp = Property.DEFAULT_CODEPAGE; if (codepage != null) { Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PageBreakRecord.java Sun Dec 22 21:44:45 2019 @@ -20,27 +20,25 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import org.apache.poi.util.LittleEndianOutput; /** - * <p>Record that contains the functionality page breaks (horizontal and vertical)</p> + * Record that contains the functionality page breaks (horizontal and vertical)<p> * - * <p>The other two classes just specifically set the SIDS for record creation.</p> + * The other two classes just specifically set the SIDS for record creation.<p> * - * <p>REFERENCE: Microsoft Excel SDK page 322 and 420</p> + * REFERENCE: Microsoft Excel SDK page 322 and 420 * * @see HorizontalPageBreakRecord * @see VerticalPageBreakRecord - * @author Danny Mui (dmui at apache dot org) */ public abstract class PageBreakRecord extends StandardRecord { private static final int[] EMPTY_INT_ARRAY = { }; - private List<Break> _breaks; - private Map<Integer, Break> _breakMap; + private final ArrayList<Break> _breaks = new ArrayList<>(); + private final Map<Integer, Break> _breakMap = new HashMap<>(); /** * Since both records store 2byte integers (short), no point in @@ -56,8 +54,13 @@ public abstract class PageBreakRecord ex public int subFrom; public int subTo; - public Break(int main, int subFrom, int subTo) - { + public Break(Break other) { + main = other.main; + subFrom = other.subFrom; + subTo = other.subTo; + } + + public Break(int main, int subFrom, int subTo) { this.main = main; this.subFrom = subFrom; this.subTo = subTo; @@ -76,23 +79,24 @@ public abstract class PageBreakRecord ex } } - protected PageBreakRecord() { - _breaks = new ArrayList<>(); - _breakMap = new HashMap<>(); - } + protected PageBreakRecord() {} - public PageBreakRecord(RecordInputStream in) - { - int nBreaks = in.readShort(); - _breaks = new ArrayList<>(nBreaks + 2); - _breakMap = new HashMap<>(); + protected PageBreakRecord(PageBreakRecord other) { + _breaks.addAll(other._breaks); + initMap(); + } + public PageBreakRecord(RecordInputStream in) { + final int nBreaks = in.readShort(); + _breaks.ensureCapacity(nBreaks + 2); for(int k = 0; k < nBreaks; k++) { - Break br = new Break(in); - _breaks.add(br); - _breakMap.put(Integer.valueOf(br.main), br); + _breaks.add(new Break(in)); } + initMap(); + } + private void initMap() { + _breaks.forEach(br -> _breakMap.put(Integer.valueOf(br.main), br)); } public boolean isEmpty() { @@ -105,8 +109,8 @@ public abstract class PageBreakRecord ex public final void serialize(LittleEndianOutput out) { int nBreaks = _breaks.size(); out.writeShort(nBreaks); - for (int i=0; i<nBreaks; i++) { - _breaks.get(i).serialize(out); + for (Break aBreak : _breaks) { + aBreak.serialize(out); } } @@ -206,4 +210,7 @@ public abstract class PageBreakRecord ex } return result; } + + @Override + public abstract PageBreakRecord copy(); } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PaletteRecord.java Sun Dec 22 21:44:45 2019 @@ -19,34 +19,36 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; import java.util.Collections; -import java.util.List; import org.apache.poi.util.LittleEndianOutput; /** - * PaletteRecord (0x0092) - Supports custom palettes. - * @author Andrew C. Oliver (acoliver at apache dot org) - * @author Brian Sanders (bsanders at risklabs dot com) - custom palette editing - * + * Supports custom palettes. */ public final class PaletteRecord extends StandardRecord { - public final static short sid = 0x0092; + public static final short sid = 0x0092; /** The standard size of an XLS palette */ - public final static byte STANDARD_PALETTE_SIZE = (byte) 56; + public static final byte STANDARD_PALETTE_SIZE = (byte) 56; /** The byte index of the first color */ - public final static short FIRST_COLOR_INDEX = (short) 0x8; + public static final short FIRST_COLOR_INDEX = (short) 0x8; - private final List<PColor> _colors; + private final ArrayList<PColor> _colors = new ArrayList<>(); public PaletteRecord() { PColor[] defaultPalette = createDefaultPalette(); - _colors = new ArrayList<>(defaultPalette.length); + _colors.ensureCapacity(defaultPalette.length); Collections.addAll(_colors, defaultPalette); } + public PaletteRecord(PaletteRecord other) { + super(other); + _colors.ensureCapacity(other._colors.size()); + other._colors.stream().map(PColor::new).forEach(_colors::add); + } + public PaletteRecord(RecordInputStream in) { int field_1_numcolors = in.readShort(); - _colors = new ArrayList<>(field_1_numcolors); + _colors.ensureCapacity(field_1_numcolors); for (int k = 0; k < field_1_numcolors; k++) { _colors.add(new PColor(in)); } @@ -71,8 +73,8 @@ public final class PaletteRecord extends @Override public void serialize(LittleEndianOutput out) { out.writeShort(_colors.size()); - for (int i = 0; i < _colors.size(); i++) { - _colors.get(i).serialize(out); + for (PColor color : _colors) { + color.serialize(out); } } @@ -88,7 +90,7 @@ public final class PaletteRecord extends /** * Returns the color value at a given index - * + * * @param byteIndex palette index, must be >= 0x8 * * @return the RGB triplet for the color, or <code>null</code> if the specified index @@ -129,6 +131,11 @@ public final class PaletteRecord extends _colors.set(i, custColor); } + @Override + public PaletteRecord copy() { + return new PaletteRecord(this); + } + /** * Creates the default palette as PaletteRecord binary data */ @@ -213,8 +220,10 @@ public final class PaletteRecord extends _blue = blue; } - public byte[] getTriplet() { - return new byte[] { (byte) _red, (byte) _green, (byte) _blue }; + public PColor(PColor other) { + _red = other._red; + _green = other._green; + _blue = other._blue; } public PColor(RecordInputStream in) { @@ -224,6 +233,10 @@ public final class PaletteRecord extends in.readByte(); // unused } + public byte[] getTriplet() { + return new byte[] { (byte) _red, (byte) _green, (byte) _blue }; + } + public void serialize(LittleEndianOutput out) { out.writeByte(_red); out.writeByte(_green); Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PaneRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PaneRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PaneRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PaneRecord.java Sun Dec 22 21:44:45 2019 @@ -20,35 +20,41 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** * Describes the frozen and unfrozen panes. */ public final class PaneRecord extends StandardRecord { - public final static short sid = 0x41; - private short field_1_x; - private short field_2_y; - private short field_3_topRow; - private short field_4_leftColumn; - private short field_5_activePane; - public final static short ACTIVE_PANE_LOWER_RIGHT = 0; - public final static short ACTIVE_PANE_UPPER_RIGHT = 1; - public final static short ACTIVE_PANE_LOWER_LEFT = 2; - public final static short ACTIVE_PANE_UPPER_LEFT = 3; - - - public PaneRecord() - { - - } - - public PaneRecord(RecordInputStream in) - { - field_1_x = in.readShort(); - field_2_y = in.readShort(); - field_3_topRow = in.readShort(); - field_4_leftColumn = in.readShort(); - field_5_activePane = in.readShort(); + public static final short sid = 0x41; + public static final short ACTIVE_PANE_LOWER_RIGHT = 0; + public static final short ACTIVE_PANE_UPPER_RIGHT = 1; + public static final short ACTIVE_PANE_LOWER_LEFT = 2; + public static final short ACTIVE_PANE_UPPER_LEFT = 3; + + private short field_1_x; + private short field_2_y; + private short field_3_topRow; + private short field_4_leftColumn; + private short field_5_activePane; + + public PaneRecord() {} + + public PaneRecord(PaneRecord other) { + super(other); + field_1_x = other.field_1_x; + field_2_y = other.field_2_y; + field_3_topRow = other.field_3_topRow; + field_4_leftColumn = other.field_4_leftColumn; + field_5_activePane = other.field_5_activePane; + } + + public PaneRecord(RecordInputStream in) { + field_1_x = in.readShort(); + field_2_y = in.readShort(); + field_3_topRow = in.readShort(); + field_4_leftColumn = in.readShort(); + field_5_activePane = in.readShort(); } @Override @@ -60,23 +66,23 @@ public final class PaneRecord extends St buffer.append(" .x = ") .append("0x").append(HexDump.toHex( getX ())) .append(" (").append( getX() ).append(" )"); - buffer.append(System.getProperty("line.separator")); + buffer.append(System.getProperty("line.separator")); buffer.append(" .y = ") .append("0x").append(HexDump.toHex( getY ())) .append(" (").append( getY() ).append(" )"); - buffer.append(System.getProperty("line.separator")); + buffer.append(System.getProperty("line.separator")); buffer.append(" .topRow = ") .append("0x").append(HexDump.toHex( getTopRow ())) .append(" (").append( getTopRow() ).append(" )"); - buffer.append(System.getProperty("line.separator")); + buffer.append(System.getProperty("line.separator")); buffer.append(" .leftColumn = ") .append("0x").append(HexDump.toHex( getLeftColumn ())) .append(" (").append( getLeftColumn() ).append(" )"); - buffer.append(System.getProperty("line.separator")); + buffer.append(System.getProperty("line.separator")); buffer.append(" .activePane = ") .append("0x").append(HexDump.toHex( getActivePane ())) .append(" (").append( getActivePane() ).append(" )"); - buffer.append(System.getProperty("line.separator")); + buffer.append(System.getProperty("line.separator")); buffer.append("[/PANE]\n"); return buffer.toString(); @@ -103,20 +109,21 @@ public final class PaneRecord extends St } @Override - public Object clone() { - PaneRecord rec = new PaneRecord(); - - rec.field_1_x = field_1_x; - rec.field_2_y = field_2_y; - rec.field_3_topRow = field_3_topRow; - rec.field_4_leftColumn = field_4_leftColumn; - rec.field_5_activePane = field_5_activePane; - return rec; + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public PaneRecord clone() { + return copy(); + } + + @Override + public PaneRecord copy() { + return new PaneRecord(this); } /** * Get the x field for the Pane record. - * + * * @return the x value */ public short getX() @@ -126,7 +133,7 @@ public final class PaneRecord extends St /** * Set the x field for the Pane record. - * + * * @param field_1_x the x value */ public void setX(short field_1_x) @@ -136,7 +143,7 @@ public final class PaneRecord extends St /** * Get the y field for the Pane record. - * + * * @return the y value */ public short getY() @@ -146,7 +153,7 @@ public final class PaneRecord extends St /** * Set the y field for the Pane record. - * + * * @param field_2_y the y value */ public void setY(short field_2_y) @@ -156,7 +163,7 @@ public final class PaneRecord extends St /** * Get the top row field for the Pane record. - * + * * @return the top row */ public short getTopRow() @@ -166,7 +173,7 @@ public final class PaneRecord extends St /** * Set the top row field for the Pane record. - * + * * @param field_3_topRow the top row */ public void setTopRow(short field_3_topRow) @@ -176,7 +183,7 @@ public final class PaneRecord extends St /** * Get the left column field for the Pane record. - * + * * @return the left column */ public short getLeftColumn() @@ -186,7 +193,7 @@ public final class PaneRecord extends St /** * Set the left column field for the Pane record. - * + * * @param field_4_leftColumn the left column */ public void setLeftColumn(short field_4_leftColumn) @@ -197,7 +204,7 @@ public final class PaneRecord extends St /** * Get the active pane field for the Pane record. * - * @return One of + * @return One of * ACTIVE_PANE_LOWER_RIGHT * ACTIVE_PANE_UPPER_RIGHT * ACTIVE_PANE_LOWER_LEFT @@ -212,7 +219,7 @@ public final class PaneRecord extends St * Set the active pane field for the Pane record. * * @param field_5_activePane - * One of + * One of * ACTIVE_PANE_LOWER_RIGHT * ACTIVE_PANE_UPPER_RIGHT * ACTIVE_PANE_LOWER_LEFT Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRecord.java Sun Dec 22 21:44:45 2019 @@ -19,20 +19,26 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Password Record (0x0013)<p> - * Description: stores the encrypted password for a sheet or workbook (HSSF doesn't support encryption) - * REFERENCE: PG 371 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) + * Stores the encrypted password for a sheet or workbook (HSSF doesn't support encryption) */ public final class PasswordRecord extends StandardRecord { - public final static short sid = 0x0013; - private int field_1_password; // not sure why this is only 2 bytes, but it is... go figure + public static final short sid = 0x0013; + + // not sure why this is only 2 bytes, but it is... go figure + private int field_1_password; public PasswordRecord(int password) { field_1_password = password; } + public PasswordRecord(PasswordRecord other) { + super(other); + field_1_password = other.field_1_password; + } + public PasswordRecord(RecordInputStream in) { field_1_password = in.readShort(); } @@ -77,10 +83,18 @@ public final class PasswordRecord extend return sid; } + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public PasswordRecord clone() { + return copy(); + } + /** * Clone this record. */ - public Object clone() { - return new PasswordRecord(field_1_password); + public PasswordRecord copy() { + return new PasswordRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PasswordRev4Record.java Sun Dec 22 21:44:45 2019 @@ -21,18 +21,22 @@ import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; /** - * Title: Protection Revision 4 password Record (0x01BC)<p> - * Description: Stores the (2 byte??!!) encrypted password for a shared workbook<p> - * REFERENCE: PG 374 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) + * Protection Revision 4 password Record (0x01BC)<p> + * Stores the (2 byte??!!) encrypted password for a shared workbook */ public final class PasswordRev4Record extends StandardRecord { - public final static short sid = 0x01BC; + public static final short sid = 0x01BC; private int field_1_password; public PasswordRev4Record(int pw) { field_1_password = pw; } + public PasswordRev4Record(PasswordRev4Record other) { + super(other); + field_1_password = other.field_1_password; + } + public PasswordRev4Record(RecordInputStream in) { field_1_password = in.readShort(); } @@ -66,4 +70,9 @@ public final class PasswordRev4Record ex public short getSid() { return sid; } + + @Override + public PasswordRev4Record copy() { + return new PasswordRev4Record(this); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PrecisionRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PrecisionRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PrecisionRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PrecisionRecord.java Sun Dec 22 21:44:45 2019 @@ -20,21 +20,24 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; /** - * Title: Precision Record<P> - * Description: defines whether to store with full precision or what's displayed by the gui - * (meaning have really screwed up and skewed figures or only think you do!)<P> - * REFERENCE: PG 372 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> + * Defines whether to store with full precision or what's displayed by the gui + * (meaning have really screwed up and skewed figures or only think you do!) + * * @version 2.0-pre */ public final class PrecisionRecord extends StandardRecord { - public final static short sid = 0xE; - public short field_1_precision; + public static final short sid = 0xE; - public PrecisionRecord() { + public short field_1_precision; + + public PrecisionRecord() {} + + public PrecisionRecord(PrecisionRecord other) { + super(other); + field_1_precision = other.field_1_precision; } - public PrecisionRecord(RecordInputStream in) - { + public PrecisionRecord(RecordInputStream in) { field_1_precision = in.readShort(); } @@ -44,11 +47,7 @@ public final class PrecisionRecord exten * @param fullprecision - or not */ public void setFullPrecision(boolean fullprecision) { - if (fullprecision) { - field_1_precision = 1; - } else { - field_1_precision = 0; - } + field_1_precision = (short) (fullprecision ? 1 : 0); } /** @@ -80,4 +79,9 @@ public final class PrecisionRecord exten { return sid; } + + @Override + public PrecisionRecord copy() { + return new PrecisionRecord(this); + } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PrintGridlinesRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PrintGridlinesRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PrintGridlinesRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PrintGridlinesRecord.java Sun Dec 22 21:44:45 2019 @@ -17,24 +17,25 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Print Gridlines Record<P> - * Description: whether to print the gridlines when you enjoy you spreadsheet on paper.<P> - * REFERENCE: PG 373 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) + * Whether to print the gridlines when you enjoy the spreadsheet on paper. + * * @version 2.0-pre */ public final class PrintGridlinesRecord extends StandardRecord { - public final static short sid = 0x2b; - private short field_1_print_gridlines; + public static final short sid = 0x2b; + private short field_1_print_gridlines; - public PrintGridlinesRecord() { + public PrintGridlinesRecord() {} + + public PrintGridlinesRecord(PrintGridlinesRecord other) { + super(other); + field_1_print_gridlines = other.field_1_print_gridlines; } - public PrintGridlinesRecord(RecordInputStream in) - { + public PrintGridlinesRecord(RecordInputStream in) { field_1_print_gridlines = in.readShort(); } @@ -44,11 +45,7 @@ public final class PrintGridlinesRecord * @param pg make spreadsheet ugly - Y/N */ public void setPrintGridlines(boolean pg) { - if (pg) { - field_1_print_gridlines = 1; - } else { - field_1_print_gridlines = 0; - } + field_1_print_gridlines = (short) (pg ? 1 : 0); } /** @@ -81,9 +78,15 @@ public final class PrintGridlinesRecord return sid; } - public Object clone() { - PrintGridlinesRecord rec = new PrintGridlinesRecord(); - rec.field_1_print_gridlines = field_1_print_gridlines; - return rec; + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public PrintGridlinesRecord clone() { + return copy(); + } + + public PrintGridlinesRecord copy() { + return new PrintGridlinesRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PrintHeadersRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PrintHeadersRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PrintHeadersRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PrintHeadersRecord.java Sun Dec 22 21:44:45 2019 @@ -18,25 +18,26 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Print Headers Record<P> - * Description: Whether or not to print the row/column headers when you - * enjoy your spreadsheet in the physical form.<P> - * REFERENCE: PG 373 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) + * Whether or not to print the row/column headers when you enjoy your spreadsheet in the physical form. + * * @version 2.0-pre */ public final class PrintHeadersRecord extends StandardRecord { - public final static short sid = 0x2a; - private short field_1_print_headers; + public static final short sid = 0x2a; + private short field_1_print_headers; - public PrintHeadersRecord() { + public PrintHeadersRecord() {} + + public PrintHeadersRecord(PrintHeadersRecord other) { + super(other); + field_1_print_headers = other.field_1_print_headers; } - public PrintHeadersRecord(RecordInputStream in) - { + + public PrintHeadersRecord(RecordInputStream in) { field_1_print_headers = in.readShort(); } @@ -81,9 +82,15 @@ public final class PrintHeadersRecord ex return sid; } - public Object clone() { - PrintHeadersRecord rec = new PrintHeadersRecord(); - rec.field_1_print_headers = field_1_print_headers; - return rec; + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public PrintHeadersRecord clone() { + return copy(); + } + + public PrintHeadersRecord copy() { + return new PrintHeadersRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java Sun Dec 22 21:44:45 2019 @@ -18,20 +18,36 @@ package org.apache.poi.hssf.record; import org.apache.poi.ss.usermodel.PrintSetup; -import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; +import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: PAGESETUP (0x00A1)<p> - * Description: Stores print setup options -- bogus for HSSF (and marked as such)<p> - * REFERENCE: PG 385 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p> - * REFERENCE: PG 412 Microsoft Excel Binary File Format Structure v20091214 - * + * Stores print setup options -- bogus for HSSF (and marked as such) + * * @since 2.0-pre */ public final class PrintSetupRecord extends StandardRecord { - public final static short sid = 0x00A1; + public static final short sid = 0x00A1; + // print over then down + private static final BitField lefttoright = BitFieldFactory.getInstance(0x01); + // landscape mode + private static final BitField landscape = BitFieldFactory.getInstance(0x02); + // if papersize, scale, resolution, copies, landscape + private static final BitField validsettings = BitFieldFactory.getInstance(0x04); + // print mono/b&w, colorless + private static final BitField nocolor = BitFieldFactory.getInstance(0x08); + // print draft quality + private static final BitField draft = BitFieldFactory.getInstance(0x10); + // print the notes + private static final BitField notes = BitFieldFactory.getInstance(0x20); + // the orientation is not set + private static final BitField noOrientation = BitFieldFactory.getInstance(0x40); + // use a user set page no, instead of auto + private static final BitField usepage = BitFieldFactory.getInstance(0x80); + + /** Constants for this are held in {@link PrintSetup} */ private short field_1_paper_size; private short field_2_scale; @@ -39,37 +55,30 @@ public final class PrintSetupRecord exte private short field_4_fit_width; private short field_5_fit_height; private short field_6_options; - static final private BitField lefttoright = - BitFieldFactory.getInstance(0x01); // print over then down - static final private BitField landscape = - BitFieldFactory.getInstance(0x02); // landscape mode - static final private BitField validsettings = BitFieldFactory.getInstance( - 0x04); // if papersize, scale, resolution, copies, landscape - - // weren't obtained from the print consider them - // mere bunk - static final private BitField nocolor = - BitFieldFactory.getInstance(0x08); // print mono/b&w, colorless - static final private BitField draft = - BitFieldFactory.getInstance(0x10); // print draft quality - static final private BitField notes = - BitFieldFactory.getInstance(0x20); // print the notes - static final private BitField noOrientation = - BitFieldFactory.getInstance(0x40); // the orientation is not set - static final private BitField usepage = - BitFieldFactory.getInstance(0x80); // use a user set page no, instead of auto private short field_7_hresolution; private short field_8_vresolution; private double field_9_headermargin; private double field_10_footermargin; private short field_11_copies; - public PrintSetupRecord() - { + public PrintSetupRecord() {} + + public PrintSetupRecord(PrintSetupRecord other) { + super(other); + field_1_paper_size = other.field_1_paper_size; + field_2_scale = other.field_2_scale; + field_3_page_start = other.field_3_page_start; + field_4_fit_width = other.field_4_fit_width; + field_5_fit_height = other.field_5_fit_height; + field_6_options = other.field_6_options; + field_7_hresolution = other.field_7_hresolution; + field_8_vresolution = other.field_8_vresolution; + field_9_headermargin = other.field_9_headermargin; + field_10_footermargin = other.field_10_footermargin; + field_11_copies = other.field_11_copies; } - public PrintSetupRecord(RecordInputStream in) - { + public PrintSetupRecord(RecordInputStream in) { field_1_paper_size = in.readShort(); field_2_scale = in.readShort(); field_3_page_start = in.readShort(); @@ -347,19 +356,16 @@ public final class PrintSetupRecord exte return sid; } - public Object clone() { - PrintSetupRecord rec = new PrintSetupRecord(); - rec.field_1_paper_size = field_1_paper_size; - rec.field_2_scale = field_2_scale; - rec.field_3_page_start = field_3_page_start; - rec.field_4_fit_width = field_4_fit_width; - rec.field_5_fit_height = field_5_fit_height; - rec.field_6_options = field_6_options; - rec.field_7_hresolution = field_7_hresolution; - rec.field_8_vresolution = field_8_vresolution; - rec.field_9_headermargin = field_9_headermargin; - rec.field_10_footermargin = field_10_footermargin; - rec.field_11_copies = field_11_copies; - return rec; + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public PrintSetupRecord clone() { + return copy(); + } + + @Override + public PrintSetupRecord copy() { + return new PrintSetupRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ProtectRecord.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ProtectRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ProtectRecord.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ProtectRecord.java Sun Dec 22 21:44:45 2019 @@ -21,16 +21,15 @@ import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.Removal; /** - * Title: Protect Record (0x0012)<p> - * Description: defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)<p> + * Defines whether a sheet or workbook is protected (HSSF DOES NOT SUPPORT ENCRYPTION)<p> * HSSF now supports the simple "protected" sheets (where they are not encrypted and open office et al * ignore the password record entirely). - * REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) */ public final class ProtectRecord extends StandardRecord { - public final static short sid = 0x0012; + public static final short sid = 0x0012; private static final BitField protectFlag = BitFieldFactory.getInstance(0x0001); @@ -40,6 +39,11 @@ public final class ProtectRecord extends _options = options; } + private ProtectRecord(ProtectRecord other) { + super(other); + _options = other._options; + } + public ProtectRecord(boolean isProtected) { this(0); setProtect(isProtected); @@ -86,7 +90,16 @@ public final class ProtectRecord extends return sid; } - public Object clone() { - return new ProtectRecord(_options); + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public ProtectRecord clone() { + return copy(); + } + + @Override + public ProtectRecord copy() { + return new ProtectRecord(this); } } Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java?rev=1871911&r1=1871910&r2=1871911&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java Sun Dec 22 21:44:45 2019 @@ -23,12 +23,10 @@ import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; /** - * Title: Protection Revision 4 Record (0x01AF)<p> - * Description: describes whether this is a protected shared/tracked workbook<p> - * REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2) + * Describes whether this is a protected shared/tracked workbook<p> */ public final class ProtectionRev4Record extends StandardRecord { - public final static short sid = 0x01AF; + public static final short sid = 0x01AF; private static final BitField protectedFlag = BitFieldFactory.getInstance(0x0001); @@ -38,6 +36,11 @@ public final class ProtectionRev4Record _options = options; } + private ProtectionRev4Record(ProtectionRev4Record other) { + super(other); + _options = other._options; + } + public ProtectionRev4Record(boolean protect) { this(0); setProtect(protect); @@ -83,4 +86,9 @@ public final class ProtectionRev4Record public short getSid() { return sid; } + + @Override + public ProtectionRev4Record copy() { + return new ProtectionRev4Record(this); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org