You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/12/22 21:44:48 UTC

svn commit: r1871911 [7/15] - in /poi/trunk/src: integrationtest/org/apache/poi/ integrationtest/org/apache/poi/hssf/usermodel/ java/org/apache/poi/common/ java/org/apache/poi/ddf/ java/org/apache/poi/hssf/eventusermodel/dummyrecord/ java/org/apache/po...

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WSBoolRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WSBoolRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WSBoolRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WSBoolRecord.java Sun Dec 22 21:44:45 2019
@@ -20,36 +20,50 @@ package org.apache.poi.hssf.record;
 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:        WSBOOL (0x0081) (called SHEETPR in OOO doc)<p>
- * Description:  stores workbook settings  (aka its a big "everything we didn't
- *               put somewhere else")<p>
- * REFERENCE:  PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
+ * Stores workbook settings (aka its a big "everything we didn't put somewhere else")
  */
 public final class WSBoolRecord extends StandardRecord {
-    public final static short     sid = 0x0081;
-    private byte                  field_1_wsbool;         // crappy names are because this is really one big short field (2byte)
-    private byte                  field_2_wsbool;         // but the docs inconsistently use it as 2 separate bytes
-
-    // I decided to be consistent in this way.
-    private static final BitField autobreaks    = BitFieldFactory.getInstance(0x01); // are automatic page breaks visible
+    public static final short     sid = 0x0081;
+    // are automatic page breaks visible
+    private static final BitField autobreaks    = BitFieldFactory.getInstance(0x01);
 
     // bits 1 to 3 unused
-    private static final BitField dialog        = BitFieldFactory.getInstance(0x10); // is sheet dialog sheet
-    private static final BitField applystyles   = BitFieldFactory.getInstance(0x20); // whether to apply automatic styles to outlines
-    private static final BitField rowsumsbelow  = BitFieldFactory.getInstance(0x40); // whether summary rows will appear below detail in outlines
-    private static final BitField rowsumsright  = BitFieldFactory.getInstance(0x80); // whether summary rows will appear right of the detail in outlines
-    private static final BitField fittopage     = BitFieldFactory.getInstance(0x01); // whether to fit stuff to the page
+    // is sheet dialog sheet
+    private static final BitField dialog        = BitFieldFactory.getInstance(0x10);
+    // whether to apply automatic styles to outlines
+    private static final BitField applystyles   = BitFieldFactory.getInstance(0x20);
+    // whether summary rows will appear below detail in outlines
+    private static final BitField rowsumsbelow  = BitFieldFactory.getInstance(0x40);
+    // whether summary rows will appear right of the detail in outlines
+    private static final BitField rowsumsright  = BitFieldFactory.getInstance(0x80);
+    // whether to fit stuff to the page
+    private static final BitField fittopage     = BitFieldFactory.getInstance(0x01);
 
     // bit 2 reserved
-    private static final BitField displayguts   = BitFieldFactory.getInstance(0x06); // whether to display outline symbols (in the gutters)
+    // whether to display outline symbols (in the gutters)
+    private static final BitField displayguts   = BitFieldFactory.getInstance(0x06);
 
     // bits 4-5 reserved
-    private static final BitField alternateexpression = BitFieldFactory.getInstance(0x40); // whether to use alternate expression eval
-    private static final BitField alternateformula    = BitFieldFactory.getInstance(0x80); // whether to use alternate formula entry
-
-    public WSBoolRecord() {
+    // whether to use alternate expression eval
+    private static final BitField alternateexpression = BitFieldFactory.getInstance(0x40);
+    // whether to use alternate formula entry
+    private static final BitField alternateformula    = BitFieldFactory.getInstance(0x80);
+
+    // crappy names are because this is really one big short field (2byte)
+    private byte field_1_wsbool;
+    // but the docs inconsistently use it as 2 separate bytes
+    private byte field_2_wsbool;
+
+
+    public WSBoolRecord() {}
+
+    public WSBoolRecord(WSBoolRecord other) {
+        super(other);
+        field_1_wsbool = other.field_1_wsbool;
+        field_2_wsbool = other.field_2_wsbool;
     }
 
     public WSBoolRecord(RecordInputStream in) {
@@ -292,10 +306,16 @@ public final class WSBoolRecord extends
         return sid;
     }
 
-    public Object clone() {
-      WSBoolRecord rec = new WSBoolRecord();
-      rec.field_1_wsbool = field_1_wsbool;
-      rec.field_2_wsbool = field_2_wsbool;
-      return rec;
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public WSBoolRecord clone() {
+        return copy();
+    }
+
+    @Override
+    public WSBoolRecord copy() {
+      return new WSBoolRecord(this);
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WindowOneRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WindowOneRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WindowOneRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WindowOneRecord.java Sun Dec 22 21:44:45 2019
@@ -22,55 +22,64 @@ import org.apache.poi.util.BitFieldFacto
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Title:        Window1 Record<P>
- * Description:  Stores the attributes of the workbook window.  This is basically
- *               so the gui knows how big to make the window holding the spreadsheet
- *               document.<P>
- * REFERENCE:  PG 421 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
- * @author Andrew C. Oliver (acoliver at apache dot org)
+ * Stores the attributes of the workbook window.
+ * This is basically so the gui knows how big to make the window holding the spreadsheet document.
+ *
  * @version 2.0-pre
  */
 public final class WindowOneRecord extends StandardRecord {
-    public final static short     sid = 0x3d;
+    public static final short sid = 0x3d;
 
-    // our variable names stolen from old TV sets.
-    private short                 field_1_h_hold;                  // horizontal position
-    private short                 field_2_v_hold;                  // vertical position
-    private short                 field_3_width;
-    private short                 field_4_height;
-    private short                 field_5_options;
-    static final private BitField hidden   =
-        BitFieldFactory.getInstance(0x01);                                        // is this window is hidden
-    static final private BitField iconic   =
-        BitFieldFactory.getInstance(0x02);                                        // is this window is an icon
+    // horizontal position
+    private short field_1_h_hold;
+    // vertical position
+    private short field_2_v_hold;
+    private short field_3_width;
+    private short field_4_height;
+    private short field_5_options;
+    // is this window is hidden
+    static final private BitField hidden   = BitFieldFactory.getInstance(0x01);
+    // is this window is an icon
+    static final private BitField iconic   = BitFieldFactory.getInstance(0x02);
+    // reserved
     @SuppressWarnings("unused")
-    static final private BitField reserved = BitFieldFactory.getInstance(0x04);   // reserved
-    static final private BitField hscroll  =
-        BitFieldFactory.getInstance(0x08);                                        // display horizontal scrollbar
-    static final private BitField vscroll  =
-        BitFieldFactory.getInstance(0x10);                                        // display vertical scrollbar
-    static final private BitField tabs     =
-        BitFieldFactory.getInstance(0x20);                                        // display tabs at the bottom
+    static final private BitField reserved = BitFieldFactory.getInstance(0x04);
+    // display horizontal scrollbar
+    static final private BitField hscroll  = BitFieldFactory.getInstance(0x08);
+    // display vertical scrollbar
+    static final private BitField vscroll  = BitFieldFactory.getInstance(0x10);
+    // display tabs at the bottom
+    static final private BitField tabs     = BitFieldFactory.getInstance(0x20);
 
     // all the rest are "reserved"
-    private int                   field_6_active_sheet;
-    private int                   field_7_first_visible_tab;
-    private short                 field_8_num_selected_tabs;
-    private short                 field_9_tab_width_ratio;
-
-    public WindowOneRecord()
-    {
+    private int   field_6_active_sheet;
+    private int   field_7_first_visible_tab;
+    private short field_8_num_selected_tabs;
+    private short field_9_tab_width_ratio;
+
+    public WindowOneRecord() {}
+
+    public WindowOneRecord(WindowOneRecord other) {
+        super(other);
+        field_1_h_hold            = other.field_1_h_hold;
+        field_2_v_hold            = other.field_2_v_hold;
+        field_3_width             = other.field_3_width;
+        field_4_height            = other.field_4_height;
+        field_5_options           = other.field_5_options;
+        field_6_active_sheet      = other.field_6_active_sheet;
+        field_7_first_visible_tab = other.field_7_first_visible_tab;
+        field_8_num_selected_tabs = other.field_8_num_selected_tabs;
+        field_9_tab_width_ratio   = other.field_9_tab_width_ratio;
     }
 
-    public WindowOneRecord(RecordInputStream in)
-    {
+    public WindowOneRecord(RecordInputStream in) {
         field_1_h_hold            = in.readShort();
         field_2_v_hold            = in.readShort();
         field_3_width             = in.readShort();
         field_4_height            = in.readShort();
         field_5_options           = in.readShort();
         field_6_active_sheet      = in.readShort();
-        field_7_first_visible_tab     = in.readShort();
+        field_7_first_visible_tab = in.readShort();
         field_8_num_selected_tabs = in.readShort();
         field_9_tab_width_ratio   = in.readShort();
     }
@@ -318,16 +327,16 @@ public final class WindowOneRecord exten
 
     // end options bitfields
 
-    
+
     /**
-     * @return the index of the currently displayed sheet 
+     * @return the index of the currently displayed sheet
      */
     public int getActiveSheetIndex() {
     	return field_6_active_sheet;
     }
 
     /**
-     * @return the first visible sheet in the worksheet tab-bar. 
+     * @return the first visible sheet in the worksheet tab-bar.
      * I.E. the scroll position of the tab-bar.
      */
     public int getFirstVisibleTab() {
@@ -407,4 +416,9 @@ public final class WindowOneRecord exten
     {
         return sid;
     }
+
+    @Override
+    public WindowOneRecord copy() {
+        return new WindowOneRecord(this);
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WindowProtectRecord.java Sun Dec 22 21:44:45 2019
@@ -21,14 +21,13 @@ 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: Window Protect Record (0x0019)<p>
- * Description:  flags whether workbook windows are protected<p>
- * REFERENCE:  PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
+ * Flags whether workbook windows are protected
  */
 public final class WindowProtectRecord extends StandardRecord {
-    public final static short sid = 0x0019;
+    public static final short sid = 0x0019;
 
     private static final BitField settingsProtectedFlag = BitFieldFactory.getInstance(0x0001);
 
@@ -38,6 +37,11 @@ public final class WindowProtectRecord e
         _options = options;
     }
 
+    public WindowProtectRecord(WindowProtectRecord other) {
+        super(other);
+        _options = other._options;
+    }
+
     public WindowProtectRecord(RecordInputStream in) {
         this(in.readUShort());
     }
@@ -85,8 +89,17 @@ public final class WindowProtectRecord e
     {
         return sid;
     }
+
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public WindowProtectRecord clone() {
+        return copy();
+    }
+
     @Override
-    public Object clone() {
-        return new WindowProtectRecord(_options);
+    public WindowProtectRecord copy() {
+        return new WindowProtectRecord(this);
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java Sun Dec 22 21:44:45 2019
@@ -20,17 +20,15 @@ package org.apache.poi.hssf.record;
 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:        Window Two Record<P>
- * Description:  sheet window settings<P>
- * REFERENCE:  PG 422 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)
+ * Sheet window settings
+ *
  * @version 2.0-pre
  */
 public final class WindowTwoRecord extends StandardRecord {
-    public final static short sid = 0x023E;
+    public static final short sid = 0x023E;
 
     // bitfields
     private static final BitField displayFormulas         = BitFieldFactory.getInstance(0x01);
@@ -39,7 +37,7 @@ public final class WindowTwoRecord exten
     private static final BitField freezePanes             = BitFieldFactory.getInstance(0x08);
     private static final BitField displayZeros            = BitFieldFactory.getInstance(0x10);
     /**  if false use color in field 4 if true use default foreground for headers */
-    private static final BitField defaultHeader           = BitFieldFactory.getInstance(0x20);   
+    private static final BitField defaultHeader           = BitFieldFactory.getInstance(0x20);
     private static final BitField arabic                  = BitFieldFactory.getInstance(0x040);
     private static final BitField displayGuts             = BitFieldFactory.getInstance(0x080);
     private static final BitField freezePanesNoSplit      = BitFieldFactory.getInstance(0x100);
@@ -49,20 +47,28 @@ public final class WindowTwoRecord exten
     // 4-7 reserved
     // end bitfields
 
-    private short             field_1_options;
-    private short             field_2_top_row;
-    private short             field_3_left_col;
-    private int               field_4_header_color;
-    private short             field_5_page_break_zoom;
-    private short             field_6_normal_zoom;
-    private int               field_7_reserved;
-
-    public WindowTwoRecord()
-    {
+    private short field_1_options;
+    private short field_2_top_row;
+    private short field_3_left_col;
+    private int   field_4_header_color;
+    private short field_5_page_break_zoom;
+    private short field_6_normal_zoom;
+    private int   field_7_reserved;
+
+    public WindowTwoRecord() {}
+
+    public WindowTwoRecord(WindowTwoRecord other) {
+        super(other);
+        field_1_options = other.field_1_options;
+        field_2_top_row = other.field_2_top_row;
+        field_3_left_col = other.field_3_left_col;
+        field_4_header_color = other.field_4_header_color;
+        field_5_page_break_zoom = other.field_5_page_break_zoom;
+        field_6_normal_zoom = other.field_6_normal_zoom;
+        field_7_reserved = other.field_7_reserved;
     }
 
-    public WindowTwoRecord(RecordInputStream in)
-    {
+    public WindowTwoRecord(RecordInputStream in) {
       int size = in.remaining();
         field_1_options      = in.readShort();
         field_2_top_row      = in.readShort();
@@ -475,15 +481,16 @@ public final class WindowTwoRecord exten
         return sid;
     }
 
-    public Object clone() {
-      WindowTwoRecord rec = new WindowTwoRecord();
-      rec.field_1_options = field_1_options;
-      rec.field_2_top_row = field_2_top_row;
-      rec.field_3_left_col = field_3_left_col;
-      rec.field_4_header_color = field_4_header_color;
-      rec.field_5_page_break_zoom = field_5_page_break_zoom;
-      rec.field_6_normal_zoom = field_6_normal_zoom;
-      rec.field_7_reserved = field_7_reserved;
-      return rec;
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public WindowTwoRecord clone() {
+        return copy();
+    }
+
+    @Override
+    public WindowTwoRecord copy() {
+        return new WindowTwoRecord(this);
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java Sun Dec 22 21:44:45 2019
@@ -26,28 +26,33 @@ import org.apache.poi.util.StringUtil;
 
 /**
  * Title: Write Access Record (0x005C)<p>
- * 
- * Description: Stores the username of that who owns the spreadsheet generator (on unix the user's 
+ *
+ * Description: Stores the username of that who owns the spreadsheet generator (on unix the user's
  * login, on Windoze its the name you typed when you installed the thing)<p>
- * 
- * REFERENCE: PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
  */
 public final class WriteAccessRecord extends StandardRecord {
-	public final static short sid = 0x005C;
+	public static final short sid = 0x005C;
 
 	private static final byte PAD_CHAR = (byte) ' ';
 	private static final int DATA_SIZE = 112;
-	private String field_1_username;
 	/** this record is always padded to a constant length */
 	private static final byte[] PADDING = new byte[DATA_SIZE];
 	static {
 		Arrays.fill(PADDING, PAD_CHAR);
 	}
 
+	private String field_1_username;
+
+
 	public WriteAccessRecord() {
 		setUsername("");
 	}
 
+	public WriteAccessRecord(WriteAccessRecord other) {
+		super(other);
+		field_1_username = other.field_1_username;
+	}
+
 	public WriteAccessRecord(RecordInputStream in) {
 		if (in.remaining() > DATA_SIZE) {
 			throw new RecordFormatException("Expected data size (" + DATA_SIZE + ") but got ("
@@ -91,7 +96,7 @@ public final class WriteAccessRecord ext
 	/**
 	 * set the username for the user that created the report. HSSF uses the
 	 * logged in user.
-	 * 
+	 *
 	 * @param username of the user who is logged in (probably "tomcat" or "apache")
 	 */
 	public void setUsername(String username) {
@@ -109,7 +114,7 @@ public final class WriteAccessRecord ext
 	 * get the username for the user that created the report. HSSF uses the
 	 * logged in user. On natively created M$ Excel sheet this would be the name
 	 * you typed in when you installed it in most cases.
-	 * 
+	 *
 	 * @return username of the user who is logged in (probably "tomcat" or "apache")
 	 */
 	public String getUsername() {
@@ -148,4 +153,9 @@ public final class WriteAccessRecord ext
 	public short getSid() {
 		return sid;
 	}
+
+	@Override
+	public WriteAccessRecord copy() {
+		return new WriteAccessRecord(this);
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java Sun Dec 22 21:44:45 2019
@@ -20,17 +20,14 @@ package org.apache.poi.hssf.record;
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Title:        Write Protect Record<P>
- * Description:  Indicated that the sheet/workbook is write protected. 
- * REFERENCE:  PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * Indicated that the sheet/workbook is write protected.
+ *
  * @version 3.0-pre
  */
 public final class WriteProtectRecord extends StandardRecord {
-    public final static short sid = 0x86;
+    public static final short sid = 0x86;
 
-    public WriteProtectRecord()
-    {
-    }
+    public WriteProtectRecord() {}
 
     /**
      * @param in unused (since this record has no data)
@@ -62,4 +59,9 @@ public final class WriteProtectRecord ex
     {
         return sid;
     }
+
+    @Override
+    public WriteProtectRecord copy() {
+        return new WriteProtectRecord();
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java Sun Dec 22 21:44:45 2019
@@ -37,7 +37,7 @@ import org.apache.poi.util.POILogger;
 import org.apache.poi.util.RecordFormatException;
 
 /**
- * <p>CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord 
+ * <p>CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord
  * and number of up CFRuleRecord records together to simplify access to them.</p>
  * <p>Note that Excel versions before 2007 can only cope with a maximum of 3
  *  Conditional Formatting rules per sheet. Excel 2007 or newer can cope with
@@ -52,7 +52,12 @@ public final class CFRecordsAggregate ex
     private final CFHeaderBase header;
 
     /** List of CFRuleRecord objects */
-    private final List<CFRuleBase> rules;
+    private final List<CFRuleBase> rules = new ArrayList<>();
+
+    public CFRecordsAggregate(CFRecordsAggregate other) {
+        header = other.header.copy();
+        other.rules.stream().map(t -> t.copy()).forEach(rules::add);
+    }
 
     private CFRecordsAggregate(CFHeaderBase pHeader, CFRuleBase[] pRules) {
         if(pHeader == null) {
@@ -63,7 +68,7 @@ public final class CFRecordsAggregate ex
         }
         if(pRules.length > MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
             logger.log(POILogger.WARN, "Excel versions before 2007 require that "
-                    + "No more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES 
+                    + "No more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
                     + " rules may be specified, " + pRules.length + " were found,"
                     + " this file will cause problems with old Excel versions");
         }
@@ -71,7 +76,6 @@ public final class CFRecordsAggregate ex
             throw new RecordFormatException("Mismatch number of rules");
         }
         header = pHeader;
-        rules = new ArrayList<>(pRules.length);
         for (CFRuleBase pRule : pRules) {
             checkRuleType(pRule);
             rules.add(pRule);
@@ -105,7 +109,7 @@ public final class CFRecordsAggregate ex
         Record rec = rs.getNext();
         if (rec.getSid() != CFHeaderRecord.sid &&
             rec.getSid() != CFHeader12Record.sid) {
-            throw new IllegalStateException("next record sid was " + rec.getSid() 
+            throw new IllegalStateException("next record sid was " + rec.getSid()
                     + " instead of " + CFHeaderRecord.sid + " or " +
                     CFHeader12Record.sid + " as expected");
         }
@@ -127,11 +131,7 @@ public final class CFRecordsAggregate ex
      * @return A new object with the same values as this record
      */
     public CFRecordsAggregate cloneCFAggregate() {
-        CFRuleBase[] newRecs = new CFRuleBase[rules.size()];
-        for (int i = 0; i < newRecs.length; i++) {
-            newRecs[i] = getRule(i).clone();
-        }
-        return new CFRecordsAggregate(header.clone(), newRecs);
+        return new CFRecordsAggregate(this);
     }
 
     /**
@@ -143,7 +143,7 @@ public final class CFRecordsAggregate ex
 
     private void checkRuleIndex(int idx) {
         if(idx < 0 || idx >= rules.size()) {
-            throw new IllegalArgumentException("Bad rule record index (" + idx 
+            throw new IllegalArgumentException("Bad rule record index (" + idx
                     + ") nRules=" + rules.size());
         }
     }
@@ -176,8 +176,8 @@ public final class CFRecordsAggregate ex
             throw new IllegalArgumentException("r must not be null");
         }
         if(rules.size() >= MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
-            logger.log(POILogger.WARN, "Excel versions before 2007 cannot cope with" 
-                    + " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES 
+            logger.log(POILogger.WARN, "Excel versions before 2007 cannot cope with"
+                    + " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
                     + " - this file will cause problems with old Excel versions");
         }
         checkRuleType(r);

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java Sun Dec 22 21:44:45 2019
@@ -18,50 +18,37 @@
 package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
-import java.util.Comparator;
 import java.util.List;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.util.Removal;
 
-/**
- * @author Glen Stampoultzis
- */
-public final class ColumnInfoRecordsAggregate extends RecordAggregate implements Cloneable {
+public final class ColumnInfoRecordsAggregate extends RecordAggregate implements Duplicatable {
 	/**
 	 * List of {@link ColumnInfoRecord}s assumed to be in order
 	 */
-	private final List<ColumnInfoRecord> records;
-
-
-	private static final class CIRComparator implements Comparator<ColumnInfoRecord> {
-		public static final Comparator<ColumnInfoRecord> instance = new CIRComparator();
-		private CIRComparator() {
-			// enforce singleton
-		}
-		public int compare(ColumnInfoRecord a, ColumnInfoRecord b) {
-			return compareColInfos(a, b);
-		}
-		public static int compareColInfos(ColumnInfoRecord a, ColumnInfoRecord b) {
-			return a.getFirstColumn()-b.getFirstColumn();
-		}
-	}
+	private final List<ColumnInfoRecord> records = new ArrayList<>();
 
 	/**
 	 * Creates an empty aggregate
 	 */
-	public ColumnInfoRecordsAggregate() {
-		records = new ArrayList<>();
+	public ColumnInfoRecordsAggregate() {}
+
+	public ColumnInfoRecordsAggregate(ColumnInfoRecordsAggregate other) {
+		other.records.stream().map(ColumnInfoRecord::copy).forEach(records::add);
 	}
+
 	public ColumnInfoRecordsAggregate(RecordStream rs) {
 		this();
 
 		boolean isInOrder = true;
 		ColumnInfoRecord cirPrev = null;
-		while(rs.peekNextClass() == ColumnInfoRecord.class) {
+		while (rs.peekNextClass() == ColumnInfoRecord.class) {
 			ColumnInfoRecord cir = (ColumnInfoRecord) rs.getNext();
 			records.add(cir);
-			if (cirPrev != null && CIRComparator.compareColInfos(cirPrev, cir) > 0) {
+			if (cirPrev != null && compareColInfos(cirPrev, cir) > 0) {
 				isInOrder = false;
 			}
 			cirPrev = cir;
@@ -70,17 +57,21 @@ public final class ColumnInfoRecordsAggr
 			throw new RuntimeException("No column info records found");
 		}
 		if (!isInOrder) {
-			records.sort(CIRComparator.instance);
+			records.sort(ColumnInfoRecordsAggregate::compareColInfos);
 		}
 	}
 
 	@Override
+	@SuppressWarnings("squid:S2975")
+	@Deprecated
+	@Removal(version = "5.0.0")
 	public ColumnInfoRecordsAggregate clone() {
-		ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate();
-		for (ColumnInfoRecord ci : records) {
-			rec.records.add(ci.clone());
-		}
-		return rec;
+		return copy();
+	}
+
+	@Override
+	public ColumnInfoRecordsAggregate copy() {
+		return new ColumnInfoRecordsAggregate(this);
 	}
 
 	/**
@@ -88,7 +79,7 @@ public final class ColumnInfoRecordsAggr
 	 */
 	public void insertColumn(ColumnInfoRecord col) {
 		records.add(col);
-		records.sort(CIRComparator.instance);
+		records.sort(ColumnInfoRecordsAggregate::compareColInfos);
 	}
 
 	/**
@@ -111,7 +102,7 @@ public final class ColumnInfoRecordsAggr
 		ColumnInfoRecord cirPrev = null;
 		for (ColumnInfoRecord cir : records) {
 			rv.visitRecord(cir);
-			if (cirPrev != null && CIRComparator.compareColInfos(cirPrev, cir) > 0) {
+			if (cirPrev != null && compareColInfos(cirPrev, cir) > 0) {
 				// Excel probably wouldn't mind, but there is much logic in this class
 				// that assumes the column info records are kept in order
 				throw new RuntimeException("Column info records are out of order");
@@ -290,7 +281,7 @@ public final class ColumnInfoRecordsAggr
 	}
 
 	private static ColumnInfoRecord copyColInfo(ColumnInfoRecord ci) {
-		return ci.clone();
+		return ci.copy();
 	}
 
 
@@ -554,4 +545,8 @@ public final class ColumnInfoRecordsAggr
 
 		return maxIndex;
 	}
+
+	private static int compareColInfos(ColumnInfoRecord a, ColumnInfoRecord b) {
+		return a.getFirstColumn()-b.getFirstColumn();
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java Sun Dec 22 21:44:45 2019
@@ -21,33 +21,26 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.poi.hssf.model.RecordStream;
-import org.apache.poi.hssf.record.CFHeader12Record;
-import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.CFHeaderBase;
 import org.apache.poi.ss.formula.FormulaShifter;
 
 /**
  * Holds all the conditional formatting for a workbook sheet.<p>
- * 
+ *
  * See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table'
  */
 public final class ConditionalFormattingTable extends RecordAggregate {
-	private final List<CFRecordsAggregate> _cfHeaders;
+	private final List<CFRecordsAggregate> _cfHeaders = new ArrayList<>();
 
 	/**
 	 * Creates an empty ConditionalFormattingTable
 	 */
-	public ConditionalFormattingTable() {
-		_cfHeaders = new ArrayList<>();
-	}
+	public ConditionalFormattingTable() {}
 
 	public ConditionalFormattingTable(RecordStream rs) {
-
-		List<CFRecordsAggregate> temp = new ArrayList<>();
-		while (rs.peekNextClass() == CFHeaderRecord.class ||
-		       rs.peekNextClass() == CFHeader12Record.class) {
-			temp.add(CFRecordsAggregate.createCFAggregate(rs));
+		while (rs.peekNextRecord() instanceof CFHeaderBase) {
+			_cfHeaders.add(CFRecordsAggregate.createCFAggregate(rs));
 		}
-		_cfHeaders = temp;
 	}
 
 	public void visitContainedRecords(RecordVisitor rv) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java Sun Dec 22 21:44:45 2019
@@ -56,9 +56,7 @@ public final class DataValidityTable ext
 			return;
 		}
 		rv.visitRecord(_headerRec);
-		for (int i = 0; i < _validationList.size(); i++) {
-			rv.visitRecord(_validationList.get(i));
-		}
+		_validationList.forEach(rv::visitRecord);
 	}
 
 	public void addDataValidation(DVRecord dvRecord) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java Sun Dec 22 21:44:45 2019
@@ -35,9 +35,6 @@ import org.apache.poi.util.RecordFormatE
 /**
  * The formula record aggregate is used to join together the formula record and it's
  * (optional) string record and (optional) Shared Formula Record (template reads, excel optimization).
- *
- * @author Glen Stampoultzis (glens at apache.org)
- * @author Vladimirs Abramovs(Vladimirs.Abramovs at exigenservices.com) - Array Formula support
  */
 public final class FormulaRecordAggregate extends RecordAggregate implements CellValueRecordInterface {
 
@@ -79,6 +76,7 @@ public final class FormulaRecordAggregat
 			}
 		}
 	}
+
 	/**
 	 * Sometimes the shared formula flag "seems" to be erroneously set (because the corresponding
 	 * {@link SharedFormulaRecord} does not exist). Normally this would leave no way of determining

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java Sun Dec 22 21:44:45 2019
@@ -25,12 +25,9 @@ import org.apache.poi.hssf.record.MergeC
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
 
-/**
- * 
- * @author Josh Micich
- */
 public final class MergedCellsTable extends RecordAggregate {
-	private static int MAX_MERGED_REGIONS = 1027; // enforced by the 8224 byte limit
+	// enforced by the 8224 byte limit
+	private static final int MAX_MERGED_REGIONS = 1027;
 
 	private final List<CellRangeAddress> _mergedRegions;
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java Sun Dec 22 21:44:45 2019
@@ -24,8 +24,6 @@ import org.apache.poi.hssf.record.Record
  * <tt>RecordAggregate</tt>s are groups of of BIFF <tt>Record</tt>s that are typically stored
  * together and/or updated together.  Workbook / Sheet records are typically stored in a sequential
  * list, which does not provide much structure to coordinate updates.
- *
- * @author Josh Micich
  */
 public abstract class RecordAggregate extends RecordBase {
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java Sun Dec 22 21:44:45 2019
@@ -24,7 +24,21 @@ import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.poi.hssf.model.RecordStream;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.ArrayRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.ContinueRecord;
+import org.apache.poi.hssf.record.DBCellRecord;
+import org.apache.poi.hssf.record.DConRefRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.FormulaRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.record.MulBlankRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
+import org.apache.poi.hssf.record.TableRecord;
+import org.apache.poi.hssf.record.UnknownRecord;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.formula.FormulaShifter;
 
@@ -116,7 +130,7 @@ public final class RowRecordsAggregate e
         // Integer integer = Integer.valueOf(row.getRowNumber());
         _rowRecords.put(Integer.valueOf(row.getRowNumber()), row);
         // Clear the cached values
-        _rowRecordValues = null; 
+        _rowRecordValues = null;
         if ((row.getRowNumber() < _firstrow) || (_firstrow == -1)) {
             _firstrow = row.getRowNumber();
         }
@@ -137,7 +151,7 @@ public final class RowRecordsAggregate e
             _rowRecords.put(key, rr);
             throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
         }
-        
+
         // Clear the cached values
         _rowRecordValues = null;
     }
@@ -260,7 +274,9 @@ public final class RowRecordsAggregate e
             // Serialize a block of cells for those rows
             final int startRowNumber = getStartRowNumberForBlock(blockIndex);
             final int endRowNumber = getEndRowNumberForBlock(blockIndex);
-            DBCellRecord.Builder dbcrBuilder = new DBCellRecord.Builder();
+
+            final List<Short> cellOffsets = new ArrayList<>();
+
             // Note: Cell references start from the second row...
             int cellRefOffset = (rowBlockSize - RowRecord.ENCODED_SIZE);
             for (int row = startRowNumber; row <= endRowNumber; row++) {
@@ -271,17 +287,25 @@ public final class RowRecordsAggregate e
                     pos += rowCellSize;
                     // Add the offset to the first cell for the row into the
                     // DBCellRecord.
-                    dbcrBuilder.addCellOffset(cellRefOffset);
+                    cellOffsets.add((short)cellRefOffset);
                     cellRefOffset = rowCellSize;
                 }
             }
             // Calculate Offset from the start of a DBCellRecord to the first Row
-            rv.visitRecord(dbcrBuilder.build(pos));
+            rv.visitRecord(new DBCellRecord(pos, shortListToArray(cellOffsets)));
         }
-        for (Record _unknownRecord : _unknownRecords) {
-            // Potentially breaking the file here since we don't know exactly where to write these records
-            rv.visitRecord(_unknownRecord);
+
+        // Potentially breaking the file here since we don't know exactly where to write these records
+        _unknownRecords.forEach(rv::visitRecord);
+    }
+
+    private static short[] shortListToArray(List<Short> list) {
+        final short[] arr = new short[list.size()];
+        int idx = 0;
+        for (Short s : list) {
+            arr[idx++] = s;
         }
+        return arr;
     }
 
     public Iterator<RowRecord> getIterator() {
@@ -434,7 +458,7 @@ public final class RowRecordsAggregate e
 
         return startHidden;
     }
-    
+
     /**
      * Returns an iterator for the cell values
      */

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java Sun Dec 22 21:44:45 2019
@@ -17,48 +17,49 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
 
 /**
  * Border Formatting Block of the Conditional Formatting Rule Record.
  */
-public final class BorderFormatting implements Cloneable {
+public final class BorderFormatting implements Duplicatable {
     /** No border */
-    public final static short    BORDER_NONE                = 0x0;
+    public static final short    BORDER_NONE                = 0x0;
     /** Thin border */
-    public final static short    BORDER_THIN                = 0x1;
+    public static final short    BORDER_THIN                = 0x1;
     /** Medium border */
-    public final static short    BORDER_MEDIUM              = 0x2;
+    public static final short    BORDER_MEDIUM              = 0x2;
     /** dash border */
-    public final static short    BORDER_DASHED              = 0x3;
+    public static final short    BORDER_DASHED              = 0x3;
     /** dot border */
-    public final static short    BORDER_HAIR                = 0x4;
+    public static final short    BORDER_HAIR                = 0x4;
     /** Thick border */
-    public final static short    BORDER_THICK               = 0x5;
+    public static final short    BORDER_THICK               = 0x5;
     /** double-line border */
-    public final static short    BORDER_DOUBLE              = 0x6;
+    public static final short    BORDER_DOUBLE              = 0x6;
     /** hair-line border */
-    public final static short    BORDER_DOTTED              = 0x7;
+    public static final short    BORDER_DOTTED              = 0x7;
     /** Medium dashed border */
-    public final static short    BORDER_MEDIUM_DASHED       = 0x8;
+    public static final short    BORDER_MEDIUM_DASHED       = 0x8;
     /** dash-dot border */
-    public final static short    BORDER_DASH_DOT            = 0x9;
+    public static final short    BORDER_DASH_DOT            = 0x9;
     /** medium dash-dot border */
-    public final static short    BORDER_MEDIUM_DASH_DOT     = 0xA;
+    public static final short    BORDER_MEDIUM_DASH_DOT     = 0xA;
     /** dash-dot-dot border */
-    public final static short    BORDER_DASH_DOT_DOT        = 0xB;
+    public static final short    BORDER_DASH_DOT_DOT        = 0xB;
     /** medium dash-dot-dot border */
-    public final static short    BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
+    public static final short    BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
     /** slanted dash-dot border */
-    public final static short    BORDER_SLANTED_DASH_DOT    = 0xD;
+    public static final short    BORDER_SLANTED_DASH_DOT    = 0xD;
 
     // BORDER FORMATTING BLOCK
     // For Border Line Style codes see HSSFCellStyle.BORDER_XXXXXX
-    private int              field_13_border_styles1;
     private static final BitField  bordLeftLineStyle  = BitFieldFactory.getInstance(0x0000000F);
     private static final BitField  bordRightLineStyle = BitFieldFactory.getInstance(0x000000F0);
     private static final BitField  bordTopLineStyle   = BitFieldFactory.getInstance(0x00000F00);
@@ -68,19 +69,26 @@ public final class BorderFormatting impl
     private static final BitField  bordTlBrLineOnOff  = BitFieldFactory.getInstance(0x40000000);
     private static final BitField  bordBlTrtLineOnOff = BitFieldFactory.getInstance(0x80000000);
 
-    private int              field_14_border_styles2;
     private static final BitField  bordTopLineColor   = BitFieldFactory.getInstance(0x0000007F);
     private static final BitField  bordBottomLineColor= BitFieldFactory.getInstance(0x00003f80);
     private static final BitField  bordDiagLineColor  = BitFieldFactory.getInstance(0x001FC000);
     private static final BitField  bordDiagLineStyle  = BitFieldFactory.getInstance(0x01E00000);
 
+    private int field_13_border_styles1;
+    private int field_14_border_styles2;
+
 
     public BorderFormatting() {
         field_13_border_styles1    = 0;
         field_14_border_styles2    = 0;
     }
 
-    /** Creates new FontFormatting */
+    public BorderFormatting(BorderFormatting other) {
+        field_13_border_styles1 = other.field_13_border_styles1;
+        field_14_border_styles2 = other.field_14_border_styles2;
+    }
+
+        /** Creates new FontFormatting */
     public BorderFormatting(LittleEndianInput in) {
         field_13_border_styles1    = in.readInt();
         field_14_border_styles2    = in.readInt();
@@ -447,11 +455,15 @@ public final class BorderFormatting impl
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public BorderFormatting clone() {
-      BorderFormatting rec = new BorderFormatting();
-      rec.field_13_border_styles1 = field_13_border_styles1;
-      rec.field_14_border_styles2 = field_14_border_styles2;
-      return rec;
+        return copy();
+    }
+
+    public BorderFormatting copy() {
+      return new BorderFormatting(this);
     }
 
     public int serialize(int offset, byte [] data) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java Sun Dec 22 21:44:45 2019
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import java.util.stream.Stream;
+
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.hssf.record.common.ExtendedColor;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
@@ -24,27 +27,39 @@ import org.apache.poi.util.LittleEndianI
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 
 /**
  * Color Gradient / Color Scale Conditional Formatting Rule Record.
  * (Called Color Gradient in the file format docs, but more commonly
  *  Color Scale in the UI)
  */
-public final class ColorGradientFormatting implements Cloneable {
-    private static POILogger log = POILogFactory.getLogger(ColorGradientFormatting.class);
+public final class ColorGradientFormatting implements Duplicatable {
+    private static final POILogger log = POILogFactory.getLogger(ColorGradientFormatting.class);
+
+    private static final BitField clamp = BitFieldFactory.getInstance(0x01);
+    private static final BitField background = BitFieldFactory.getInstance(0x02);
 
     private byte options;
     private ColorGradientThreshold[] thresholds;
     private ExtendedColor[] colors;
-    
-    private static BitField clamp = BitFieldFactory.getInstance(0x01);
-    private static BitField background = BitFieldFactory.getInstance(0x02);
-    
+
     public ColorGradientFormatting() {
         options = 3;
         thresholds = new ColorGradientThreshold[3];
-        colors = new ExtendedColor[3];  
+        colors = new ExtendedColor[3];
+    }
+
+    public ColorGradientFormatting(ColorGradientFormatting other) {
+        options = other.options;
+        if (other.thresholds != null) {
+            thresholds = Stream.of(other.thresholds).map(ColorGradientThreshold::copy).toArray(ColorGradientThreshold[]::new);
+        }
+        if (other.colors != null) {
+            colors = Stream.of(other.colors).map(ExtendedColor::copy).toArray(ExtendedColor[]::new);
+        }
     }
+
     public ColorGradientFormatting(LittleEndianInput in) {
         in.readShort(); // Ignored
         in.readByte();  // Reserved
@@ -54,7 +69,7 @@ public final class ColorGradientFormatti
             log.log(POILogger.WARN, "Inconsistent Color Gradient defintion, found " + numI + " vs " + numG + " entries");
         }
         options = in.readByte();
-        
+
         thresholds = new ColorGradientThreshold[numI];
         for (int i=0; i<thresholds.length; i++) {
             thresholds[i] = new ColorGradientThreshold(in);
@@ -65,7 +80,7 @@ public final class ColorGradientFormatti
             colors[i] = new ExtendedColor(in);
         }
     }
-    
+
     public int getNumControlPoints() {
         return thresholds.length;
     }
@@ -73,18 +88,18 @@ public final class ColorGradientFormatti
         if (num != thresholds.length) {
             ColorGradientThreshold[] nt = new ColorGradientThreshold[num];
             ExtendedColor[] nc = new ExtendedColor[num];
-            
+
             int copy = Math.min(thresholds.length, num);
             System.arraycopy(thresholds, 0, nt, 0, copy);
             System.arraycopy(colors, 0, nc, 0, copy);
-            
+
             this.thresholds = nt;
             this.colors = nc;
-            
+
             updateThresholdPositions();
         }
     }
-    
+
     public ColorGradientThreshold[] getThresholds() {
         return thresholds;
     }
@@ -99,7 +114,7 @@ public final class ColorGradientFormatti
     public void setColors(ExtendedColor[] colors) {
         this.colors = (colors == null) ? null : colors.clone();
     }
-    
+
     public boolean isClampToCurve() {
         return getOptionFlag(clamp);
     }
@@ -107,8 +122,7 @@ public final class ColorGradientFormatti
         return getOptionFlag(background);
     }
     private boolean getOptionFlag(BitField field) {
-        int value = field.getValue(options);
-        return value==0 ? false : true;
+        return field.isSet(options);
     }
 
     private void updateThresholdPositions() {
@@ -116,8 +130,8 @@ public final class ColorGradientFormatti
         for (int i=0; i<thresholds.length; i++) {
             thresholds[i].setPosition(step*i);
         }
-    }    
-    
+    }
+
     public String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append("    [Color Gradient Formatting]\n");
@@ -132,17 +146,19 @@ public final class ColorGradientFormatti
         buffer.append("    [/Color Gradient Formatting]\n");
         return buffer.toString();
     }
-    
-    public Object clone()  {
-      ColorGradientFormatting rec = new ColorGradientFormatting();
-      rec.options = options;
-      rec.thresholds = new ColorGradientThreshold[thresholds.length];
-      rec.colors = new ExtendedColor[colors.length];
-      System.arraycopy(thresholds, 0, rec.thresholds, 0, thresholds.length);
-      System.arraycopy(colors, 0, rec.colors, 0, colors.length);
-      return rec;
+
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public ColorGradientFormatting clone() {
+        return copy();
+    }
+
+    public ColorGradientFormatting copy()  {
+        return new ColorGradientFormatting(this);
     }
-    
+
     public int getDataLength() {
         int len = 6;
         for (Threshold t : thresholds) {
@@ -161,15 +177,15 @@ public final class ColorGradientFormatti
         out.writeByte(thresholds.length);
         out.writeByte(thresholds.length);
         out.writeByte(options);
-        
+
         for (ColorGradientThreshold t : thresholds) {
             t.serialize(out);
         }
-        
+
         double step = 1d / (colors.length-1);
         for (int i=0; i<colors.length; i++) {
             out.writeDouble(i*step);
-            
+
             ExtendedColor c = colors[i];
             c.serialize(out);
         }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java Sun Dec 22 21:44:45 2019
@@ -17,21 +17,27 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
 
 /**
  * Color Gradient / Color Scale specific Threshold / value (CFVO),
  *  for changes in Conditional Formatting
  */
-public final class ColorGradientThreshold extends Threshold implements Cloneable {
+public final class ColorGradientThreshold extends Threshold implements Duplicatable {
     private double position;
 
     public ColorGradientThreshold() {
-        super();
         position = 0d;
     }
 
+    public ColorGradientThreshold(ColorGradientThreshold other) {
+        super(other);
+        position = other.position;
+    }
+
     /** Creates new Color Gradient Threshold */
     public ColorGradientThreshold(LittleEndianInput in) {
         super(in);
@@ -50,11 +56,16 @@ public final class ColorGradientThreshol
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public ColorGradientThreshold clone() {
-      ColorGradientThreshold rec = new ColorGradientThreshold();
-      super.copyTo(rec);
-      rec.position = position;
-      return rec;
+        return copy();
+    }
+
+    @Override
+    public ColorGradientThreshold copy() {
+      return new ColorGradientThreshold(this);
     }
 
     public void serialize(LittleEndianOutput out) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java Sun Dec 22 21:44:45 2019
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.hssf.record.common.ExtendedColor;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
@@ -24,57 +25,68 @@ import org.apache.poi.util.LittleEndianI
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 
 /**
  * Data Bar Conditional Formatting Rule Record.
  */
-public final class DataBarFormatting implements Cloneable {
+public final class DataBarFormatting implements Duplicatable {
     private static POILogger log = POILogFactory.getLogger(DataBarFormatting.class);
 
+    private static final BitField iconOnly = BitFieldFactory.getInstance(0x01);
+    private static final BitField reversed = BitFieldFactory.getInstance(0x04);
+
     private byte options;
     private byte percentMin;
     private byte percentMax;
     private ExtendedColor color;
     private DataBarThreshold thresholdMin;
     private DataBarThreshold thresholdMax;
-    
-    private static BitField iconOnly = BitFieldFactory.getInstance(0x01);
-    private static BitField reversed = BitFieldFactory.getInstance(0x04);
-    
+
     public DataBarFormatting() {
         options = 2;
     }
+
+    public DataBarFormatting(DataBarFormatting other) {
+        options = other.options;
+        percentMin = other.percentMin;
+        percentMax = other.percentMax;
+        color = (other.color == null) ? null : other.color.copy();
+        thresholdMin = (other.thresholdMin == null) ? null : other.thresholdMin.copy();
+        thresholdMax = (other.thresholdMax == null) ? null : other.thresholdMax.copy();
+    }
+
     public DataBarFormatting(LittleEndianInput in) {
         in.readShort(); // Ignored
         in.readByte();  // Reserved
         options = in.readByte();
-        
+
         percentMin = in.readByte();
         percentMax = in.readByte();
         if (percentMin < 0 || percentMin > 100)
             log.log(POILogger.WARN, "Inconsistent Minimum Percentage found " + percentMin);
         if (percentMax < 0 || percentMax > 100)
             log.log(POILogger.WARN, "Inconsistent Minimum Percentage found " + percentMin);
-        
+
         color = new ExtendedColor(in);
         thresholdMin = new DataBarThreshold(in);
         thresholdMax = new DataBarThreshold(in);
     }
-    
+
     public boolean isIconOnly() {
         return getOptionFlag(iconOnly);
     }
     public void setIconOnly(boolean only) {
         setOptionFlag(only, iconOnly);
     }
-    
+
     public boolean isReversed() {
         return getOptionFlag(reversed);
     }
     public void setReversed(boolean rev) {
         setOptionFlag(rev, reversed);
     }
-    
+
     private boolean getOptionFlag(BitField field) {
         int value = field.getValue(options);
         return value==0 ? false : true;
@@ -89,35 +101,35 @@ public final class DataBarFormatting imp
     public void setPercentMin(byte percentMin) {
         this.percentMin = percentMin;
     }
-    
+
     public byte getPercentMax() {
         return percentMax;
     }
     public void setPercentMax(byte percentMax) {
         this.percentMax = percentMax;
     }
-    
+
     public ExtendedColor getColor() {
         return color;
     }
     public void setColor(ExtendedColor color) {
         this.color = color;
     }
-    
+
     public DataBarThreshold getThresholdMin() {
         return thresholdMin;
     }
     public void setThresholdMin(DataBarThreshold thresholdMin) {
         this.thresholdMin = thresholdMin;
     }
-    
+
     public DataBarThreshold getThresholdMax() {
         return thresholdMax;
     }
     public void setThresholdMax(DataBarThreshold thresholdMax) {
         this.thresholdMax = thresholdMax;
     }
-    
+
     public String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append("    [Data Bar Formatting]\n");
@@ -129,21 +141,22 @@ public final class DataBarFormatting imp
         buffer.append("    [/Data Bar Formatting]\n");
         return buffer.toString();
     }
-    
-    public Object clone()  {
-      DataBarFormatting rec = new DataBarFormatting();
-      rec.options = options;
-      rec.percentMin = percentMin;
-      rec.percentMax = percentMax;
-      rec.color = color.clone();
-      rec.thresholdMin = thresholdMin.clone();
-      rec.thresholdMax = thresholdMax.clone();
-      return rec;
+
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public DataBarFormatting clone()  {
+        return copy();
+    }
+
+    public DataBarFormatting copy()  {
+      return new DataBarFormatting(this);
     }
-    
+
     public int getDataLength() {
         return 6 + color.getDataLength() +
-               thresholdMin.getDataLength() + 
+               thresholdMin.getDataLength() +
                thresholdMax.getDataLength();
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarThreshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarThreshold.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarThreshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/DataBarThreshold.java Sun Dec 22 21:44:45 2019
@@ -17,26 +17,38 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.Removal;
 
 /**
  * Data Bar specific Threshold / value (CFVO),
  *  for changes in Conditional Formatting
  */
-public final class DataBarThreshold extends Threshold implements Cloneable {
+public final class DataBarThreshold extends Threshold implements Duplicatable {
     public DataBarThreshold() {
         super();
     }
 
+    public DataBarThreshold(DataBarThreshold other) {
+        super(other);
+    }
+
     /** Creates new Data Bar Threshold */
     public DataBarThreshold(LittleEndianInput in) {
         super(in);
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public DataBarThreshold clone() {
-      DataBarThreshold rec = new DataBarThreshold();
-      super.copyTo(rec);
-      return rec;
+        return copy();
+    }
+
+    @Override
+    public DataBarThreshold copy() {
+      return new DataBarThreshold(this);
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java Sun Dec 22 21:44:45 2019
@@ -20,17 +20,17 @@ package org.apache.poi.hssf.record.cf;
 
 import java.util.Locale;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.Removal;
 
 /**
  * Font Formatting Block of the Conditional Formatting Rule Record.
  */
-public final class FontFormatting implements Cloneable {
-    private final byte[] _rawData = new byte[RAW_DATA_SIZE];
-
+public final class FontFormatting implements Duplicatable {
     private static final int OFFSET_FONT_NAME = 0;
     private static final int OFFSET_FONT_HEIGHT = 64;
     private static final int OFFSET_FONT_OPTIONS = 68;
@@ -49,7 +49,7 @@ public final class FontFormatting implem
     private static final int RAW_DATA_SIZE = 118;
 
 
-    public final static int  FONT_CELL_HEIGHT_PRESERVED   = 0xFFFFFFFF;
+    public static final int  FONT_CELL_HEIGHT_PRESERVED   = 0xFFFFFFFF;
 
     // FONT OPTIONS MASKS
     private static final BitField posture       = BitFieldFactory.getInstance(0x00000002);
@@ -88,6 +88,8 @@ public final class FontFormatting implem
      */
     private static final short FONT_WEIGHT_BOLD	 = 0x2bc;
 
+    private final byte[] _rawData = new byte[RAW_DATA_SIZE];
+
     public FontFormatting() {
         setFontHeight(-1);
         setItalic(false);
@@ -114,11 +116,12 @@ public final class FontFormatting implem
         setShort(OFFSET_FONT_FORMATING_END, 0x0001);
     }
 
-    /** Creates new FontFormatting */
+    public FontFormatting(FontFormatting other) {
+        System.arraycopy(other._rawData, 0, _rawData, 0, _rawData.length);
+    }
+
     public FontFormatting(RecordInputStream in) {
-        for (int i = 0; i < _rawData.length; i++) {
-            _rawData[i] = in.readByte();
-        }
+        in.readFully(_rawData);
     }
 
     private short getShort(int offset) {
@@ -499,7 +502,7 @@ public final class FontFormatting implem
             append(getFontWeight()).
             append(
                     getFontWeight() == FONT_WEIGHT_NORMAL ? "(Normal)"
-                    : getFontWeight() == FONT_WEIGHT_BOLD ? "(Bold)" 
+                    : getFontWeight() == FONT_WEIGHT_BOLD ? "(Bold)"
                     : "0x"+Integer.toHexString(getFontWeight())).
             append("\n");
         }
@@ -533,9 +536,15 @@ public final class FontFormatting implem
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public FontFormatting clone() {
-        FontFormatting other = new FontFormatting();
-        System.arraycopy(_rawData, 0, other._rawData, 0, _rawData.length);
-        return other;
+        return copy();
+    }
+
+    @Override
+    public FontFormatting copy() {
+        return new FontFormatting(this);
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java Sun Dec 22 21:44:45 2019
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import java.util.stream.Stream;
+
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
@@ -24,17 +27,18 @@ import org.apache.poi.util.LittleEndianI
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 
 /**
  * Icon / Multi-State Conditional Formatting Rule Record.
  */
-public final class IconMultiStateFormatting implements Cloneable {
-    private static POILogger log = POILogFactory.getLogger(IconMultiStateFormatting.class);
-            
+public final class IconMultiStateFormatting implements Duplicatable {
+    private static final POILogger log = POILogFactory.getLogger(IconMultiStateFormatting.class);
+
     private IconSet iconSet;
     private byte options;
     private Threshold[] thresholds;
-    
+
     private static BitField iconOnly = BitFieldFactory.getInstance(0x01);
     private static BitField reversed = BitFieldFactory.getInstance(0x04);
 
@@ -43,6 +47,15 @@ public final class IconMultiStateFormatt
         options = 0;
         thresholds = new Threshold[iconSet.num];
     }
+
+    public IconMultiStateFormatting(IconMultiStateFormatting other) {
+        iconSet = other.iconSet;
+        options = other.options;
+        if (other.thresholds != null) {
+            thresholds = Stream.of(other.thresholds).map(Threshold::copy).toArray(Threshold[]::new);
+        }
+    }
+
     public IconMultiStateFormatting(LittleEndianInput in) {
         in.readShort(); // Ignored
         in.readByte();  // Reserved
@@ -53,13 +66,13 @@ public final class IconMultiStateFormatt
             log.log(POILogger.WARN, "Inconsistent Icon Set defintion, found " + iconSet + " but defined as " + num + " entries");
         }
         options = in.readByte();
-        
+
         thresholds = new Threshold[iconSet.num];
         for (int i=0; i<thresholds.length; i++) {
             thresholds[i] = new IconMultiStateThreshold(in);
         }
     }
-    
+
     public IconSet getIconSet() {
         return iconSet;
     }
@@ -73,21 +86,21 @@ public final class IconMultiStateFormatt
     public void setThresholds(Threshold[] thresholds) {
         this.thresholds = (thresholds == null) ? null : thresholds.clone();
     }
-    
+
     public boolean isIconOnly() {
         return getOptionFlag(iconOnly);
     }
     public void setIconOnly(boolean only) {
         setOptionFlag(only, iconOnly);
     }
-    
+
     public boolean isReversed() {
         return getOptionFlag(reversed);
     }
     public void setReversed(boolean rev) {
         setOptionFlag(rev, reversed);
     }
-    
+
     private boolean getOptionFlag(BitField field) {
         int value = field.getValue(options);
         return value==0 ? false : true;
@@ -95,7 +108,7 @@ public final class IconMultiStateFormatt
     private void setOptionFlag(boolean option, BitField field) {
         options = field.setByteBoolean(options, option);
     }
-    
+
     public String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append("    [Icon Formatting]\n");
@@ -108,16 +121,20 @@ public final class IconMultiStateFormatt
         buffer.append("    [/Icon Formatting]\n");
         return buffer.toString();
     }
-    
-    public Object clone()  {
-      IconMultiStateFormatting rec = new IconMultiStateFormatting();
-      rec.iconSet = iconSet;
-      rec.options = options;
-      rec.thresholds = new Threshold[thresholds.length];
-      System.arraycopy(thresholds, 0, rec.thresholds, 0, thresholds.length);
-      return rec;
+
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public IconMultiStateFormatting clone()  {
+        return copy();
+    }
+
+    @Override
+    public IconMultiStateFormatting copy()  {
+        return new IconMultiStateFormatting(this);
     }
-    
+
     public int getDataLength() {
         int len = 6;
         for (Threshold t : thresholds) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java Sun Dec 22 21:44:45 2019
@@ -17,14 +17,16 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
 
 /**
  * Icon / Multi-State specific Threshold / value (CFVO),
  *  for changes in Conditional Formatting
  */
-public final class IconMultiStateThreshold extends Threshold implements Cloneable {
+public final class IconMultiStateThreshold extends Threshold implements Duplicatable {
     /**
      * Cell values that are equal to the threshold value do not pass the threshold
      */
@@ -33,15 +35,18 @@ public final class IconMultiStateThresho
      * Cell values that are equal to the threshold value pass the threshold.
      */
     public static final byte EQUALS_INCLUDE = 1;
-    
+
     private byte equals;
 
     public IconMultiStateThreshold() {
-        super();
         equals = EQUALS_INCLUDE;
     }
 
-    /** Creates new Ico Multi-State Threshold */
+    public IconMultiStateThreshold(IconMultiStateThreshold other) {
+        super(other);
+        equals = other.equals;
+    }
+
     public IconMultiStateThreshold(LittleEndianInput in) {
         super(in);
         equals = in.readByte();
@@ -61,11 +66,16 @@ public final class IconMultiStateThresho
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public IconMultiStateThreshold clone() {
-      IconMultiStateThreshold rec = new IconMultiStateThreshold();
-      super.copyTo(rec);
-      rec.equals = equals;
-      return rec;
+        return copy();
+    }
+
+    @Override
+    public IconMultiStateThreshold copy() {
+        return new IconMultiStateThreshold(this);
     }
 
     public void serialize(LittleEndianOutput out) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java Sun Dec 22 21:44:45 2019
@@ -17,80 +17,87 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.common.Duplicatable;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
 
 /**
  * Pattern Formatting Block of the Conditional Formatting Rule Record.
  */
-public final class PatternFormatting implements Cloneable {
+public final class PatternFormatting implements Duplicatable {
     /**  No background */
-    public final static short     NO_FILL             = 0  ;
+    public static final short     NO_FILL             = 0  ;
     /**  Solidly filled */
-    public final static short     SOLID_FOREGROUND    = 1  ;
+    public static final short     SOLID_FOREGROUND    = 1  ;
     /**  Small fine dots */
-    public final static short     FINE_DOTS           = 2  ;
+    public static final short     FINE_DOTS           = 2  ;
     /**  Wide dots */
-    public final static short     ALT_BARS            = 3  ;
+    public static final short     ALT_BARS            = 3  ;
     /**  Sparse dots */
-    public final static short     SPARSE_DOTS         = 4  ;
+    public static final short     SPARSE_DOTS         = 4  ;
     /**  Thick horizontal bands */
-    public final static short     THICK_HORZ_BANDS    = 5  ;
+    public static final short     THICK_HORZ_BANDS    = 5  ;
     /**  Thick vertical bands */
-    public final static short     THICK_VERT_BANDS    = 6  ;
+    public static final short     THICK_VERT_BANDS    = 6  ;
     /**  Thick backward facing diagonals */
-    public final static short     THICK_BACKWARD_DIAG = 7  ;
+    public static final short     THICK_BACKWARD_DIAG = 7  ;
     /**  Thick forward facing diagonals */
-    public final static short     THICK_FORWARD_DIAG  = 8  ;
+    public static final short     THICK_FORWARD_DIAG  = 8  ;
     /**  Large spots */
-    public final static short     BIG_SPOTS           = 9  ;
+    public static final short     BIG_SPOTS           = 9  ;
     /**  Brick-like layout */
-    public final static short     BRICKS              = 10 ;
+    public static final short     BRICKS              = 10 ;
     /**  Thin horizontal bands */
-    public final static short     THIN_HORZ_BANDS     = 11 ;
+    public static final short     THIN_HORZ_BANDS     = 11 ;
     /**  Thin vertical bands */
-    public final static short     THIN_VERT_BANDS     = 12 ;
+    public static final short     THIN_VERT_BANDS     = 12 ;
     /**  Thin backward diagonal */
-    public final static short     THIN_BACKWARD_DIAG  = 13 ;
+    public static final short     THIN_BACKWARD_DIAG  = 13 ;
     /**  Thin forward diagonal */
-    public final static short     THIN_FORWARD_DIAG   = 14 ;
+    public static final short     THIN_FORWARD_DIAG   = 14 ;
     /**  Squares */
-    public final static short     SQUARES             = 15 ;
+    public static final short     SQUARES             = 15 ;
     /**  Diamonds */
-    public final static short     DIAMONDS            = 16 ;
+    public static final short     DIAMONDS            = 16 ;
     /**  Less Dots */
-    public final static short     LESS_DOTS           = 17 ;
+    public static final short     LESS_DOTS           = 17 ;
     /**  Least Dots */
-    public final static short     LEAST_DOTS          = 18 ;
-    
-    
+    public static final short     LEAST_DOTS          = 18 ;
+
+
     // PATTERN FORMATING BLOCK
     // For Pattern Styles see constants at HSSFCellStyle (from NO_FILL to LEAST_DOTS)
-    private int              field_15_pattern_style;
     private static final BitField  fillPatternStyle = BitFieldFactory.getInstance(0xFC00);
-    
-    private int              field_16_pattern_color_indexes;
-    private static final BitField  patternColorIndex = BitFieldFactory.getInstance(0x007F);         
-    private static final BitField  patternBackgroundColorIndex = BitFieldFactory.getInstance(0x3F80);         
 
-    
+    private static final BitField  patternColorIndex = BitFieldFactory.getInstance(0x007F);
+    private static final BitField  patternBackgroundColorIndex = BitFieldFactory.getInstance(0x3F80);
+
+    private int field_15_pattern_style;
+    private int field_16_pattern_color_indexes;
+
+
     public PatternFormatting() {
-        field_15_pattern_style    = 0;
-        field_16_pattern_color_indexes    = 0;
+        field_15_pattern_style = 0;
+        field_16_pattern_color_indexes = 0;
+    }
+
+    public PatternFormatting(PatternFormatting other) {
+        field_15_pattern_style = other.field_15_pattern_style;
+        field_16_pattern_color_indexes = other.field_16_pattern_color_indexes;
     }
-    
-    /** Creates new FontFormatting */
+
     public PatternFormatting(LittleEndianInput in) {
         field_15_pattern_style    = in.readUShort();
         field_16_pattern_color_indexes    = in.readUShort();
     }
-    
+
     public int getDataLength() {
         return 4;
     }
-    
+
     /**
      * setting fill pattern
      *
@@ -112,7 +119,7 @@ public final class PatternFormatting imp
      * @see #SQUARES
      * @see #DIAMONDS
      *
-     * @param fp  fill pattern 
+     * @param fp  fill pattern
      */
     public void setFillPattern(int fp) {
         field_15_pattern_style = fillPatternStyle.setValue(field_15_pattern_style, fp);
@@ -124,11 +131,11 @@ public final class PatternFormatting imp
     public int getFillPattern() {
         return fillPatternStyle.getValue(field_15_pattern_style);
     }
-    
+
     /**
      * set the background fill color.
      */
-    public void setFillBackgroundColor(int bg) {        
+    public void setFillBackgroundColor(int bg) {
         field_16_pattern_color_indexes = patternBackgroundColorIndex.setValue(field_16_pattern_color_indexes,bg);
     }
 
@@ -154,7 +161,7 @@ public final class PatternFormatting imp
     public int getFillForegroundColor() {
         return patternColorIndex.getValue(field_16_pattern_color_indexes);
     }
-    
+
     public String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append("    [Pattern Formatting]\n");
@@ -164,12 +171,17 @@ public final class PatternFormatting imp
         buffer.append("    [/Pattern Formatting]\n");
         return buffer.toString();
     }
-    
-    public Object clone()  {
-      PatternFormatting rec = new PatternFormatting();
-      rec.field_15_pattern_style = field_15_pattern_style;
-      rec.field_16_pattern_color_indexes = field_16_pattern_color_indexes; 
-      return rec;
+
+    @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
+    public PatternFormatting clone()  {
+        return copy();
+    }
+
+    public PatternFormatting copy()  {
+        return new PatternFormatting(this);
     }
 
     public void serialize(LittleEndianOutput out) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java Sun Dec 22 21:44:45 2019
@@ -39,6 +39,12 @@ public abstract class Threshold {
         value = 0d;
     }
 
+    protected Threshold(Threshold other) {
+        type = other.type;
+        formula = other.formula.copy();
+        value = other.value;
+    }
+
     /** Creates new Threshold */
     protected Threshold(LittleEndianInput in) {
         type = in.readByte();
@@ -92,7 +98,7 @@ public abstract class Threshold {
     public void setValue(Double value) {
         this.value = value;
     }
-    
+
     public int getDataLength() {
         int len = 1 + formula.getEncodedSize();
         if (value != null) {
@@ -111,12 +117,6 @@ public abstract class Threshold {
         return buffer.toString();
     }
 
-    public void copyTo(Threshold rec) {
-      rec.type = type;
-      rec.formula = formula;
-      rec.value = value;
-    }
-
     public void serialize(LittleEndianOutput out) {
         out.writeByte(type);
         if (formula.getTokens().length == 0) {
@@ -128,4 +128,6 @@ public abstract class Threshold {
             out.writeDouble(value);
         }
     }
+
+    public abstract Threshold copy();
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/chart/AreaFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/chart/AreaFormatRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/chart/AreaFormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/chart/AreaFormatRecord.java Sun Dec 22 21:44:45 2019
@@ -23,18 +23,17 @@ 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;
 
 /**
- * The area format record is used to define the colours and patterns for an area.<p>
- * 
- * @author Glen Stampoultzis (glens at apache.org)
+ * The area format record is used to define the colours and patterns for an area.
  */
-public final class AreaFormatRecord extends StandardRecord implements Cloneable {
-    public final static short sid = 0x100A;
-    
+public final class AreaFormatRecord extends StandardRecord {
+    public static final short sid = 0x100A;
+
     private static final BitField automatic = BitFieldFactory.getInstance(0x1);
     private static final BitField invert    = BitFieldFactory.getInstance(0x2);
-    
+
     private  int        field_1_foregroundColor;
     private  int        field_2_backgroundColor;
     private  short      field_3_pattern;
@@ -43,20 +42,25 @@ public final class AreaFormatRecord exte
     private  short      field_6_backcolorIndex;
 
 
-    public AreaFormatRecord()
-    {
+    public AreaFormatRecord() {}
 
-    }
-
-    public AreaFormatRecord(RecordInputStream in)
-    {
+    public AreaFormatRecord(RecordInputStream in) {
         field_1_foregroundColor        = in.readInt();
         field_2_backgroundColor        = in.readInt();
         field_3_pattern                = in.readShort();
         field_4_formatFlags            = in.readShort();
         field_5_forecolorIndex         = in.readShort();
         field_6_backcolorIndex         = in.readShort();
+    }
 
+    public AreaFormatRecord(AreaFormatRecord other) {
+        super(other);
+        field_1_foregroundColor        = other.field_1_foregroundColor;
+        field_2_backgroundColor        = other.field_2_backgroundColor;
+        field_3_pattern                = other.field_3_pattern;
+        field_4_formatFlags            = other.field_4_formatFlags;
+        field_5_forecolorIndex         = other.field_5_forecolorIndex;
+        field_6_backcolorIndex         = other.field_6_backcolorIndex;
     }
 
     public String toString()
@@ -67,29 +71,29 @@ public final class AreaFormatRecord exte
         buffer.append("    .foregroundColor      = ")
             .append("0x").append(HexDump.toHex(  getForegroundColor ()))
             .append(" (").append( getForegroundColor() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
+        buffer.append(System.getProperty("line.separator"));
         buffer.append("    .backgroundColor      = ")
             .append("0x").append(HexDump.toHex(  getBackgroundColor ()))
             .append(" (").append( getBackgroundColor() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
+        buffer.append(System.getProperty("line.separator"));
         buffer.append("    .pattern              = ")
             .append("0x").append(HexDump.toHex(  getPattern ()))
             .append(" (").append( getPattern() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
+        buffer.append(System.getProperty("line.separator"));
         buffer.append("    .formatFlags          = ")
             .append("0x").append(HexDump.toHex(  getFormatFlags ()))
             .append(" (").append( getFormatFlags() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
-        buffer.append("         .automatic                = ").append(isAutomatic()).append('\n'); 
-        buffer.append("         .invert                   = ").append(isInvert()).append('\n'); 
+        buffer.append(System.getProperty("line.separator"));
+        buffer.append("         .automatic                = ").append(isAutomatic()).append('\n');
+        buffer.append("         .invert                   = ").append(isInvert()).append('\n');
         buffer.append("    .forecolorIndex       = ")
             .append("0x").append(HexDump.toHex(  getForecolorIndex ()))
             .append(" (").append( getForecolorIndex() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
+        buffer.append(System.getProperty("line.separator"));
         buffer.append("    .backcolorIndex       = ")
             .append("0x").append(HexDump.toHex(  getBackcolorIndex ()))
             .append(" (").append( getBackcolorIndex() ).append(" )");
-        buffer.append(System.getProperty("line.separator")); 
+        buffer.append(System.getProperty("line.separator"));
 
         buffer.append("[/AREAFORMAT]\n");
         return buffer.toString();
@@ -114,21 +118,13 @@ public final class AreaFormatRecord exte
     }
 
     @Override
+    @SuppressWarnings("squid:S2975")
+    @Deprecated
+    @Removal(version = "5.0.0")
     public AreaFormatRecord clone() {
-        AreaFormatRecord rec = new AreaFormatRecord();
-    
-        rec.field_1_foregroundColor = field_1_foregroundColor;
-        rec.field_2_backgroundColor = field_2_backgroundColor;
-        rec.field_3_pattern = field_3_pattern;
-        rec.field_4_formatFlags = field_4_formatFlags;
-        rec.field_5_forecolorIndex = field_5_forecolorIndex;
-        rec.field_6_backcolorIndex = field_6_backcolorIndex;
-        return rec;
+        return copy();
     }
 
-
-
-
     /**
      * Get the foreground color field for the AreaFormat record.
      */
@@ -260,4 +256,9 @@ public final class AreaFormatRecord exte
     {
         return invert.isSet(field_4_formatFlags);
     }
+
+    @Override
+    public AreaFormatRecord copy() {
+        return new AreaFormatRecord(this);
+    }
 }



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