poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1851210 - in /poi/trunk/src: integrationtest/org/apache/poi/stress/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/sl/draw/geom/ java/org/apache/poi/ss/formula/ java/org/apache/poi/ss/formula/ptg/ java/org/apache/poi/ss/usermodel/...
Date Sun, 13 Jan 2019 17:14:24 GMT
Author: centic
Date: Sun Jan 13 17:14:24 2019
New Revision: 1851210

URL: http://svn.apache.org/viewvc?rev=1851210&view=rev
Log:
Fix some Findbugs and IDE issues, refactor some duplicated code,
improve some exception texts, add comment for missing Ptg for SxName

Modified:
    poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
    poi/trunk/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
    poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
    poi/trunk/src/java/org/apache/poi/ss/formula/ptg/Ptg.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
    poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java Sun Jan 13
17:14:24 2019
@@ -37,6 +37,10 @@ import org.apache.poi.openxml4j.exceptio
 import org.apache.poi.util.IOUtils;
 import org.apache.xmlbeans.XmlException;
 
+/**
+ * Base class with things that can be run for any supported file handler
+ * in the integration tests, mostly text-extraction related at the moment.
+ */
 public abstract class AbstractFileHandler implements FileHandler {
     public static final Set<String> EXPECTED_EXTRACTOR_FAILURES = new HashSet<>();
     static {

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java Sun Jan 13 17:14:24
2019
@@ -88,7 +88,7 @@ public class HSSFFileHandler extends Spr
 		try {
 			System.setOut(new PrintStream(new OutputStream() {
 				@Override
-				public void write(int b) throws IOException {
+				public void write(int b) {
 				}
 			}));
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Sun Jan 13 17:14:24 2019
@@ -28,8 +28,8 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.helpers.RowShifter;
 import org.apache.poi.util.Configurator;
-import org.apache.poi.util.LocaleUtil;
 
 /**
  * High level representation of a row of a spreadsheet.
@@ -725,11 +725,8 @@ public final class HSSFRow implements Ro
      */
     @Override
     public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int
step) {
-        if(step < 0)
-            throw new IllegalArgumentException("Shifting step may not be negative ");
-        if(firstShiftColumnIndex > lastShiftColumnIndex)
-            throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
-                    "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
+        RowShifter.validateShiftParameters(firstShiftColumnIndex, lastShiftColumnIndex, step);
+
         if(lastShiftColumnIndex + step + 1> cells.length)
             extend(lastShiftColumnIndex + step + 1);
         for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex;
columnIndex--){ // process cells backwards, because of shifting 
@@ -746,6 +743,7 @@ public final class HSSFRow implements Ro
         cells = new HSSFCell[newLenght];
         System.arraycopy(temp, 0, cells, 0, temp.length);
     }
+
     /**
      * Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the
left.
      * @param firstShiftColumnIndex the column to start shifting
@@ -754,13 +752,8 @@ public final class HSSFRow implements Ro
      */
     @Override
     public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
{
-        if(step < 0)
-            throw new IllegalArgumentException("Shifting step may not be negative ");
-        if(firstShiftColumnIndex > lastShiftColumnIndex)
-            throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
-                    "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
-        if(firstShiftColumnIndex - step < 0) 
-            throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex
+ step)).toString());
+        RowShifter.validateShiftLeftParameters(firstShiftColumnIndex, lastShiftColumnIndex,
step);
+
         for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex;
columnIndex++){ 
             HSSFCell cell = getCell(columnIndex);
             if(cell != null){

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java Sun Jan 13 17:14:24
2019
@@ -26,12 +26,10 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.EventFilter;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.events.XMLEvent;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
@@ -52,14 +50,6 @@ public class PresetGeometries extends Li
 
     @SuppressWarnings("unused")
     public void init(InputStream is) throws XMLStreamException, JAXBException {
-        // StAX:
-        EventFilter startElementFilter = new EventFilter() {
-            @Override
-            public boolean accept(XMLEvent event) {
-                return event.isStartElement();
-            }
-        };
-        
         XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory();
         XMLStreamReader streamReader = staxFactory.createXMLStreamReader(new StreamSource(is));
         try {
@@ -108,12 +98,9 @@ public class PresetGeometries extends Li
             // in case of failure
             PresetGeometries lInst = new PresetGeometries();
             try {
-                InputStream is = PresetGeometries.class.
-                    getResourceAsStream("presetShapeDefinitions.xml");
-                try {
+                try (InputStream is = PresetGeometries.class.
+                        getResourceAsStream("presetShapeDefinitions.xml")) {
                     lInst.init(is);
-                } finally {
-                    is.close();
                 }
             } catch (Exception e){
                 throw new RuntimeException(e);

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java Sun Jan 13 17:14:24 2019
@@ -203,7 +203,7 @@ public final class FormulaParser {
         final int sheetIndex = -1; //don't care?
         Ptg[] arr = FormulaParser.parse(tableText, workbook, FormulaType.CELL, sheetIndex,
rowIndex);
         if (arr.length != 1 || !(arr[0] instanceof Area3DPxg) ) {
-            throw new IllegalStateException("Illegal structured reference");
+            throw new IllegalStateException("Illegal structured reference, had length: "
+ arr.length);
         }
         return (Area3DPxg) arr[0];
     }
@@ -211,7 +211,7 @@ public final class FormulaParser {
     /** Read New Character From Input Stream */
     private void GetChar() {
         // The intersection operator is a space.  We track whether the run of 
-        // whitespace preceeding "look" counts as an intersection operator.  
+        // whitespace preceding "look" counts as an intersection operator.
         if (IsWhite(look)) {
             if (look == ' ') {
                 _inIntersection = true;
@@ -223,7 +223,8 @@ public final class FormulaParser {
         
         // Check to see if we've walked off the end of the string.
         if (_pointer > _formulaLength) {
-            throw new RuntimeException("too far");
+            throw new RuntimeException("Parsed past the end of the formula, pos: " + _pointer
+
+                    ", length: " + _formulaLength + ", formula: " + _formulaString);
         }
         if (_pointer < _formulaLength) {
             look=_formulaString.codePointAt(_pointer);
@@ -650,18 +651,24 @@ public final class FormulaParser {
                 resetPointer(savePtr1);
                 break;
             }
-            if (specName.equals(specAll)) {
-                isAllSpec = true;
-            } else if (specName.equals(specData)) {
-                isDataSpec = true;
-            } else if (specName.equals(specHeaders)) {
-                isHeadersSpec = true;
-            } else if (specName.equals(specThisRow)) {
-                isThisRowSpec = true;
-            } else if (specName.equals(specTotals)) {
-                isTotalsSpec  = true;
-            } else {
-                throw new FormulaParseException("Unknown special quantifier "+ specName);
+            switch (specName) {
+                case specAll:
+                    isAllSpec = true;
+                    break;
+                case specData:
+                    isDataSpec = true;
+                    break;
+                case specHeaders:
+                    isHeadersSpec = true;
+                    break;
+                case specThisRow:
+                    isThisRowSpec = true;
+                    break;
+                case specTotals:
+                    isTotalsSpec = true;
+                    break;
+                default:
+                    throw new FormulaParseException("Unknown special quantifier " + specName);
             }
             nSpecQuantifiers++;
             if (look == ','){
@@ -687,13 +694,13 @@ public final class FormulaParser {
         } else {
             nColQuantifiers++;
             if (look == ','){
-                throw new FormulaParseException("The formula "+ _formulaString + "is illegal:
you should not use ',' with column quantifiers");
+                throw new FormulaParseException("The formula "+ _formulaString + " is illegal:
you should not use ',' with column quantifiers");
             } else if (look == ':') {
                 GetChar();
                 endColumnName = parseAsColumnQuantifier();
                 nColQuantifiers++;
                 if (endColumnName == null) {
-                    throw new FormulaParseException("The formula "+ _formulaString + "is
illegal: the string after ':' must be column quantifier");
+                    throw new FormulaParseException("The formula "+ _formulaString + " is
illegal: the string after ':' must be column quantifier");
                 }
             }
         }
@@ -708,18 +715,24 @@ public final class FormulaParser {
                 resetPointer(savePtr0);
                 String name = parseAsSpecialQuantifier();
                 if (name!=null) {
-                    if (name.equals(specAll)) {
-                        isAllSpec = true;
-                    } else if (name.equals(specData)) {
-                        isDataSpec = true;
-                    } else if (name.equals(specHeaders)) {
-                        isHeadersSpec = true;
-                    } else if (name.equals(specThisRow)) {
-                        isThisRowSpec = true;
-                    } else if (name.equals(specTotals)) {
-                        isTotalsSpec  = true;
-                    } else {
-                        throw new FormulaParseException("Unknown special quantifier "+ name);
+                    switch (name) {
+                        case specAll:
+                            isAllSpec = true;
+                            break;
+                        case specData:
+                            isDataSpec = true;
+                            break;
+                        case specHeaders:
+                            isHeadersSpec = true;
+                            break;
+                        case specThisRow:
+                            isThisRowSpec = true;
+                            break;
+                        case specTotals:
+                            isTotalsSpec = true;
+                            break;
+                        default:
+                            throw new FormulaParseException("Unknown special quantifier "
+ name);
                     }
                     nSpecQuantifiers++;
                 } else {
@@ -1344,7 +1357,6 @@ public final class FormulaParser {
     
     /**
      * Adds a name (named range or user defined function) to underlying workbook's names
table
-     * @param functionName
      */
     private void addName(String functionName) {
         final Name name = _book.createName();
@@ -1878,13 +1890,12 @@ public final class FormulaParser {
         boolean hasUnions = false;
         while (true) {
             SkipWhite();
-            switch(look) {
-                case ',':
-                    GetChar();
-                    hasUnions = true;
-                    ParseNode other = intersectionExpression();
-                    result = new ParseNode(UnionPtg.instance, result, other);
-                    continue;
+            if (look == ',') {
+                GetChar();
+                hasUnions = true;
+                ParseNode other = intersectionExpression();
+                result = new ParseNode(UnionPtg.instance, result, other);
+                continue;
             }
             if (hasUnions) {
                 return augmentWithMemPtg(result);

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/ptg/Ptg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/ptg/Ptg.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/ptg/Ptg.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/ptg/Ptg.java Sun Jan 13 17:14:24 2019
@@ -145,6 +145,7 @@ public abstract class Ptg {
 			case MissingArgPtg.sid:   return MissingArgPtg.instance;  // 0x16
 
 			case StringPtg.sid:       return new StringPtg(in);       // 0x17
+			// not implemented yet: case SxNamePtg.sid:       return new SxNamePtg(in);       // 0x18
 			case AttrPtg.sid:         return new AttrPtg(in);         // 0x19
 			case ErrPtg.sid:          return ErrPtg.read(in);         // 0x1c
 			case BoolPtg.sid:         return BoolPtg.read(in);        // 0x1d

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java Sun Jan 13 17:14:24
2019
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.LocaleUtil;
 
 /**
  * Helper for shifting rows up or down
@@ -116,4 +117,36 @@ public abstract class RowShifter extends
         // if the merged-region and the overwritten area intersect, we need to remove it
         return merged.intersects(overwrite);
     }
+
+    /**
+     * Verify that the given column indices and step denote a valid range of columns to shift
+     *
+     * @param firstShiftColumnIndex the column to start shifting
+     * @param lastShiftColumnIndex the column to end shifting
+     * @param step length of the shifting step
+     */
+    public static void validateShiftParameters(int firstShiftColumnIndex, int lastShiftColumnIndex,
int step) {
+        if(step < 0) {
+            throw new IllegalArgumentException("Shifting step may not be negative, but had
" + step);
+        }
+        if(firstShiftColumnIndex > lastShiftColumnIndex) {
+            throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
+                    "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
+        }
+    }
+
+    /**
+     * Verify that the given column indices and step denote a valid range of columns to shift
to the left
+     *
+     * @param firstShiftColumnIndex the column to start shifting
+     * @param lastShiftColumnIndex the column to end shifting
+     * @param step length of the shifting step
+     */
+    public static void validateShiftLeftParameters(int firstShiftColumnIndex, int lastShiftColumnIndex,
int step) {
+        validateShiftParameters(firstShiftColumnIndex, lastShiftColumnIndex, step);
+
+        if(firstShiftColumnIndex - step < 0) {
+            throw new IllegalStateException("Column index less than zero: " + (firstShiftColumnIndex
+ step));
+        }
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sun Jan 13 17:14:24
2019
@@ -1323,4 +1323,4 @@ public final class XSSFCell extends Cell
     }
         
 }
-    
+

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Sun Jan 13 17:14:24
2019
@@ -29,10 +29,10 @@ import org.apache.poi.ss.usermodel.CellC
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.helpers.RowShifter;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.Internal;
-import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
@@ -634,13 +634,8 @@ public class XSSFRow implements Row, Com
      */
     @Override
     public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int
step) {
-        if(step < 0) {
-            throw new IllegalArgumentException("Shifting step may not be negative ");
-        }
-        if(firstShiftColumnIndex > lastShiftColumnIndex) {
-            throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
-                    "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
-        }
+        RowShifter.validateShiftParameters(firstShiftColumnIndex, lastShiftColumnIndex, step);
+
         for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex;
columnIndex--){ // process cells backwards, because of shifting
             shiftCell(columnIndex, step);
         }
@@ -653,6 +648,7 @@ public class XSSFRow implements Row, Com
             }
         }
     }
+
     /**
      * Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the
left.
      * @param firstShiftColumnIndex the column to start shifting
@@ -661,16 +657,8 @@ public class XSSFRow implements Row, Com
      */
     @Override
     public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step)
{
-        if(step < 0) {
-            throw new IllegalArgumentException("Shifting step may not be negative ");
-        }
-        if(firstShiftColumnIndex > lastShiftColumnIndex) {
-            throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
-                    "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
-        }
-        if(firstShiftColumnIndex - step < 0) {
-            throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex
+ step)).toString());
-        }
+        RowShifter.validateShiftLeftParameters(firstShiftColumnIndex, lastShiftColumnIndex,
step);
+
         for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex;
columnIndex++){
             shiftCell(columnIndex, -step);
         }
@@ -682,6 +670,7 @@ public class XSSFRow implements Row, Com
             }
         }
     }
+
     private void shiftCell(int columnIndex, int step/*pass negative value for left shift*/){
         if(columnIndex + step < 0) {
             throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(columnIndex
+ step)).toString());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java Sun Jan
13 17:14:24 2019
@@ -17,8 +17,9 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -72,8 +73,8 @@ public final class TestSXSSFBugs extends
         s1.setRepeatingRows(cra);
 
         PrintSetup ps1 = s1.getPrintSetup();
-        assertEquals(false, ps1.getValidSettings());
-        assertEquals(false, ps1.getLandscape());
+        assertFalse(ps1.getValidSettings());
+        assertFalse(ps1.getLandscape());
 
 
         // Had valid print settings before repeating
@@ -81,14 +82,14 @@ public final class TestSXSSFBugs extends
         PrintSetup ps2 = s2.getPrintSetup();
 
         ps2.setLandscape(false);
-        assertEquals(true, ps2.getValidSettings());
-        assertEquals(false, ps2.getLandscape());
+        assertTrue(ps2.getValidSettings());
+        assertFalse(ps2.getLandscape());
         s2.setRepeatingColumns(cra);
         s2.setRepeatingRows(cra);
 
         ps2 = s2.getPrintSetup();
-        assertEquals(true, ps2.getValidSettings());
-        assertEquals(false, ps2.getLandscape());
+        assertTrue(ps2.getValidSettings());
+        assertFalse(ps2.getLandscape());
 
         wb1.close();
         wb2.close();
@@ -137,7 +138,7 @@ public final class TestSXSSFBugs extends
         Cell cell = row.createCell(colIndex++);
         cell.setCellType(CellType.STRING);
         cell.setCellValue("multiple");
-        cell = row.createCell(colIndex++);
+        cell = row.createCell(colIndex);
         cell.setCellType(CellType.STRING);
         cell.setCellValue("unique");
 
@@ -146,7 +147,7 @@ public final class TestSXSSFBugs extends
         writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B3, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
         writeRow(sheet, rowIndex++, 2d,  "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B4, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
         writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B5, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
-        writeRow(sheet, rowIndex++, 2d,  "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B6, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+        writeRow(sheet, rowIndex, 2d,  "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B6, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
 
         /*FileOutputStream fileOut = new FileOutputStream(filename);
         wb.write(fileOut);
@@ -211,6 +212,5 @@ public final class TestSXSSFBugs extends
             workbook.close();
             out.flush();
         }
-        // logger.info("File written!");
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
Sun Jan 13 17:14:24 2019
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -180,7 +181,7 @@ public final class TestXSSFFormulaParser
         assertEquals(1, ptgs.length);
         assertEquals(NameXPxg.class, ptgs[0].getClass());
         assertEquals(0,    ((NameXPxg)ptgs[0]).getExternalWorkbookNumber());
-        assertEquals(null, ((NameXPxg)ptgs[0]).getSheetName());
+        assertNull(((NameXPxg) ptgs[0]).getSheetName());
         assertEquals("NR_Global_B2",((NameXPxg)ptgs[0]).getNameName());
         assertEquals("[0]!NR_Global_B2", ptgs[0].toFormulaString());
 
@@ -259,7 +260,7 @@ public final class TestXSSFFormulaParser
         assertEquals(1, ptgs.length);
         assertEquals(NameXPxg.class, ptgs[0].getClass());
         assertEquals(1,    ((NameXPxg)ptgs[0]).getExternalWorkbookNumber());
-        assertEquals(null, ((NameXPxg)ptgs[0]).getSheetName());
+        assertNull(((NameXPxg) ptgs[0]).getSheetName());
         assertEquals("NR_Global_B2",((NameXPxg)ptgs[0]).getNameName());
         assertEquals("[1]!NR_Global_B2", ptgs[0].toFormulaString());
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java Sun Jan 13
17:14:24 2019
@@ -172,9 +172,7 @@ public class HwmfWindowing {
         public void draw(HwmfGraphics ctx) {
             final HwmfDrawProperties prop = ctx.getProperties();
             final Rectangle2D old = prop.getWindow();
-            double oldX = (old == null ? 0 : old.getX());
-            double oldY = (old == null ? 0 : old.getY());
-            if (oldX != getX() || oldY != getY()) {
+            if (old.getX() != getX() || old.getY() != getY()) {
                 prop.setWindowOrg(getX(), getY());
                 ctx.updateWindowMapMode();
             }

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=1851210&r1=1851209&r2=1851210&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
Sun Jan 13 17:14:24 2019
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.formula.eval.forked;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 
@@ -68,12 +69,7 @@ public class TestForkedEvaluator {
 		Workbook wb = createWorkbook();
 
 		// The stability classifier is useful to reduce memory consumption of caching logic
-		IStabilityClassifier stabilityClassifier = new IStabilityClassifier() {
-			@Override
-            public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
-				return sheetIndex == 1;
-			}
-		};
+		IStabilityClassifier stabilityClassifier = (sheetIndex, rowIndex, columnIndex) -> sheetIndex
== 1;
 
 		ForkedEvaluator fe1 = ForkedEvaluator.create(wb, stabilityClassifier, null);
 		ForkedEvaluator fe2 = ForkedEvaluator.create(wb, stabilityClassifier, null);
@@ -86,10 +82,16 @@ public class TestForkedEvaluator {
 		fe2.updateCell("Inputs", 0, 0, new NumberEval(1.2));
 		fe2.updateCell("Inputs", 0, 1, new NumberEval(2.0));
 
-		assertEquals(18.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(),
0.0);
-		assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
+		NumberEval eval1 = (NumberEval) fe1.evaluate("Calculations", 0, 0);
+		assertNotNull(eval1);
+		assertEquals(18.9, eval1.getNumberValue(), 0.0);
+		NumberEval eval2 = (NumberEval) fe2.evaluate("Calculations", 0, 0);
+		assertNotNull(eval2);
+		assertEquals(4.0, eval2.getNumberValue(), 0.0);
 		fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0));
-		assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(),
0.0);
+		eval1 = (NumberEval) fe1.evaluate("Calculations", 0, 0);
+		assertNotNull(eval1);
+		assertEquals(13.9, eval1.getNumberValue(), 0.0);
 		
 		wb.close();
 	}

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Sun Jan
13 17:14:24 2019
@@ -37,6 +37,7 @@ import java.util.Map;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.formula.FormulaParseException;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
 import org.apache.poi.ss.util.PaneInformation;
@@ -353,7 +354,7 @@ public abstract class BaseTestBugzillaIs
                 fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
                 cell.setCellFormula(fmla);
                 fail("Expected FormulaParseException");
-            } catch (RuntimeException e){
+            } catch (FormulaParseException e){
                  assertTrue(e.getMessage().startsWith("Too many arguments to function '"+name+"'"));
             }
         }
@@ -464,8 +465,10 @@ public abstract class BaseTestBugzillaIs
         double leadingWhitespaceRatio = ((double) leadingWhitespaceColWidth)/noWhitespaceColWidth;
         double trailingWhitespaceRatio = ((double) leadingWhitespaceColWidth)/noWhitespaceColWidth;
         
-        assertGreaterThan("leading whitespace is longer than no whitespace", leadingWhitespaceRatio,
expectedRatioThreshold);
-        assertGreaterThan("trailing whitespace is longer than no whitespace", trailingWhitespaceRatio,
expectedRatioThreshold);
+        assertGreaterThan("leading whitespace is longer than no whitespace",
+                leadingWhitespaceRatio, expectedRatioThreshold);
+        assertGreaterThan("trailing whitespace is longer than no whitespace",
+                trailingWhitespaceRatio, expectedRatioThreshold);
         assertEquals("cells with equal leading and trailing whitespace have equal width",
                 leadingWhitespaceColWidth, trailingWhitespaceColWidth);
         

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java Sun Jan 13 17:14:24
2019
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -258,25 +259,25 @@ public abstract class BaseTestRow {
         // First up, no policy given, uses default
         assertEquals(CellType.STRING,  row.getCell(0).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
-        assertEquals(null, row.getCell(2));
-        assertEquals(null, row.getCell(3));
+        assertNull(row.getCell(2));
+        assertNull(row.getCell(3));
         assertEquals(CellType.BLANK,   row.getCell(4).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
 
         // RETURN_NULL_AND_BLANK - same as default
         assertEquals(CellType.STRING,  row.getCell(0, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
-        assertEquals(null, row.getCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK));
-        assertEquals(null, row.getCell(3, MissingCellPolicy.RETURN_NULL_AND_BLANK));
+        assertNull(row.getCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK));
+        assertNull(row.getCell(3, MissingCellPolicy.RETURN_NULL_AND_BLANK));
         assertEquals(CellType.BLANK,   row.getCell(4, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
 
         // RETURN_BLANK_AS_NULL - nearly the same
         assertEquals(CellType.STRING,  row.getCell(0, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
-        assertEquals(null, row.getCell(2, MissingCellPolicy.RETURN_BLANK_AS_NULL));
-        assertEquals(null, row.getCell(3, MissingCellPolicy.RETURN_BLANK_AS_NULL));
-        assertEquals(null, row.getCell(4, MissingCellPolicy.RETURN_BLANK_AS_NULL));
+        assertNull(row.getCell(2, MissingCellPolicy.RETURN_BLANK_AS_NULL));
+        assertNull(row.getCell(3, MissingCellPolicy.RETURN_BLANK_AS_NULL));
+        assertNull(row.getCell(4, MissingCellPolicy.RETURN_BLANK_AS_NULL));
         assertEquals(CellType.NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
 
         // CREATE_NULL_AS_BLANK - creates as needed
@@ -302,9 +303,9 @@ public abstract class BaseTestRow {
 
         assertEquals(CellType.STRING,  row.getCell(0).getCellType());
         assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
-        assertEquals(null, row.getCell(2));
-        assertEquals(null, row.getCell(3));
-        assertEquals(null, row.getCell(4));
+        assertNull(row.getCell(2));
+        assertNull(row.getCell(3));
+        assertNull(row.getCell(4));
         assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
         
         workbook.close();
@@ -376,36 +377,36 @@ public abstract class BaseTestRow {
         Cell cell1 = row.createCell(1);
         Iterator<Cell> it = row.cellIterator();
         assertTrue(it.hasNext());
-        assertTrue(cell1 == it.next());
+        assertSame(cell1, it.next());
         assertFalse(it.hasNext());
 
         // Add another cell at the end
         Cell cell2 = row.createCell(99);
         it = row.cellIterator();
         assertTrue(it.hasNext());
-        assertTrue(cell1 == it.next());
+        assertSame(cell1, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell2 == it.next());
+        assertSame(cell2, it.next());
 
         // Add another cell at the beginning
         Cell cell3 = row.createCell(0);
         it = row.cellIterator();
         assertTrue(it.hasNext());
-        assertTrue(cell3 == it.next());
+        assertSame(cell3, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell1 == it.next());
+        assertSame(cell1, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell2 == it.next());
+        assertSame(cell2, it.next());
 
         // Replace cell1
         Cell cell4 = row.createCell(1);
         it = row.cellIterator();
         assertTrue(it.hasNext());
-        assertTrue(cell3 == it.next());
+        assertSame(cell3, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell4 == it.next());
+        assertSame(cell4, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell2 == it.next());
+        assertSame(cell2, it.next());
         assertFalse(it.hasNext());
 
         // Add another cell, specifying the cellType
@@ -413,13 +414,13 @@ public abstract class BaseTestRow {
         it = row.cellIterator();
         assertNotNull(cell5);
         assertTrue(it.hasNext());
-        assertTrue(cell3 == it.next());
+        assertSame(cell3, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell4 == it.next());
+        assertSame(cell4, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell5 == it.next());
+        assertSame(cell5, it.next());
         assertTrue(it.hasNext());
-        assertTrue(cell2 == it.next());
+        assertSame(cell2, it.next());
         assertEquals(CellType.STRING, cell5.getCellType());
         wb.close();
     }
@@ -432,10 +433,10 @@ public abstract class BaseTestRow {
        Row row2 = sheet.createRow(1);
 
        // Won't be styled currently
-       assertEquals(false, row1.isFormatted());
-       assertEquals(false, row2.isFormatted());
-       assertEquals(null, row1.getRowStyle());
-       assertEquals(null, row2.getRowStyle());
+        assertFalse(row1.isFormatted());
+        assertFalse(row2.isFormatted());
+        assertNull(row1.getRowStyle());
+        assertNull(row2.getRowStyle());
 
        // Style one
        CellStyle style = wb1.createCellStyle();
@@ -443,9 +444,9 @@ public abstract class BaseTestRow {
        row2.setRowStyle(style);
 
        // Check
-       assertEquals(false, row1.isFormatted());
-       assertEquals(true, row2.isFormatted());
-       assertEquals(null, row1.getRowStyle());
+        assertFalse(row1.isFormatted());
+        assertTrue(row2.isFormatted());
+        assertNull(row1.getRowStyle());
        assertEquals(style, row2.getRowStyle());
 
        // Save, load and re-check
@@ -458,9 +459,9 @@ public abstract class BaseTestRow {
        row2 = sheet.getRow(1);
        style = wb2.getCellStyleAt(style.getIndex());
 
-       assertEquals(false, row1.isFormatted());
-       assertEquals(true, row2.isFormatted());
-       assertEquals(null, row1.getRowStyle());
+        assertFalse(row1.isFormatted());
+        assertTrue(row2.isFormatted());
+        assertNull(row1.getRowStyle());
        assertEquals(style, row2.getRowStyle());
        assertEquals(4, style.getDataFormat());
        

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java?rev=1851210&r1=1851209&r2=1851210&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
Sun Jan 13 17:14:24 2019
@@ -71,6 +71,7 @@ public abstract class BaseTestSheetUpdat
         
         workbook.close();
     }
+
     /**
      *  Set single-cell array formula
      */

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=1851210&r1=1851209&r2=1851210&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 Sun Jan 13 17:14:24
2019
@@ -465,7 +465,7 @@ public final class TestCellReference {
 
     @Test
     public void test62828() {
-        Workbook wb = new HSSFWorkbook();
+        final Workbook wb = new HSSFWorkbook();
         final Sheet sheet = wb.createSheet("Ctor test");
         final String sheetName = sheet.getSheetName();
         final Row row = sheet.createRow(0);



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


Mime
View raw message