poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1751086 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/xdgf/geom/ ooxml/java/org/apache/poi/xssf/extractor/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/java/o...
Date Sat, 02 Jul 2016 18:28:43 GMT
Author: onealj
Date: Sat Jul  2 18:28:43 2016
New Revision: 1751086

URL: http://svn.apache.org/viewvc?rev=1751086&view=rev
Log:
bug 59773: move loop invariants outside of loop or change for loops to for-each loops

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java Sat Jul  2 18:28:43 2016
@@ -135,7 +135,8 @@ public final class HSSFName implements N
         int sheetNumber = _definedNameRec.getSheetNumber();
 
         //Check to ensure no other names have the same case-insensitive name
-        for ( int i = wb.getNumNames()-1; i >=0; i-- )
+        final int lastNameIndex = wb.getNumNames()-1;
+        for ( int i = lastNameIndex; i >=0; i-- )
         {
             NameRecord rec = wb.getNameRecord(i);
             if (rec != _definedNameRec) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sat Jul  2 18:28:43 2016
@@ -1640,7 +1640,8 @@ public final class HSSFSheet implements
             if (moveComments) {
                 // This code would get simpler if NoteRecords could be organised by HSSFRow.
                 HSSFPatriarch patriarch = createDrawingPatriarch();
-                for (int i = patriarch.getChildren().size() - 1; i >= 0; i--) {
+                final int lastChildIndex = patriarch.getChildren().size() - 1;
+                for (int i = lastChildIndex; i >= 0; i--) {
                     HSSFShape shape = patriarch.getChildren().get(i);
                     if (!(shape instanceof HSSFComment)) {
                         continue;
@@ -2372,7 +2373,9 @@ public final class HSSFSheet implements
 
         //create a combobox control for each column
         HSSFPatriarch p = createDrawingPatriarch();
-        for (int col = range.getFirstColumn(); col <= range.getLastColumn(); col++) {
+        final int firstColumn = range.getFirstColumn();
+        final int lastColumn = range.getLastColumn();
+        for (int col = firstColumn; col <= lastColumn; col++) {
             p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0,
                     (short) col, firstRow, (short) (col + 1), firstRow + 1));
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java Sat Jul  2
18:28:43 2016
@@ -289,7 +289,8 @@ public final class PackagePartName imple
 	private static void checkPCharCompliance(String segment)
 			throws InvalidFormatException {
 		boolean errorFlag;
-		for (int i = 0; i < segment.length(); ++i) {
+		final int length = segment.length();
+		for (int i = 0; i < length; ++i) {
 			char c = segment.charAt(i);
 			errorFlag = true;
 
@@ -328,7 +329,7 @@ public final class PackagePartName imple
 			if (errorFlag && c == '%') {
 				// We certainly found an encoded character, check for length
 				// now ( '%' HEXDIGIT HEXDIGIT)
-				if (((segment.length() - i) < 2)) {
+				if (((length - i) < 2)) {
 					throw new InvalidFormatException("The segment " + segment
 							+ " contain invalid encoded character !");
 				}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java Sat Jul
 2 18:28:43 2016
@@ -606,12 +606,13 @@ public final class PackagingURIHelper {
 		StringBuffer retVal = new StringBuffer();
 		String uriStr = uri.toASCIIString();
 		char c;
-		for (int i = 0; i < uriStr.length(); ++i) {
+		final int length = uriStr.length();
+		for (int i = 0; i < length; ++i) {
 			c = uriStr.charAt(i);
 			if (c == '%') {
 				// We certainly found an encoded character, check for length
 				// now ( '%' HEXDIGIT HEXDIGIT)
-				if (((uriStr.length() - i) < 2)) {
+				if (((length - i) < 2)) {
 					throw new IllegalArgumentException("The uri " + uriStr
 							+ " contain invalid encoded character !");
 				}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/geom/SplineRenderer.java Sat Jul  2 18:28:43
2016
@@ -30,15 +30,17 @@ public class SplineRenderer {
             ValueVector knots, ValueVector weights, int degree) {
 
         double firstKnot = knots.get(0);
-        double lastKnot = knots.get(knots.size() - 1);
+        final int count = knots.size();
+        double lastKnot = knots.get(count - 1);
 
         // scale knots to [0, 1] based on first/last knots
-        for (int i = 0; i < knots.size(); i++) {
+        for (int i = 0; i < count; i++) {
             knots.set((knots.get(i) - firstKnot) / lastKnot, i);
         }
 
         // if we don't have enough knots, duplicate the last knot until we do
-        for (int i = knots.size(); i < controlPoints.numPoints() + degree + 1; i++) {
+        final int  knotsToAdd = controlPoints.numPoints() + degree + 1;
+        for (int i = count; i < knotsToAdd; i++) {
             knots.add(1);
         }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java Sat Jul
 2 18:28:43 2016
@@ -30,6 +30,7 @@ import org.apache.poi.ss.usermodel.Comme
 import org.apache.poi.ss.usermodel.DataFormatter;
 import org.apache.poi.ss.usermodel.HeaderFooter;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFDrawing;
 import org.apache.poi.xssf.usermodel.XSSFRelation;
@@ -134,10 +135,10 @@ public class XSSFExcelExtractor extends
         }
 
         StringBuffer text = new StringBuffer();
-        for(int i=0; i<workbook.getNumberOfSheets(); i++) {
-            XSSFSheet sheet = workbook.getSheetAt(i);
+        for(Sheet sh : workbook) {
+            XSSFSheet sheet = (XSSFSheet) sh;
             if(includeSheetNames) {
-                text.append(workbook.getSheetName(i)).append("\n");
+                text.append(sheet.getSheetName()).append("\n");
             }
 
             // Header(s), if present

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java Sat Jul  2 18:28:43
2016
@@ -239,7 +239,8 @@ public class SXSSFWorkbook implements Wo
         {
             _wb=workbook;
             _sharedStringSource = useSharedStringsTable ? _wb.getSharedStringSource() : null;
-            for ( int i = 0; i < _wb.getNumberOfSheets(); i++ )
+            final int numberOfSheets = _wb.getNumberOfSheets();
+            for ( int i = 0; i < numberOfSheets; i++ )
             {
                 XSSFSheet sheet = _wb.getSheetAt( i );
                 createAndRegisterSXSSFSheet( sheet );

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java Sat
Jul  2 18:28:43 2016
@@ -50,11 +50,12 @@ public final class XSSFEvaluationWorkboo
     public EvaluationSheet getSheet(int sheetIndex) {
         // Performance optimization: build sheet cache the first time this is called
         // to avoid re-creating the XSSFEvaluationSheet each time a new cell is evaluated
-        // EvaluationWorkbooks make not guarentee to syncronize changes made to
+        // EvaluationWorkbooks make not guarantee to synchronize changes made to
         // the underlying workbook after the EvaluationWorkbook is created.
         if (_sheetCache == null) {
-            _sheetCache = new XSSFEvaluationSheet[_uBook.getNumberOfSheets()];
-            for (int i=0; i < _uBook.getNumberOfSheets(); i++) {
+            final int numberOfSheets = _uBook.getNumberOfSheets();
+            _sheetCache = new XSSFEvaluationSheet[numberOfSheets];
+            for (int i=0; i < numberOfSheets; i++) {
                 _sheetCache[i] = new XSSFEvaluationSheet(_uBook.getSheetAt(i));
             }
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Sat Jul
 2 18:28:43 2016
@@ -379,18 +379,17 @@ public class XSSFRichTextString implemen
      *                      index is out of range.
      */
     public XSSFFont getFontAtIndex( int index ) {
-        if(st.sizeOfRArray() == 0) return null;
-
+        final ThemesTable themes = getThemesTable();
         int pos = 0;
-        for(int i = 0; i < st.sizeOfRArray(); i++){
-            CTRElt r = st.getRArray(i);
-            if(index >= pos && index < pos + r.getT().length()) {
+        for(CTRElt r : st.getRArray()){
+            final int length = r.getT().length();
+            if(index >= pos && index < pos + length) {
                XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr()));
-               fnt.setThemesTable(getThemesTable());
+               fnt.setThemesTable(themes);
                return fnt;
             }
 
-            pos += r.getT().length();
+            pos += length;
         }
         return null;
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sat Jul  2 18:28:43
2016
@@ -2674,7 +2674,8 @@ public class XSSFSheet extends POIXMLDoc
     public int findEndOfRowOutlineGroup(int row) {
         short level = getRow(row).getCTRow().getOutlineLevel();
         int currentRow;
-        for (currentRow = row; currentRow < getLastRowNum(); currentRow++) {
+        final int lastRowNum = getLastRowNum();
+        for (currentRow = row; currentRow < lastRowNum; currentRow++) {
             if (getRow(currentRow) == null
                     || getRow(currentRow).getCTRow().getOutlineLevel() < level) {
                 break;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sat Jul  2 18:28:43
2016
@@ -1084,11 +1084,12 @@ public class XSSFWorkbook extends POIXML
      */
     @Override
     public int getSheetIndex(String name) {
-        for (int i = 0 ; i < sheets.size() ; ++i) {
-            XSSFSheet sheet = sheets.get(i);
-            if (name.equalsIgnoreCase(sheet.getSheetName())) {
-                return i;
+        int idx = 0;
+        for (XSSFSheet sh : sheets) {
+            if (name.equalsIgnoreCase(sh.getSheetName())) {
+                return idx;
             }
+            idx++;
         }
         return -1;
     }
@@ -1264,12 +1265,13 @@ public class XSSFWorkbook extends POIXML
 
     @Override
     public void removeName(String name) {
-        for (int i = 0; i < namedRanges.size(); i++) {
-            XSSFName nm = namedRanges.get(i);
+        int idx = 0;
+        for (XSSFName nm : namedRanges) {
             if(nm.getNameName().equalsIgnoreCase(name)) {
-                removeName(i);
+                removeName(idx);
                 return;
             }
+            idx++;
         }
         throw new IllegalArgumentException("Named range was not found: " + name);
     }
@@ -1551,9 +1553,10 @@ public class XSSFWorkbook extends POIXML
      */
     @Override
     public void setSelectedTab(int index) {
-        for (int i = 0 ; i < sheets.size() ; ++i) {
-            XSSFSheet sheet = sheets.get(i);
-            sheet.setSelected(i == index);
+        int idx = 0;
+        for (XSSFSheet sh : sheets) {
+            sh.setSelected(idx == index);
+            idx++;
         }
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java Sat
Jul  2 18:28:43 2016
@@ -64,7 +64,8 @@ public final class XSSFFormulaUtils {
      */
     public void updateSheetName(final int sheetIndex, final String oldName, final String
newName) {
         // update named ranges
-        for (int i = 0; i < _wb.getNumberOfNames(); i++) {
+        final int numberOfNames = _wb.getNumberOfNames();
+        for (int i = 0; i < numberOfNames; i++) {
             XSSFName nm = _wb.getNameAt(i);
             if (nm.getSheetIndex() == -1 || nm.getSheetIndex() == sheetIndex) {
                 updateName(nm, oldName, newName);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java?rev=1751086&r1=1751085&r2=1751086&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java Sat
Jul  2 18:28:43 2016
@@ -85,7 +85,8 @@ public final class XSSFRowShifter extend
     public void updateNamedRanges(FormulaShifter shifter) {
         Workbook wb = sheet.getWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
-        for (int i = 0; i < wb.getNumberOfNames(); i++) {
+        final int numberOfNames = wb.getNumberOfNames();
+        for (int i = 0; i < numberOfNames; i++) {
             Name name = wb.getNameAt(i);
             String formula = name.getRefersToFormula();
             int sheetIndex = name.getSheetIndex();



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


Mime
View raw message