poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1795681 - in /poi/trunk/src: java/org/apache/poi/ss/util/CellReference.java testcases/org/apache/poi/ss/util/TestCellReference.java
Date Sat, 20 May 2017 21:04:14 GMT
Author: onealj
Date: Sat May 20 21:04:14 2017
New Revision: 1795681

URL: http://svn.apache.org/viewvc?rev=1795681&view=rev
Log:
github-55: document that CellReference#isRowWithinRange(String rowNum, SpreadsheetVersion
ss) expects rowNum to be parseable as an integer

Modified:
    poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
    poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java?rev=1795681&r1=1795680&r2=1795681&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java Sat May 20 21:04:14 2017
@@ -132,6 +132,7 @@ public class CellReference {
         if (rowRef.length() == 0) {
             _rowIndex = -1;
         } else {
+            // throws NumberFormatException if rowRef is not convertable to an int
             _rowIndex = Integer.parseInt(rowRef)-1; // -1 to convert 1-based to zero-based
         }
     }
@@ -342,8 +343,24 @@ public class CellReference {
         return true;
     }
 
+    /**
+     * Determines whether {@code rowStr} is a valid row number for a given SpreadsheetVersion.
+     * @param rowStr  the numeric portion of an A1-style cell reference (1-based index)
+     * @param ssVersion  the spreadsheet version
+     * @throws NumberFormatException if rowStr is not parseable as an integer
+     */
     public static boolean isRowWithinRange(String rowStr, SpreadsheetVersion ssVersion) {
-        int rowNum = Integer.parseInt(rowStr) - 1;
+        final int rowNum = Integer.parseInt(rowStr) - 1;
+        return isRowWithinRange(rowNum, ssVersion);
+    }
+
+    /**
+     * Determines whether {@code row} is a valid row number for a given SpreadsheetVersion.
+     * @param rowNum  the row number (0-based index)
+     * @param ssVersion  the spreadsheet version
+     * @since 3.17 beta 1
+     */
+    public static boolean isRowWithinRange(int rowNum, SpreadsheetVersion ssVersion) {
         return 0 <= rowNum && rowNum <= ssVersion.getLastRowIndex();
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java?rev=1795681&r1=1795680&r2=1795681&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java Sat May 20 21:04:14
2017
@@ -353,8 +353,26 @@ public final class TestCellReference {
         assertTrue("first row", CellReference.isRowWithinRange("1", ss));
         assertTrue("last row", CellReference.isRowWithinRange("1048576", ss));
         assertFalse("1 beyond last row", CellReference.isRowWithinRange("1048577", ss));
+
+        // int versions of above, using 0-based indices
+        assertFalse("1 before first row", CellReference.isRowWithinRange(-1, ss));
+        assertTrue("first row", CellReference.isRowWithinRange(0, ss));
+        assertTrue("last row", CellReference.isRowWithinRange(1048575, ss));
+        assertFalse("1 beyond last row", CellReference.isRowWithinRange(1048576, ss));
+    }
+
+    @Test(expected=NumberFormatException.class)
+    public void isRowWithinRangeNonInteger_BigNumber() {
+        String rowNum = "4000000000";
+        CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007);
     }
     
+    @Test(expected=NumberFormatException.class)
+    public void isRowWithinRangeNonInteger_Alpha() {
+        String rowNum = "NotANumber";
+        CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007);
+    }
+
     @Test
     public void isColWithinRange() {
         SpreadsheetVersion ss = SpreadsheetVersion.EXCEL2007;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message