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/12 22:33:24 UTC
svn commit: r1748065 - 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: Sun Jun 12 22:33:24 2016
New Revision: 1748065
URL: http://svn.apache.org/viewvc?rev=1748065&view=rev
Log:
remove public convenience methods that let the user avoid creating a CellAddress object. Having the user provide a CellAddress increases the chance the user-provided object will be reused if possible. This also moves the validation of the CellAddress object outside of this BorderPropertyTemplate class (easier to debug), improves readability, and runs slightly faster since the CellAddress is needed anyways as a key.
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=1748065&r1=1748064&r2=1748065&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 Sun Jun 12 22:33:24 2016
@@ -477,7 +477,8 @@ public final class BorderPropertyTemplat
int lastCol = range.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstCol; col <= lastCol; col++) {
- removeProperties(row, col, BORDER_DIRECTION_PROPERTY_NAMES);
+ CellAddress cell = new CellAddress(row, col);
+ removeProperties(cell, BORDER_DIRECTION_PROPERTY_NAMES);
}
}
removeBorderColors(range);
@@ -581,11 +582,12 @@ public final class BorderPropertyTemplat
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
+ CellAddress cell = new CellAddress(row, i);
// if BORDER_TOP is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(row, i, CellUtil.BORDER_TOP) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_TOP) == null) {
drawTopBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.TOP_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.TOP_BORDER_COLOR, color);
}
}
@@ -602,11 +604,12 @@ public final class BorderPropertyTemplat
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
+ CellAddress cell = new CellAddress(row, i);
// if BORDER_BOTTOM is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(row, i, CellUtil.BORDER_BOTTOM) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_BOTTOM) == null) {
drawBottomBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.BOTTOM_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.BOTTOM_BORDER_COLOR, color);
}
}
@@ -623,11 +626,12 @@ public final class BorderPropertyTemplat
int lastRow = range.getLastRow();
int col = range.getFirstColumn();
for (int i = firstRow; i <= lastRow; i++) {
+ CellAddress cell = new CellAddress(i, col);
// if BORDER_LEFT is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(i, col, CellUtil.BORDER_LEFT) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_LEFT) == null) {
drawLeftBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.LEFT_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.LEFT_BORDER_COLOR, color);
}
}
@@ -645,11 +649,12 @@ public final class BorderPropertyTemplat
int lastRow = range.getLastRow();
int col = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
+ CellAddress cell = new CellAddress(i, col);
// if BORDER_RIGHT is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(i, col, CellUtil.BORDER_RIGHT) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_RIGHT) == null) {
drawRightBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.RIGHT_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.RIGHT_BORDER_COLOR, color);
}
}
@@ -772,7 +777,8 @@ public final class BorderPropertyTemplat
int lastColumn = range.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstColumn; col <= lastColumn; col++) {
- removeProperties(row, col, BORDER_COLOR_PROPERTY_NAMES);
+ CellAddress cell = new CellAddress(row, col);
+ removeProperties(cell, BORDER_COLOR_PROPERTY_NAMES);
}
}
}
@@ -780,13 +786,11 @@ public final class BorderPropertyTemplat
/**
* Adds a property to this BorderPropertyTemplate for a given cell
*
- * @param row
- * @param col
- * @param property
- * @param value
+ * @param cell The cell to add the property to in the property template.
+ * @param property The property key to add to the property template.
+ * @param value The property value to add to the property template.
*/
- private void addProperty(int row, int col, String property, Object value) {
- CellAddress cell = new CellAddress(row, col);
+ private void addProperty(CellAddress cell, String property, Object value) {
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
cellProperties = new HashMap<String, Object>();
@@ -794,6 +798,18 @@ public final class BorderPropertyTemplat
cellProperties.put(property, value);
_propertyTemplate.put(cell, cellProperties);
}
+ /**
+ * Adds a property to this BorderPropertyTemplate for a given cell
+ *
+ * @param row The row number of the cell to add the property to
+ * @param col
+ * @param property The property key to add to the property template.
+ * @param value The property value to add to the property template.
+ */
+ private void addProperty(int row, int col, String property, Object value) {
+ CellAddress cell = new CellAddress(row, col);
+ addProperty(cell, property, value);
+ }
/**
* Removes a set of properties from this BorderPropertyTemplate for a
@@ -803,8 +819,7 @@ public final class BorderPropertyTemplat
* @param col the column index of the cell to remove properties from
* @param properties a list of the property names to remove from the cell
*/
- private void removeProperties(int row, int col, Set<String> properties) {
- CellAddress cell = new CellAddress(row, col);
+ private void removeProperties(CellAddress cell, Set<String> properties) {
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
cellProperties.keySet().removeAll(properties);
@@ -837,17 +852,6 @@ public final class BorderPropertyTemplat
}
/**
- * Retrieves the number of borders assigned to a cell
- *
- * @param row
- * @param col
- * @since 3.15 beta 2
- */
- public int getNumBorders(int row, int col) {
- return getNumBorders(new CellAddress(row, col));
- }
-
- /**
* Retrieves the number of border colors assigned to a cell
*
* @param cell
@@ -868,17 +872,6 @@ public final class BorderPropertyTemplat
}
/**
- * Retrieves the number of border colors assigned to a cell
- *
- * @param row The row number of the cell to get the number of border colors from.
- * @param col The column number of the cell to get the number of border colors from.
- * @since 3.15 beta 2
- */
- public int getNumBorderColors(int row, int col) {
- return getNumBorderColors(new CellAddress(row, col));
- }
-
- /**
* Retrieves the border style for a given cell
*
* @param cell The cell to get a template property from.
@@ -893,16 +886,4 @@ public final class BorderPropertyTemplat
}
return null;
}
-
- /**
- * Retrieves the border style for a given cell
- *
- * @param row The row number of the cell to get a template property from.
- * @param col The column number of the cell to get a template property from.
- * @param property the template property to get from the BorderPropertyTemplate. Example: {@link CellUtil#BORDER_TOP}.
- * @since 3.15 beta 2
- */
- public Object getTemplateProperty(int row, int col, String property) {
- return getTemplateProperty(new CellAddress(row, col), property);
- }
}
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=1748065&r1=1748064&r2=1748065&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 Sun Jun 12 22:33:24 2016
@@ -41,49 +41,55 @@ public final class TestBorderPropertyTem
@Test
public void getNumBorders() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorders(a1a1, BorderStyle.THIN, BorderExtent.TOP);
- assertEquals(1, pt.getNumBorders(0, 0));
+ assertEquals(1, pt.getNumBorders(a1));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.BOTTOM);
- assertEquals(2, pt.getNumBorders(0, 0));
+ assertEquals(2, pt.getNumBorders(a1));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.NONE);
- assertEquals(0, pt.getNumBorders(0, 0));
+ assertEquals(0, pt.getNumBorders(a1));
}
@Test
public void getNumBorderColors() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.TOP);
- assertEquals(1, pt.getNumBorderColors(0, 0));
+ assertEquals(1, pt.getNumBorderColors(a1));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.BOTTOM);
- assertEquals(2, pt.getNumBorderColors(0, 0));
+ assertEquals(2, pt.getNumBorderColors(a1));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.NONE);
- assertEquals(0, pt.getNumBorderColors(0, 0));
+ assertEquals(0, pt.getNumBorderColors(a1));
}
@Test
public void getTemplateProperties() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorders(a1a1, BorderStyle.THIN, BorderExtent.TOP);
- assertThin(pt.getTemplateProperty(0, 0, CellUtil.BORDER_TOP));
+ assertThin(pt.getTemplateProperty(a1, CellUtil.BORDER_TOP));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.BOTTOM);
- assertMedium(pt.getTemplateProperty(0, 0, CellUtil.BORDER_BOTTOM));
+ assertMedium(pt.getTemplateProperty(a1, CellUtil.BORDER_BOTTOM));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.TOP);
- assertRed(pt.getTemplateProperty(0, 0, CellUtil.TOP_BORDER_COLOR));
+ assertRed(pt.getTemplateProperty(a1, CellUtil.TOP_BORDER_COLOR));
pt.drawBorderColors(a1a1, IndexedColors.BLUE.getIndex(), BorderExtent.BOTTOM);
- assertBlue(pt.getTemplateProperty(0, 0, CellUtil.BOTTOM_BORDER_COLOR));
+ assertBlue(pt.getTemplateProperty(a1, CellUtil.BOTTOM_BORDER_COLOR));
}
@Test
@@ -313,7 +319,7 @@ public final class TestBorderPropertyTem
assertMedium(pt.getTemplateProperty(addr, CellUtil.BORDER_LEFT));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(addr));
- assertMedium(pt.getTemplateProperty(i ,j, CellUtil.BORDER_RIGHT));
+ assertMedium(pt.getTemplateProperty(addr, CellUtil.BORDER_RIGHT));
} else {
assertEquals(0, pt.getNumBorders(addr));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org