aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/poi/ss/util/CellRangeAddressBase.java')
-rw-r--r--src/java/org/apache/poi/ss/util/CellRangeAddressBase.java66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java b/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
index 1224e479d6..bef4596743 100644
--- a/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
+++ b/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
@@ -17,14 +17,12 @@
package org.apache.poi.ss.util;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
-import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
+import org.apache.poi.common.Duplicatable;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
@@ -34,13 +32,13 @@ import org.apache.poi.ss.usermodel.Cell;
*
* Common superclass of 8-bit and 16-bit versions
*/
-public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
+public abstract class CellRangeAddressBase implements Iterable<CellAddress>, Duplicatable {
/**
* Indicates a cell or range is in the given relative position in a range.
* More than one of these may apply at once.
*/
- public static enum CellPosition {
+ public enum CellPosition {
/** range starting rows are equal */
TOP,
/** range ending rows are equal */
@@ -138,7 +136,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
}
/**
- * Determines if the given coordinates lie within the bounds
+ * Determines if the given coordinates lie within the bounds
* of this range.
*
* @param rowInd The row, 0-based.
@@ -150,11 +148,11 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
return _firstRow <= rowInd && rowInd <= _lastRow && //containsRow
_firstCol <= colInd && colInd <= _lastCol; //containsColumn
}
-
+
/**
- * Determines if the given {@link CellReference} lies within the bounds
- * of this range.
- * <p>NOTE: It is up to the caller to ensure the reference is
+ * Determines if the given {@link CellReference} lies within the bounds
+ * of this range.
+ * <p>NOTE: It is up to the caller to ensure the reference is
* for the correct sheet, since this instance doesn't have a sheet reference.
*
* @param ref the CellReference to check
@@ -164,11 +162,11 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public boolean isInRange(CellReference ref) {
return isInRange(ref.getRow(), ref.getCol());
}
-
+
/**
- * Determines if the given {@link CellAddress} lies within the bounds
- * of this range.
- * <p>NOTE: It is up to the caller to ensure the reference is
+ * Determines if the given {@link CellAddress} lies within the bounds
+ * of this range.
+ * <p>NOTE: It is up to the caller to ensure the reference is
* for the correct sheet, since this instance doesn't have a sheet reference.
*
* @param ref the CellAddress to check
@@ -178,11 +176,11 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public boolean isInRange(CellAddress ref) {
return isInRange(ref.getRow(), ref.getColumn());
}
-
+
/**
- * Determines if the given {@link Cell} lies within the bounds
- * of this range.
- * <p>NOTE: It is up to the caller to ensure the reference is
+ * Determines if the given {@link Cell} lies within the bounds
+ * of this range.
+ * <p>NOTE: It is up to the caller to ensure the reference is
* for the correct sheet, since this instance doesn't have a sheet reference.
*
* @param cell the Cell to check
@@ -192,7 +190,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public boolean isInRange(Cell cell) {
return isInRange(cell.getRowIndex(), cell.getColumnIndex());
}
-
+
/**
* Check if the row is in the specified cell range
*
@@ -202,7 +200,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public boolean containsRow(int rowInd) {
return _firstRow <= rowInd && rowInd <= _lastRow;
}
-
+
/**
* Check if the column is in the specified cell range
*
@@ -212,7 +210,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public boolean containsColumn(int colInd) {
return _firstCol <= colInd && colInd <= _lastCol;
}
-
+
/**
* Determines whether or not this CellRangeAddress and the specified CellRangeAddress intersect.
*
@@ -226,7 +224,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
other._firstRow <= this._lastRow &&
other._firstCol <= this._lastCol;
}
-
+
/**
* Useful for logic like table/range styling, where some elements apply based on relative position in a range.
* @param rowInd
@@ -245,10 +243,10 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
if (rowInd == getLastRow()) positions.add(CellPosition.BOTTOM);
if (colInd == getFirstColumn()) positions.add(CellPosition.LEFT);
if (colInd == getLastColumn()) positions.add(CellPosition.RIGHT);
-
+
return positions;
}
-
+
/**
* @param firstCol column number for the upper left hand corner
*/
@@ -291,37 +289,37 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
public Iterator<CellAddress> iterator() {
return new RowMajorCellAddressIterator(this);
}
-
+
/**
* Iterates over the cell addresses in a cell range in row major order
- *
+ *
* The iterator is unaffected by changes to the CellRangeAddressBase instance
* after the iterator is created.
*/
private static class RowMajorCellAddressIterator implements Iterator<CellAddress> {
private final int firstRow, firstCol, lastRow, lastCol;
private int r, c;
-
+
public RowMajorCellAddressIterator(CellRangeAddressBase ref) {
r = firstRow = ref.getFirstRow();
c = firstCol = ref.getFirstColumn();
lastRow = ref.getLastRow();
lastCol = ref.getLastColumn();
-
+
// whole row and whole column ranges currently not supported
if (firstRow < 0) throw new IllegalStateException("First row cannot be negative.");
if (firstCol < 0) throw new IllegalStateException("First column cannot be negative.");
-
+
// avoid infinite iteration
if (firstRow > lastRow) throw new IllegalStateException("First row cannot be greater than last row.");
if (firstCol > lastCol) throw new IllegalStateException("First column cannot be greater than last column.");
}
-
+
@Override
public boolean hasNext() {
return r <= lastRow && c <= lastCol;
}
-
+
@Override
public CellAddress next() {
if (hasNext()) {
@@ -346,7 +344,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
CellAddress crB = new CellAddress(_lastRow, _lastCol);
return getClass().getName() + " [" + crA.formatAsString() + ":" + crB.formatAsString() +"]";
}
-
+
// In case _firstRow > _lastRow or _firstCol > _lastCol
protected int getMinRow() {
return Math.min(_firstRow, _lastRow);
@@ -360,7 +358,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
protected int getMaxColumn() {
return Math.max(_firstCol, _lastCol);
}
-
+
@Override
public boolean equals(Object other) {
if (other instanceof CellRangeAddressBase) {
@@ -372,7 +370,7 @@ public abstract class CellRangeAddressBase implements Iterable<CellAddress> {
}
return false;
}
-
+
@Override
public int hashCode() {
return (getMinColumn() +