]> source.dussan.org Git - poi.git/commitdiff
bug 58348: use copy constructor design pattern rather than cloneable pattern for...
authorJaven O'Neal <onealj@apache.org>
Tue, 24 Nov 2015 08:52:45 +0000 (08:52 +0000)
committerJaven O'Neal <onealj@apache.org>
Tue, 24 Nov 2015 08:52:45 +0000 (08:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1716074 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/CellCopyPolicy.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index 80043210a6b9e363ddc1c9e44371921ee9b5dab7..8a0377b9a8ba72bec1affe8be3cb12ab135238f0 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.poi.ss.usermodel;
 import org.apache.poi.util.Beta;
 
 @Beta
-public class CellCopyPolicy implements Cloneable {
+public class CellCopyPolicy {
     // cell-level policies
     public static final boolean DEFAULT_COPY_CELL_VALUE_POLICY = true;
     public static final boolean DEFAULT_COPY_CELL_STYLE_POLICY = true;
@@ -55,6 +55,24 @@ public class CellCopyPolicy implements Cloneable {
      */
     public CellCopyPolicy() { }
     
+    /**
+     * Copy constructor
+     *
+     * @param other policy to copy
+     */
+    public CellCopyPolicy(CellCopyPolicy other) {
+        copyCellValue = other.isCopyCellValue();
+        copyCellStyle = other.isCopyCellStyle();
+        copyCellFormula = other.isCopyCellFormula();
+        copyHyperlink = other.isCopyHyperlink();
+        mergeHyperlink = other.isMergeHyperlink();
+        
+        copyRowHeight = other.isCopyRowHeight();
+        condenseRows = other.isCondenseRows();
+        
+        copyMergedRegions = other.isCopyMergedRegions();
+    }
+    
     // should builder be replaced with CellCopyPolicy setters that return the object
     // to allow setters to be chained together?
     // policy.setCopyCellValue(true).setCopyCellStyle(true)
@@ -134,7 +152,7 @@ public class CellCopyPolicy implements Cloneable {
         }
     }
     
-    private Builder createBuilder() {
+    public Builder createBuilder() {
         final Builder builder = new Builder()
                 .cellValue(copyCellValue)
                 .cellStyle(copyCellStyle)
@@ -146,11 +164,6 @@ public class CellCopyPolicy implements Cloneable {
                 .mergedRegions(copyMergedRegions);
         return builder;
     }
-    
-    @Override
-    public CellCopyPolicy clone() {
-        return createBuilder().build();
-    }
 
 /*
  * Cell-level policies 
index 379a675bba6438468b2e5b0c10db6bc9f112bc3d..fd3674b3e040bd0875c91b654ddf27f5efbed81e 100644 (file)
@@ -2705,7 +2705,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         
         // FIXME: is special behavior needed if srcRows and destRows belong to the same sheets and the regions overlap?
         
-        final CellCopyPolicy options = policy.clone();
+        final CellCopyPolicy options = new CellCopyPolicy(policy);
         // avoid O(N^2) performance scanning through all regions for each row
         // merged regions will be copied after all the rows have been copied
         options.setCopyMergedRegions(false);