You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/06/13 00:43:34 UTC
svn commit: r1748072 - in /poi/branches/ss_border_property_template/src:
java/org/apache/poi/ss/util/BorderPropertyTemplate.java
testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java
Author: onealj
Date: Mon Jun 13 00:43:34 2016
New Revision: 1748072
URL: http://svn.apache.org/viewvc?rev=1748072&view=rev
Log:
add copy constructor
Modified:
poi/branches/ss_border_property_template/src/java/org/apache/poi/ss/util/BorderPropertyTemplate.java
poi/branches/ss_border_property_template/src/testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java
Modified: poi/branches/ss_border_property_template/src/java/org/apache/poi/ss/util/BorderPropertyTemplate.java
URL: http://svn.apache.org/viewvc/poi/branches/ss_border_property_template/src/java/org/apache/poi/ss/util/BorderPropertyTemplate.java?rev=1748072&r1=1748071&r2=1748072&view=diff
==============================================================================
--- poi/branches/ss_border_property_template/src/java/org/apache/poi/ss/util/BorderPropertyTemplate.java (original)
+++ poi/branches/ss_border_property_template/src/java/org/apache/poi/ss/util/BorderPropertyTemplate.java Mon Jun 13 00:43:34 2016
@@ -198,6 +198,30 @@ public final class BorderPropertyTemplat
}
/**
+ * Copy constructor
+ *
+ * Create a template from an existing template.
+ * Changes made to either template do not affect the other template.
+ * @since 3.15 beta 2
+ */
+ public BorderPropertyTemplate(BorderPropertyTemplate prototype) {
+ this();
+ // deep copy the _propertyTemplate map from prototype
+ for (Entry<CellAddress, Map<String, Object>> other : prototype._propertyTemplate.entrySet()) {
+ CellAddress cell = other.getKey();
+ Map<String, Object> otherMap = other.getValue();
+
+ // The keys in otherMap are immutable Strings
+ // The values in otherMap are immutable Shorts or BorderStyles
+ // Therefore, this map's data cannot be modified through protoype
+ Map<String, Object> map = new HashMap<String, Object>(otherMap);
+
+ // CellAddress is an immutable class, therefore it is ok to reference the same instance
+ _propertyTemplate.put(cell, map);
+ }
+ }
+
+ /**
* Add a group of cell borders for a cell range to the border property template.
* The borders are not applied to the cells at this time, just the template is drawn
* (<code>drawBorders</code> stages changes using the border property template).
Modified: poi/branches/ss_border_property_template/src/testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java
URL: http://svn.apache.org/viewvc/poi/branches/ss_border_property_template/src/testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java?rev=1748072&r1=1748071&r2=1748072&view=diff
==============================================================================
--- poi/branches/ss_border_property_template/src/testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java (original)
+++ poi/branches/ss_border_property_template/src/testcases/org/apache/poi/ss/util/TestBorderPropertyTemplate.java Mon Jun 13 00:43:34 2016
@@ -18,6 +18,7 @@
package org.apache.poi.ss.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
@@ -44,6 +45,37 @@ public final class TestBorderPropertyTem
private static final short AUTOMATIC = IndexedColors.AUTOMATIC.getIndex();
@Test
+ public void createTemplateFromExisting() throws IOException {
+ CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellRangeAddress b2b2 = new CellRangeAddress(1, 1, 1, 1); //B2:B2
+ CellRangeAddress c3c3 = new CellRangeAddress(2, 2, 2, 2); //C3:C3
+ CellAddress a1 = new CellAddress(0, 0); //A1
+ CellAddress b2 = new CellAddress(1, 1); //B2
+ CellAddress c3 = new CellAddress(2, 2); //C3
+
+ BorderPropertyTemplate pt1 = new BorderPropertyTemplate();
+ pt1.drawBorders(a1a1, BorderStyle.THIN, RED, BorderExtent.TOP);
+
+ // check to make sure borders were copied
+ BorderPropertyTemplate pt2 = new BorderPropertyTemplate(pt1);
+ assertEquals(1, pt2.getNumBorders(a1));
+ assertThin(pt2.getTemplateProperty(a1, CellUtil.BORDER_TOP));
+ assertRed(pt2.getTemplateProperty(a1, CellUtil.TOP_BORDER_COLOR));
+
+ // Changes to original template should not affect copied template.
+ pt1.drawBorders(b2b2, BorderStyle.THIN, RED, BorderExtent.TOP);
+ assertEquals(0, pt2.getNumBorders(b2));
+ assertNull(pt2.getTemplateProperty(b2, CellUtil.BORDER_TOP));
+ assertNull(pt2.getTemplateProperty(b2, CellUtil.TOP_BORDER_COLOR));
+
+ // Changes to copied template should not affect original template
+ pt2.drawBorders(c3c3, BorderStyle.THIN, RED, BorderExtent.TOP);
+ assertEquals(0, pt1.getNumBorders(c3));
+ assertNull(pt1.getTemplateProperty(c3, CellUtil.BORDER_TOP));
+ assertNull(pt1.getTemplateProperty(c3, CellUtil.TOP_BORDER_COLOR));
+ }
+
+ @Test
public void getNumBorders() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
CellAddress a1 = new CellAddress(0, 0); //A1
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org