rewrite switch statements to not re-check the switch'd variable
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ss_border_property_template@1748070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a63d82bbee
commit
0ae778e5cd
@ -198,9 +198,10 @@ public final class BorderPropertyTemplate {
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a group of cell borders for a cell range. The borders are not
|
||||
* applied to the cells at this time, just the template is drawn. To apply
|
||||
* the drawn borders to a sheet, use {@link #applyBorders}.
|
||||
* 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).
|
||||
* To apply the drawn borders to a sheet, use {@link #applyBorders}.
|
||||
*
|
||||
* @param range range of cells on which borders are drawn.
|
||||
* @param borderType Type of border to draw.
|
||||
@ -257,9 +258,10 @@ public final class BorderPropertyTemplate {
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a group of cell borders for a cell range. The borders are not
|
||||
* applied to the cells at this time, just the template is drawn. To apply
|
||||
* the drawn borders to a sheet, use {@link #applyBorders}.
|
||||
* Add a group of cell borders and colors 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).
|
||||
* To apply the drawn borders to a sheet, use {@link #applyBorders}.
|
||||
*
|
||||
* @param range range of cells on which borders are drawn.
|
||||
* @param borderType Type of border to draw.
|
||||
@ -375,16 +377,18 @@ public final class BorderPropertyTemplate {
|
||||
private void drawOutsideBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case HORIZONTAL:
|
||||
case VERTICAL:
|
||||
if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
|
||||
drawTopBorder(range, borderType);
|
||||
drawBottomBorder(range, borderType);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
|
||||
drawLeftBorder(range, borderType);
|
||||
drawRightBorder(range, borderType);
|
||||
}
|
||||
break;
|
||||
case HORIZONTAL:
|
||||
drawTopBorder(range, borderType);
|
||||
drawBottomBorder(range, borderType);
|
||||
break;
|
||||
case VERTICAL:
|
||||
drawLeftBorder(range, borderType);
|
||||
drawRightBorder(range, borderType);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
@ -406,21 +410,23 @@ public final class BorderPropertyTemplate {
|
||||
* </ul>
|
||||
*/
|
||||
private void drawHorizontalBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case INSIDE:
|
||||
int firstRow = range.getFirstRow();
|
||||
int lastRow = range.getLastRow();
|
||||
int firstCol = range.getFirstColumn();
|
||||
int lastCol = range.getLastColumn();
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
for (int i = firstRow; i <= lastRow; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
|
||||
if (extent == BorderExtent.ALL || i > firstRow) {
|
||||
drawTopBorder(row, borderType);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || i < lastRow) {
|
||||
drawBottomBorder(row, borderType);
|
||||
}
|
||||
break;
|
||||
case INSIDE:
|
||||
for (int i = firstRow; i <= lastRow; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
|
||||
if (i > firstRow) drawTopBorder(row, borderType);
|
||||
if (i < lastRow) drawBottomBorder(row, borderType);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -442,21 +448,23 @@ public final class BorderPropertyTemplate {
|
||||
* </ul>
|
||||
*/
|
||||
private void drawVerticalBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case INSIDE:
|
||||
int firstRow = range.getFirstRow();
|
||||
int lastRow = range.getLastRow();
|
||||
int firstCol = range.getFirstColumn();
|
||||
int lastCol = range.getLastColumn();
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
for (int i = firstCol; i <= lastCol; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(firstRow, lastRow, i, i);
|
||||
if (extent == BorderExtent.ALL || i > firstCol) {
|
||||
drawLeftBorder(row, borderType);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || i < lastCol) {
|
||||
drawRightBorder(row, borderType);
|
||||
}
|
||||
break;
|
||||
case INSIDE:
|
||||
for (int i = firstCol; i <= lastCol; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(firstRow, lastRow, i, i);
|
||||
if (i > firstCol) drawLeftBorder(row, borderType);
|
||||
if (i < lastCol) drawRightBorder(row, borderType);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -488,6 +496,12 @@ public final class BorderPropertyTemplate {
|
||||
* Applies the drawn borders to a Sheet. The borders that are applied are
|
||||
* the ones that have been drawn by the {@link #drawBorders} and
|
||||
* {@link #drawBorderColors} methods.
|
||||
* The same border property template can be applied to multiple sheets
|
||||
* from the same or different workbooks.
|
||||
*
|
||||
* If the border property template contains cell addresses outside the valid range
|
||||
* of <code>sheet</code>, borders for those cell addresses are quietly ignored and
|
||||
* not applied to <code>sheet</code>.
|
||||
*
|
||||
* @param sheet Sheet on which to apply borders
|
||||
* @since 3.15 beta 2
|
||||
@ -510,10 +524,11 @@ public final class BorderPropertyTemplate {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color for a group of cell borders for a cell range. The borders
|
||||
* are not applied to the cells at this time, just the template is drawn. If
|
||||
* the borders do not exist, a {@link BorderStyle#THIN} border is used. To apply the
|
||||
* drawn borders to a sheet, use {@link #applyBorders}.
|
||||
* Sets the color for 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).
|
||||
* If the borders do not exist, a {@link BorderStyle#THIN} border is used.
|
||||
* To apply the drawn borders to a sheet, use {@link #applyBorders}.
|
||||
*
|
||||
* @param range range of cells on which colors are set.
|
||||
* @param color Color index from {@link IndexedColors} used to draw the borders.
|
||||
@ -684,16 +699,18 @@ public final class BorderPropertyTemplate {
|
||||
private void drawOutsideBorderColors(CellRangeAddress range, short color, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case HORIZONTAL:
|
||||
case VERTICAL:
|
||||
if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
|
||||
drawTopBorderColor(range, color);
|
||||
drawBottomBorderColor(range, color);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
|
||||
drawLeftBorderColor(range, color);
|
||||
drawRightBorderColor(range, color);
|
||||
}
|
||||
break;
|
||||
case HORIZONTAL:
|
||||
drawTopBorderColor(range, color);
|
||||
drawBottomBorderColor(range, color);
|
||||
break;
|
||||
case VERTICAL:
|
||||
drawLeftBorderColor(range, color);
|
||||
drawRightBorderColor(range, color);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
@ -715,21 +732,23 @@ public final class BorderPropertyTemplate {
|
||||
* </ul>
|
||||
*/
|
||||
private void drawHorizontalBorderColors(CellRangeAddress range, short color, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case INSIDE:
|
||||
int firstRow = range.getFirstRow();
|
||||
int lastRow = range.getLastRow();
|
||||
int firstCol = range.getFirstColumn();
|
||||
int lastCol = range.getLastColumn();
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
for (int i = firstRow; i <= lastRow; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
|
||||
if (extent == BorderExtent.ALL || i > firstRow) {
|
||||
drawTopBorderColor(row, color);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || i < lastRow) {
|
||||
drawBottomBorderColor(row, color);
|
||||
}
|
||||
break;
|
||||
case INSIDE:
|
||||
for (int i = firstRow; i <= lastRow; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
|
||||
if (i > firstRow) drawTopBorderColor(row, color);
|
||||
if (i < lastRow) drawBottomBorderColor(row, color);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -751,21 +770,23 @@ public final class BorderPropertyTemplate {
|
||||
* </ul>
|
||||
*/
|
||||
private void drawVerticalBorderColors(CellRangeAddress range, short color, BorderExtent extent) {
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
case INSIDE:
|
||||
int firstRow = range.getFirstRow();
|
||||
int lastRow = range.getLastRow();
|
||||
int firstCol = range.getFirstColumn();
|
||||
int lastCol = range.getLastColumn();
|
||||
switch (extent) {
|
||||
case ALL:
|
||||
for (int i = firstCol; i <= lastCol; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(firstRow, lastRow, i, i);
|
||||
if (extent == BorderExtent.ALL || i > firstCol) {
|
||||
drawLeftBorderColor(row, color);
|
||||
}
|
||||
if (extent == BorderExtent.ALL || i < lastCol) {
|
||||
drawRightBorderColor(row, color);
|
||||
}
|
||||
break;
|
||||
case INSIDE:
|
||||
for (int i = firstCol; i <= lastCol; i++) {
|
||||
CellRangeAddress row = new CellRangeAddress(firstRow, lastRow, i, i);
|
||||
if (i > firstCol) drawLeftBorderColor(row, color);
|
||||
if (i < lastCol) drawRightBorderColor(row, color);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user