[github-342] Use foreach. Thanks to XenoAmess. This closes #342

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-07-16 18:08:50 +00:00
parent 4f54f29a2d
commit 22badcef27
29 changed files with 94 additions and 114 deletions

View File

@ -160,8 +160,7 @@ public class XSSFDataValidationHelper implements DataValidationHelper {
CellRangeAddress[] cellRangeAddresses = cellRangeAddressList.getCellRangeAddresses();
List<String> sqref = new ArrayList<>();
for (int i = 0; i < cellRangeAddresses.length; i++) {
CellRangeAddress cellRangeAddress = cellRangeAddresses[i];
for (CellRangeAddress cellRangeAddress : cellRangeAddresses) {
sqref.add(cellRangeAddress.formatAsString());
}
newDataValidation.setSqref(sqref);

View File

@ -85,15 +85,15 @@ public abstract class EscherPart extends HPBFPart {
*/
protected void generateData() {
int size = 0;
for(int i=0; i<records.length; i++) {
size += records[i].getRecordSize();
for (EscherRecord escherRecord : records) {
size += escherRecord.getRecordSize();
}
byte[] data = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
size = 0;
for(int i=0; i<records.length; i++) {
for (EscherRecord record : records) {
int thisSize =
records[i].serialize(size, data);
record.serialize(size, data);
size += thisSize;
}

View File

@ -67,19 +67,19 @@ public final class SLWTTextListing {
// Loop over the records, printing the text
Record[] slwtc = thisSets[k].getSlideRecords();
for(int l=0; l<slwtc.length; l++) {
for (Record record : slwtc) {
String text = null;
if(slwtc[l] instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom)slwtc[l];
if (record instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom) record;
text = tba.getText();
}
if(slwtc[l] instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom)slwtc[l];
if (record instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom) record;
text = tca.getText();
}
if(text != null) {
text = text.replace('\r','\n');
if (text != null) {
text = text.replace('\r', '\n');
System.out.println(" ''" + text + "''");
}
}

View File

@ -160,12 +160,12 @@ public final class MovieShape extends HSLFPictureShape {
}
Record[] r = lst.getChildRecords();
for (int i = 0; i < r.length; i++) {
if(r[i] instanceof ExMCIMovie){
ExMCIMovie mci = (ExMCIMovie)r[i];
for (Record record : r) {
if (record instanceof ExMCIMovie) {
ExMCIMovie mci = (ExMCIMovie) record;
ExVideoContainer exVideo = mci.getExVideo();
int objectId = exVideo.getExMediaAtom().getObjectId();
if(objectId == idx){
if (objectId == idx) {
return exVideo.getPathAtom().getText();
}
}

View File

@ -52,11 +52,11 @@ public final class Environment extends PositionDependentRecordContainer
_children = Record.findChildRecords(source,start+8,len-8);
// Find our FontCollection record
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof FontCollection) {
fontCollection = (FontCollection)_children[i];
} else if (_children[i] instanceof TxMasterStyleAtom){
txmaster = (TxMasterStyleAtom)_children[i];
for (Record child : _children) {
if (child instanceof FontCollection) {
fontCollection = (FontCollection) child;
} else if (child instanceof TxMasterStyleAtom) {
txmaster = (TxMasterStyleAtom) child;
}
}

View File

@ -43,9 +43,9 @@ public class ExObjList extends RecordContainer {
*/
public ExHyperlink[] getExHyperlinks() {
ArrayList<ExHyperlink> links = new ArrayList<>();
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof ExHyperlink) {
links.add( (ExHyperlink)_children[i] );
for (Record child : _children) {
if (child instanceof ExHyperlink) {
links.add((ExHyperlink) child);
}
}
@ -114,10 +114,10 @@ public class ExObjList extends RecordContainer {
* @return found <code>ExHyperlink</code> or <code>null</code>
*/
public ExHyperlink get(int id){
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof ExHyperlink) {
ExHyperlink rec = (ExHyperlink)_children[i];
if (rec.getExHyperlinkAtom().getNumber() == id){
for (Record child : _children) {
if (child instanceof ExHyperlink) {
ExHyperlink rec = (ExHyperlink) child;
if (rec.getExHyperlinkAtom().getNumber() == id) {
return rec;
}
}

View File

@ -75,13 +75,13 @@ public final class HSLFSoundData {
public static HSLFSoundData[] find(Document document){
ArrayList<HSLFSoundData> lst = new ArrayList<>();
org.apache.poi.hslf.record.Record[] ch = document.getChildRecords();
for (int i = 0; i < ch.length; i++) {
if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){
RecordContainer col = (RecordContainer)ch[i];
org.apache.poi.hslf.record.Record[] sr = col.getChildRecords();
for (int j = 0; j < sr.length; j++) {
if(sr[j] instanceof Sound){
lst.add(new HSLFSoundData((Sound)sr[j]));
for (Record value : ch) {
if (value.getRecordType() == RecordTypes.SoundCollection.typeID) {
RecordContainer col = (RecordContainer) value;
Record[] sr = col.getChildRecords();
for (Record record : sr) {
if (record instanceof Sound) {
lst.add(new HSLFSoundData((Sound) record));
}
}
}

View File

@ -161,8 +161,8 @@ public final class Ffn {
System.arraycopy(_fontSig, 0, buf, offset, _fontSig.length);
offset += _fontSig.length;
for (int i = 0; i < _xszFfn.length; i++) {
LittleEndian.putShort(buf, offset, (short) _xszFfn[i]);
for (char c : _xszFfn) {
LittleEndian.putShort(buf, offset, (short) c);
offset += LittleEndianConsts.SHORT_SIZE;
}

View File

@ -129,9 +129,8 @@ public final class FontTable
LittleEndian.putShort(buf, 0, _extraDataSz);
tableStream.write(buf);
for(int i = 0; i < _fontNames.length; i++)
{
tableStream.write(_fontNames[i].toByteArray());
for (Ffn fontName : _fontNames) {
tableStream.write(fontName.toByteArray());
}
}

View File

@ -93,8 +93,7 @@ public class HSSFRequest {
if (listeners != null) {
for (int k = 0; k < listeners.size(); k++) {
Object listenObj = listeners.get(k);
for (Object listenObj : listeners) {
if (listenObj instanceof AbortableHSSFListener) {
AbortableHSSFListener listener = (AbortableHSSFListener) listenObj;
userCode = listener.abortableProcessRecord(rec);

View File

@ -294,10 +294,7 @@ final class LinkTable {
* @param sheetNumber 1-based sheet number
*/
public NameRecord getSpecificBuiltinRecord(byte builtInCode, int sheetNumber) {
Iterator<NameRecord> iterator = _definedNames.iterator();
while (iterator.hasNext()) {
NameRecord record = iterator.next();
for (NameRecord record : _definedNames) {
//print areas are one based
if (record.getBuiltInName() == builtInCode && record.getSheetNumber() == sheetNumber) {
return record;

View File

@ -173,8 +173,7 @@ public final class ObjRecord extends Record {
if (_uninterpretedData == null) {
for (int i = 0; i < subrecords.size(); i++) {
SubRecord record = subrecords.get(i);
for (SubRecord record : subrecords) {
record.serialize(out);
}
int expectedEndIx = offset + dataSize;

View File

@ -69,12 +69,11 @@ public final class ChartSubstreamRecordAggregate extends RecordAggregate {
return;
}
rv.visitRecord(_bofRec);
for (int i = 0; i < _recs.size(); i++) {
RecordBase rb = _recs.get(i);
for (RecordBase rb : _recs) {
if (rb instanceof RecordAggregate) {
((RecordAggregate) rb).visitContainedRecords(rv);
} else {
rv.visitRecord((org.apache.poi.hssf.record.Record) rb);
rv.visitRecord((Record) rb);
}
}
rv.visitRecord(EOFRecord.instance);

View File

@ -73,12 +73,11 @@ public final class CustomViewSettingsRecordAggregate extends RecordAggregate {
return;
}
rv.visitRecord(_begin);
for (int i = 0; i < _recs.size(); i++) {
RecordBase rb = _recs.get(i);
for (RecordBase rb : _recs) {
if (rb instanceof RecordAggregate) {
((RecordAggregate) rb).visitContainedRecords(rv);
} else {
rv.visitRecord((org.apache.poi.hssf.record.Record) rb);
rv.visitRecord((Record) rb);
}
}
rv.visitRecord(_end);

View File

@ -131,11 +131,10 @@ public final class ValueRecordsAggregate implements Iterable<CellValueRecordInte
public int getPhysicalNumberOfCells() {
int count = 0;
for (int r = 0; r < records.length; r++) {
CellValueRecordInterface[] rowCells = records[r];
for (CellValueRecordInterface[] rowCells : records) {
if (rowCells != null) {
for (int c = 0; c < rowCells.length; c++) {
if (rowCells[c] != null)
for (CellValueRecordInterface rowCell : rowCells) {
if (rowCell != null)
count++;
}
}
@ -201,8 +200,9 @@ public final class ValueRecordsAggregate implements Iterable<CellValueRecordInte
}
CellValueRecordInterface[] rowCells=records[row];
if(rowCells==null) return false;
for(int col=0;col<rowCells.length;col++) {
if(rowCells[col]!=null) return true;
for (CellValueRecordInterface rowCell : rowCells) {
if (rowCell != null)
return true;
}
return false;
}
@ -281,17 +281,16 @@ public final class ValueRecordsAggregate implements Iterable<CellValueRecordInte
}
public void updateFormulasAfterRowShift(FormulaShifter shifter, int currentExternSheetIndex) {
for (int i = 0; i < records.length; i++) {
CellValueRecordInterface[] rowCells = records[i];
for (CellValueRecordInterface[] rowCells : records) {
if (rowCells == null) {
continue;
}
for (int j = 0; j < rowCells.length; j++) {
CellValueRecordInterface cell = rowCells[j];
for (CellValueRecordInterface cell : rowCells) {
if (cell instanceof FormulaRecordAggregate) {
FormulaRecordAggregate fra = (FormulaRecordAggregate)cell;
FormulaRecordAggregate fra = (FormulaRecordAggregate) cell;
Ptg[] ptgs = fra.getFormulaTokens(); // needs clone() inside this getter?
Ptg[] ptgs2 = ((FormulaRecordAggregate)cell).getFormulaRecord().getParsedExpression(); // needs clone() inside this getter?
Ptg[] ptgs2 = ((FormulaRecordAggregate) cell).getFormulaRecord().getParsedExpression(); // needs
// clone() inside this getter?
if (shifter.adjustFormula(ptgs, currentExternSheetIndex)) {
fra.setParsedExpression(ptgs);

View File

@ -55,9 +55,7 @@ public final class HSSFDataFormat implements DataFormat {
HSSFDataFormat(InternalWorkbook workbook) {
_workbook = workbook;
Iterator<FormatRecord> i = workbook.getFormats().iterator();
while (i.hasNext()) {
FormatRecord r = i.next();
for (FormatRecord r : workbook.getFormats()) {
ensureFormatsSize(r.getIndexCode());
_formats.set(r.getIndexCode(), r.getFormatString());
}

View File

@ -82,10 +82,8 @@ public final class HSSFObjectData extends HSSFPicture implements ObjectData {
* Exception if there wasn't one
*/
protected EmbeddedObjectRefSubRecord findObjectRecord() {
Iterator<SubRecord> subRecordIter = getObjRecord().getSubRecords().iterator();
while (subRecordIter.hasNext()) {
Object subRecord = subRecordIter.next();
for (Object subRecord : getObjRecord().getSubRecords()) {
if (subRecord instanceof EmbeddedObjectRefSubRecord) {
return (EmbeddedObjectRefSubRecord) subRecord;
}

View File

@ -67,11 +67,10 @@ public class POIFSViewEngine
{
Object[] data = inspected.getViewableArray();
for (int j = 0; j < data.length; j++)
{
objects.addAll(inspectViewable(data[ j ], drilldown,
indentLevel + 1,
indentString));
for (Object datum : data) {
objects.addAll(inspectViewable(datum, drilldown,
indentLevel + 1,
indentString));
}
}
else

View File

@ -111,8 +111,7 @@ abstract class CellCacheEntry implements ICacheEntry {
protected final void recurseClearCachedFormulaResults() {
FormulaCellCacheEntry[] formulaCells = getConsumingCells();
for (int i = 0; i < formulaCells.length; i++) {
FormulaCellCacheEntry fc = formulaCells[i];
for (FormulaCellCacheEntry fc : formulaCells) {
fc.clearFormulaEntry();
if (fc != this) {
fc.recurseClearCachedFormulaResults();
@ -127,11 +126,10 @@ abstract class CellCacheEntry implements ICacheEntry {
FormulaCellCacheEntry[] formulaCells = getConsumingCells();
listener.sortDependentCachedValues(formulaCells);
for (int i = 0; i < formulaCells.length; i++) {
FormulaCellCacheEntry fc = formulaCells[i];
for (FormulaCellCacheEntry fc : formulaCells) {
listener.onClearDependentCachedValue(fc, depth);
fc.clearFormulaEntry();
fc.recurseClearCachedFormulaResults(listener, depth+1);
fc.recurseClearCachedFormulaResults(listener, depth + 1);
}
}
}

View File

@ -61,9 +61,8 @@ final class FormulaCellCache {
}
public void applyOperation(IEntryOperation operation) {
Iterator<FormulaCellCacheEntry> i = _formulaEntriesByCell.values().iterator();
while (i.hasNext()) {
operation.processEntry(i.next());
for (FormulaCellCacheEntry formulaCellCacheEntry : _formulaEntriesByCell.values()) {
operation.processEntry(formulaCellCacheEntry);
}
}
}

View File

@ -80,8 +80,8 @@ final class FormulaCellCacheEntry extends CellCacheEntry {
CellCacheEntry[] prevUsedCells = _sensitiveInputCells;
int nUsed = usedCells.length;
for (int i = 0; i < nUsed; i++) {
usedCells[i].addConsumingCell(this);
for (CellCacheEntry usedCell : usedCells) {
usedCell.addConsumingCell(this);
}
if (prevUsedCells == null) {
return;
@ -97,8 +97,7 @@ final class FormulaCellCacheEntry extends CellCacheEntry {
usedSet = new HashSet<>(nUsed * 3 / 2);
usedSet.addAll(Arrays.asList(usedCells).subList(0, nUsed));
}
for (int i = 0; i < nPrevUsed; i++) {
CellCacheEntry prevUsed = prevUsedCells[i];
for (CellCacheEntry prevUsed : prevUsedCells) {
if (!usedSet.contains(prevUsed)) {
// previously was used by cellLoc, but not anymore
prevUsed.clearConsumingCell(this);

View File

@ -41,8 +41,7 @@ final class FormulaCellCacheEntrySet {
}
FormulaCellCacheEntry[] result = new FormulaCellCacheEntry[nItems];
int j=0;
for(int i=0; i<_arr.length; i++) {
FormulaCellCacheEntry cce = _arr[i];
for (FormulaCellCacheEntry cce : _arr) {
if (cce != null) {
result[j++] = cce;
}

View File

@ -61,8 +61,8 @@ public final class Count implements Function {
int temp = 0;
for(int i=0; i<nArgs; i++) {
temp += CountUtils.countArg(args[i], _predicate);
for (ValueEval arg : args) {
temp += CountUtils.countArg(arg, _predicate);
}
return new NumberEval(temp);

View File

@ -57,8 +57,8 @@ public final class Counta implements Function {
int temp = 0;
for(int i=0; i<nArgs; i++) {
temp += CountUtils.countArg(args[i], _predicate);
for (ValueEval arg : args) {
temp += CountUtils.countArg(arg, _predicate);
}
return new NumberEval(temp);

View File

@ -63,13 +63,13 @@ public class Gcd implements FreeRefFunction {
} else {
try {
ArrayList<Long> evals = new ArrayList<>();
for (int i = 0; i < args.length; i++) {
ValueEval ve = OperandResolver.getSingleValue(args[i], ec.getRowIndex(), ec.getColumnIndex());
for (ValueEval arg : args) {
ValueEval ve = OperandResolver.getSingleValue(arg, ec.getRowIndex(), ec.getColumnIndex());
double d = OperandResolver.coerceValueToDouble(ve);
if (isInvalidInput(d)) {
return ErrorEval.NUM_ERROR;
}
evals.add((long)d);
evals.add((long) d);
}
long result = evals.get(0);
for (int i = 1; i < evals.size(); i++) {

View File

@ -63,13 +63,13 @@ public class Lcm implements FreeRefFunction {
} else {
try {
ArrayList<Long> evals = new ArrayList<>();
for (int i = 0; i < args.length; i++) {
ValueEval ve = OperandResolver.getSingleValue(args[i], ec.getRowIndex(), ec.getColumnIndex());
for (ValueEval arg : args) {
ValueEval ve = OperandResolver.getSingleValue(arg, ec.getRowIndex(), ec.getColumnIndex());
double d = OperandResolver.coerceValueToDouble(ve);
if (isInvalidInput(d)) {
return ErrorEval.NUM_ERROR;
}
evals.add((long)d);
evals.add((long) d);
}
long result = evals.get(0);
for (int i = 1; i < evals.size(); i++) {

View File

@ -114,8 +114,8 @@ public abstract class MultiOperandNumericFunction implements Function {
}
DoubleList retval = new DoubleList();
for (int i = 0, iSize = operands.length; i < iSize; i++) {
collectValues(operands[i], retval);
for (ValueEval operand : operands) {
collectValues(operand, retval);
}
return retval.toArray();
}

View File

@ -37,13 +37,13 @@ final class StatsLib {
double r = 0;
double m = 0;
double s = 0;
for (int i=0, iSize=v.length; i<iSize; i++) {
s += v[i];
for (double item : v) {
s += item;
}
m = s / v.length;
s = 0;
for (int i=0, iSize=v.length; i<iSize; i++) {
s += Math.abs(v[i]-m);
for (double value : v) {
s += Math.abs(value - m);
}
r = s / v.length;
return r;
@ -102,13 +102,13 @@ final class StatsLib {
double m = 0;
double s = 0;
int n = v.length;
for (int i=0; i<n; i++) {
s += v[i];
for (double item : v) {
s += item;
}
m = s / n;
s = 0;
for (int i=0; i<n; i++) {
s += (v[i]- m) * (v[i] - m);
for (double value : v) {
s += (value - m) * (value - m);
}
r = (n == 1)

View File

@ -78,8 +78,8 @@ final class TestCellRangeUtil {
private static Set<CellAddress> getCellAddresses(CellRangeAddress[] ranges) {
final Set<CellAddress> set = new HashSet<>();
for (final CellRangeAddress range : ranges) {
for (Iterator<CellAddress> iter = range.iterator(); iter.hasNext(); ) {
set.add(iter.next());
for (CellAddress cellAddress : range) {
set.add(cellAddress);
}
}
return set;