mirror of https://github.com/apache/poi.git
bug 59773: move loop invariants outside of loop or change for loops to for-each loops
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751086 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
80e3a64280
commit
af53515279
|
@ -135,7 +135,8 @@ public final class HSSFName implements Name {
|
|||
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) {
|
||||
|
|
|
@ -1640,7 +1640,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||
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 org.apache.poi.ss.usermodel.Sheet {
|
|||
|
||||
//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));
|
||||
}
|
||||
|
|
|
@ -289,7 +289,8 @@ public final class PackagePartName implements Comparable<PackagePartName> {
|
|||
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 implements Comparable<PackagePartName> {
|
|||
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 !");
|
||||
}
|
||||
|
|
|
@ -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 !");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.poi.ss.usermodel.Comment;
|
|||
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 POIXMLTextExtractor
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -239,7 +239,8 @@ public class SXSSFWorkbook implements Workbook {
|
|||
{
|
||||
_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 );
|
||||
|
|
|
@ -50,11 +50,12 @@ public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -379,18 +379,17 @@ public class XSSFRichTextString implements RichTextString {
|
|||
* 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;
|
||||
|
||||
|
|
|
@ -2674,7 +2674,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
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;
|
||||
|
|
|
@ -1084,11 +1084,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
*/
|
||||
@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 POIXMLDocument implements Workbook {
|
|||
|
||||
@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 POIXMLDocument implements Workbook {
|
|||
*/
|
||||
@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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -85,7 +85,8 @@ public final class XSSFRowShifter extends RowShifter {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue