You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2016/05/20 22:05:01 UTC
svn commit: r1744802 - in /poi/trunk/src:
java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
Author: kiwiwings
Date: Fri May 20 22:05:00 2016
New Revision: 1744802
URL: http://svn.apache.org/viewvc?rev=1744802&view=rev
Log:
findbugs fixes
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java?rev=1744802&r1=1744801&r2=1744802&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java Fri May 20 22:05:00 2016
@@ -34,8 +34,6 @@ import org.apache.poi.ss.usermodel.Workb
* Represents a workbook being used for forked evaluation. Most operations are delegated to the
* shared master workbook, except those that potentially involve cell values that may have been
* updated after a call to {@link #getOrCreateUpdatableCell(String, int, int)}.
- *
- * @author Josh Micich
*/
final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
@@ -69,15 +67,9 @@ final class ForkedEvaluationWorkbook imp
}
public void copyUpdatedCells(Workbook workbook) {
- String[] sheetNames = new String[_sharedSheetsByName.size()];
- _sharedSheetsByName.keySet().toArray(sheetNames);
- OrderedSheet[] oss = new OrderedSheet[sheetNames.length];
- for (int i = 0; i < sheetNames.length; i++) {
- String sheetName = sheetNames[i];
- oss[i] = new OrderedSheet(sheetName, _masterBook.getSheetIndex(sheetName));
- }
- for (int i = 0; i < oss.length; i++) {
- String sheetName = oss[i].getSheetName();
+ String[] sheetNames = new String[_sharedSheetsByName.size()];
+ _sharedSheetsByName.keySet().toArray(sheetNames);
+ for (String sheetName : sheetNames) {
ForkedEvaluationSheet sheet = _sharedSheetsByName.get(sheetName);
sheet.copyUpdatedCells(workbook.getSheet(sheetName));
}
@@ -144,20 +136,4 @@ final class ForkedEvaluationWorkbook imp
public UDFFinder getUDFFinder(){
return _masterBook.getUDFFinder();
}
-
- private static final class OrderedSheet implements Comparable<OrderedSheet> {
- private final String _sheetName;
- private final int _index;
-
- public OrderedSheet(String sheetName, int index) {
- _sheetName = sheetName;
- _index = index;
- }
- public String getSheetName() {
- return _sheetName;
- }
- public int compareTo(OrderedSheet o) {
- return _index - o._index;
- }
- }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java?rev=1744802&r1=1744801&r2=1744802&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java Fri May 20 22:05:00 2016
@@ -96,8 +96,8 @@ public final class ListLevel
setStartAt( startAt );
_lvlf.setNfc( (byte) numberFormatCode );
_lvlf.setJc( (byte) alignment );
- _grpprlChpx = numberProperties;
- _grpprlPapx = entryProperties;
+ _grpprlChpx = numberProperties.clone();
+ _grpprlPapx = entryProperties.clone();
_xst = new Xst(numberText);
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java?rev=1744802&r1=1744801&r2=1744802&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java Fri May 20 22:05:00 2016
@@ -17,19 +17,24 @@
package org.apache.poi.ss.formula.eval.forked;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
-import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.IStabilityClassifier;
-
-/**
- * @author Josh Micich
- */
-public final class TestForkedEvaluator extends TestCase {
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public final class TestForkedEvaluator {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
/**
* set up a calculation workbook with input cells nicely segregated on a
* sheet called "Inputs"
@@ -53,7 +58,8 @@ public final class TestForkedEvaluator e
/**
* Shows a basic use-case for {@link ForkedEvaluator}
*/
- public void testBasic() {
+ @Test
+ public void testBasic() throws IOException {
HSSFWorkbook wb = createWorkbook();
// The stability classifier is useful to reduce memory consumption of caching logic
@@ -78,6 +84,8 @@ public final class TestForkedEvaluator e
assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0));
assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
+
+ wb.close();
}
/**
@@ -90,29 +98,19 @@ public final class TestForkedEvaluator e
* was considered less desirable because so far, the underlying 'master' workbook is strictly
* <i>read-only</i> with respect to the ForkedEvaluator.
*/
- public void testMissingInputCell() {
+ @Test
+ public void testMissingInputCell() throws IOException {
+ expectedEx.expect(UnsupportedOperationException.class);
+ expectedEx.expectMessage("Underlying cell 'A2' is missing in master sheet.");
+
HSSFWorkbook wb = createWorkbook();
- ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null);
-
- // attempt update input at cell A2 (which is missing)
try {
- fe.updateCell("Inputs", 1, 0, new NumberEval(4.0));
- throw new AssertionFailedError(
- "Expected exception to be thrown due to missing input cell");
- } catch (NullPointerException e) {
- StackTraceElement[] stes = e.getStackTrace();
- if (stes[0].getMethodName().equals("getIdentityKey")) {
- throw new AssertionFailedError("Identified bug with update of missing input cell");
- }
- throw e;
- } catch (UnsupportedOperationException e) {
- if (e.getMessage().equals(
- "Underlying cell 'A2' is missing in master sheet.")) {
- // expected during successful test
- } else {
- throw e;
- }
+ ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null);
+ // attempt update input at cell A2 (which is missing)
+ fe.updateCell("Inputs", 1, 0, new NumberEval(4.0));
+ } finally {
+ wb.close();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org