bug 58348: use copy constructor design pattern rather than cloneable pattern for CellCopyPolicy

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1716074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2015-11-24 08:52:45 +00:00
parent fc4b3fc08f
commit d84be50d54
2 changed files with 21 additions and 8 deletions

View File

@ -20,7 +20,7 @@ package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
@Beta @Beta
public class CellCopyPolicy implements Cloneable { public class CellCopyPolicy {
// cell-level policies // cell-level policies
public static final boolean DEFAULT_COPY_CELL_VALUE_POLICY = true; public static final boolean DEFAULT_COPY_CELL_VALUE_POLICY = true;
public static final boolean DEFAULT_COPY_CELL_STYLE_POLICY = true; public static final boolean DEFAULT_COPY_CELL_STYLE_POLICY = true;
@ -55,6 +55,24 @@ public class CellCopyPolicy implements Cloneable {
*/ */
public CellCopyPolicy() { } 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 // should builder be replaced with CellCopyPolicy setters that return the object
// to allow setters to be chained together? // to allow setters to be chained together?
// policy.setCopyCellValue(true).setCopyCellStyle(true) // 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() final Builder builder = new Builder()
.cellValue(copyCellValue) .cellValue(copyCellValue)
.cellStyle(copyCellStyle) .cellStyle(copyCellStyle)
@ -147,11 +165,6 @@ public class CellCopyPolicy implements Cloneable {
return builder; return builder;
} }
@Override
public CellCopyPolicy clone() {
return createBuilder().build();
}
/* /*
* Cell-level policies * Cell-level policies
*/ */

View 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? // 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 // avoid O(N^2) performance scanning through all regions for each row
// merged regions will be copied after all the rows have been copied // merged regions will be copied after all the rows have been copied
options.setCopyMergedRegions(false); options.setCopyMergedRegions(false);