diff options
author | Javen O'Neal <onealj@apache.org> | 2016-06-19 23:02:43 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2016-06-19 23:02:43 +0000 |
commit | c3c26ffdf38adab3c8237e5b6a3731a467570419 (patch) | |
tree | 805d2b2276bc702117c2726e327a0ff1c65e9836 /src/java/org/apache/poi | |
parent | 04f7652cf317a1f78055c179eb958f495e3a44a0 (diff) | |
download | poi-c3c26ffdf38adab3c8237e5b6a3731a467570419.tar.gz poi-c3c26ffdf38adab3c8237e5b6a3731a467570419.zip |
bug 56958: replace java.awt.Rectangle#intersects with native implementation to determine if CellRangeAddresses intersect; patch from Yaniv Kunda
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r-- | src/java/org/apache/poi/ss/util/CellRangeAddressBase.java | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java b/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java index 98378f0b77..05ebdd2c2a 100644 --- a/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java +++ b/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java @@ -17,15 +17,13 @@ package org.apache.poi.ss.util; -import java.awt.Rectangle; - import org.apache.poi.ss.SpreadsheetVersion; /** * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/> * - * Common subclass of 8-bit and 16-bit versions + * Common superclass of 8-bit and 16-bit versions */ public abstract class CellRangeAddressBase { @@ -133,37 +131,12 @@ public abstract class CellRangeAddressBase { * @return returns true if this range and other range have at least 1 cell in common */ public boolean intersects(CellRangeAddressBase other) { - // see java.awt.Rectangle.intersects - // http://stackoverflow.com/questions/13390333/two-rectangles-intersection - - // TODO: Replace with an intersection code that doesn't rely on java.awt - return getRectangle().intersects(other.getRectangle()); + return this._firstRow <= other._lastRow && + this._firstCol <= other._lastCol && + other._firstRow <= this._lastRow && + other._firstCol <= this._lastCol; } - // TODO: Replace with an intersection code that doesn't rely on java.awt - // Don't let this temporary implementation detail leak outside of this class - private final Rectangle getRectangle() { - int firstRow, firstCol, lastRow, lastCol; - - if (!isFullColumnRange()) { - firstRow = Math.min(_firstRow, _lastRow); - lastRow = Math.max(_firstRow, _lastRow); - } - else { - firstRow = 0; - lastRow = Integer.MAX_VALUE; - } - if (!isFullRowRange()) { - firstCol = Math.min(_firstCol, _lastCol); - lastCol = Math.max(_firstCol, _lastCol); - } - else { - firstCol = 0; - lastCol = Integer.MAX_VALUE; - } - return new Rectangle(firstRow, firstCol, lastRow-firstRow+1, lastCol-firstCol+1); - } - /** * @param firstCol column number for the upper left hand corner */ |