Iterator<String> iter = iterable.iterator();
- for (int i = 0; i < expected.length; i++) {
+ for (String element : expected) {
Assert.assertEquals(true, iter.hasNext());
- Assert.assertEquals(expected[i], iter.next());
+ Assert.assertEquals(element, iter.next());
}
Assert.assertEquals(false, iter.hasNext());
POITextExtractor[] extractors =
new POITextExtractor[] { ooxmlExtractor, ole2Extractor };
- for (int i = 0; i < extractors.length; i++) {
- POITextExtractor extractor = extractors[i];
-
- String text = extractor.getText().replaceAll("[\r\t]", "");
+ for (POITextExtractor extractor : extractors) {
+ String text = extractor.getText().replaceAll("[\r\t]", "");
assertTrue(text.startsWith("First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n"));
Pattern pattern = Pattern.compile(".*13(\\.0+)?\\s+Sheet3.*", Pattern.DOTALL);
Matcher m = pattern.matcher(text);
}
}
- for (int j = 0; j < doubleOperandOperatorTypes.length; j++) {
- int operatorType = doubleOperandOperatorTypes[j];
+ for (int operatorType : doubleOperandOperatorTypes) {
final Row row1 = sheet.createRow(offset++);
cell_10 = row1.createCell(0);
// Get without recursing
Pointer[] ptrs = trailer.getChildPointers();
- for(int i=0; i<ptrs.length; i++) {
- Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
+ for (Pointer ptr : ptrs) {
+ Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
}
// Get with recursing into chunks
- for(int i=0; i<ptrs.length; i++) {
+ for (Pointer ptr : ptrs) {
Stream stream =
- Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
+ Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
if(stream instanceof ChunkStream) {
ChunkStream cStream = (ChunkStream)stream;
cStream.findChunks();
}
// Get with recursing into chunks and pointers
- for(int i=0; i<ptrs.length; i++) {
+ for (Pointer ptr : ptrs) {
Stream stream =
- Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
+ Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
if(stream instanceof PointerContainingStream) {
PointerContainingStream pStream =
(PointerContainingStream)stream;
// Within that, grab out the Hyperlink atoms
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
- for(int i=0; i<exObjList._children.length; i++) {
- Record ch = exObjList._children[i];
+ for (Record ch : exObjList._children) {
if(ch instanceof ExHyperlink) {
linksA.add((ExHyperlink) ch);
}
//grab UserEditAtom
UserEditAtom usredit = null;
Record[] _records = hss_empty.getRecords();
- for (int i = 0; i < _records.length; i++) {
- Record record = _records[i];
+ for (Record record : _records) {
if(record.getRecordType() == RecordTypes.UserEditAtom.typeID) {
usredit = (UserEditAtom)record;
}
//grab UserEditAtom
UserEditAtom usredit = null;
Record[] _records = hss_two.getRecords();
- for (int i = 0; i < _records.length; i++) {
- Record record = _records[i];
- if(_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) {
- usredit = (UserEditAtom)_records[i];
+ for (Record record : _records) {
+ if(record.getRecordType() == RecordTypes.UserEditAtom.typeID) {
+ usredit = (UserEditAtom)record;
}
}
assertNotNull(usredit);
@Test
public void testHandleParentAwareRecords() {
Record[] records = hss.getRecords();
- for(int i=0; i<records.length; i++) {
- ensureParentAware(records[i],null);
+ for (Record record : records) {
+ ensureParentAware(record,null);
}
}
private void ensureParentAware(Record r,RecordContainer parent) {
{
return file.isFile() && file.getName().startsWith("Test");
}});
- for (int i = 0; i < docs.length; i++)
- {
- final File doc = docs[i];
+ for (final File doc : docs) {
final Logger logger = Logger.getLogger(getClass().getName());
logger.info("Processing file \" " + doc.toString() + "\".");
}
});
- for (int i = 0; i < fileList.length; i++)
- {
- final File f = fileList[i];
+ for (final File f : fileList) {
/* Read the POI filesystem's property set streams: */
final POIFile[] psf1 = Util.readPropertySets(f);
Throwable thr = null;
final int[] validCodepages = new int[]
{CODEPAGE_DEFAULT, CODEPAGE_UTF8, CODEPAGE_UTF16, CODEPAGE_1252};
- for (int i = 0; i < validCodepages.length; i++)
- {
- final int cp = validCodepages[i];
+ for (final int cp : validCodepages) {
if (cp == -1 && !hasProperDefaultCharset())
{
System.err.println(IMPROPER_DEFAULT_CHARSET_MESSAGE +
}
final int[] invalidCodepages = new int[] {0, 1, 2, 4711, 815};
- for (int i = 0; i < invalidCodepages.length; i++)
- {
- int cp = invalidCodepages[i];
+ for (int cp : invalidCodepages) {
final long type = cp == CODEPAGE_UTF16 ? Variant.VT_LPWSTR
: Variant.VT_LPSTR;
try
}
});
- for (int i = 0; i < docs.length; i++)
- {
+ for (File doc : docs) {
try {
- task.runTest(docs[i]);
+ task.runTest(doc);
} catch (Exception e) {
- throw new IOException("While handling file " + docs[i], e);
+ throw new IOException("While handling file " + doc, e);
}
}
}
/* Register the listener for all POI files. */
r.registerListener(pfl);
else
- /* Register the listener for the specified POI files
- * only. */
- for (int i = 0; i < poiFiles.length; i++)
- r.registerListener(pfl, poiFiles[i]);
+ for (String poiFile : poiFiles)
+ r.registerListener(pfl, poiFile);
/* Read the POI filesystem. */
FileInputStream stream = new FileInputStream(poiFs);
for (Iterator<String> i = p.stringPropertyNames().iterator(); i.hasNext();)
names.add(i.next());
Collections.sort(names);
- for (final Iterator<String> i = names.iterator(); i.hasNext();)
- {
- String name = i.next();
+ for (String name : names) {
String value = p.getProperty(name);
System.out.println(name + ": " + value);
}
assertEquals("Sh3", stubHSSF.getSheetName(2));
// Check we can get the formula without breaking
- for(int i=0; i<fRecs.length; i++) {
- HSSFFormulaParser.toFormulaString(stubHSSF, fRecs[i].getParsedExpression());
+ for (FormulaRecord fRec : fRecs) {
+ HSSFFormulaParser.toFormulaString(stubHSSF, fRec.getParsedExpression());
}
// Peer into just one formula, and check that
String[] files = new String[] {
"45365.xls", "45365-2.xls", "MissingBits.xls"
};
- for(int k=0; k<files.length; k++) {
- processFile(files[k]);
+ for (String file : files) {
+ processFile(file);
// Check we found our formats
assertTrue(listener.getNumberOfCustomFormats() > 5);
assertTrue( recs.length > 100 );
// And none of them are continue ones
- for(int i=0; i<recs.length; i++) {
- assertFalse( recs[i] instanceof ContinueRecord );
+ for (Record rec : recs) {
+ assertFalse( rec instanceof ContinueRecord );
}
// Check that the last few records are as we expect
int eorCount=0;
int mbrCount=0;
int brCount=0;
- for (int i = 0; i < rr.length; i++) {
- Record record = rr[i];
+ for (Record record : rr) {
if (record instanceof MulBlankRecord) {
mbrCount++;
}
Record[] rr = r;
int missingCount=0;
int lastCount=0;
- for (int i = 0; i < rr.length; i++) {
- Record record = rr[i];
+ for (Record record : rr) {
if (record instanceof MissingCellDummyRecord) {
missingCount++;
}
boolean is11 = false;
int[] rowBreaks = sheet.getRowBreaks();
- for (int i = 0; i < rowBreaks.length; i++) {
- int main = rowBreaks[i];
+ for (int main : rowBreaks) {
if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
if (main == 0) is0 = true;
if (main == 10) is10= true;
boolean is15 = false;
int[] colBreaks = sheet.getColumnBreaks();
- for (int i = 0; i < colBreaks.length; i++) {
- int main = colBreaks[i];
+ for (int main : colBreaks) {
if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
if (main == 0) is0 = true;
if (main == 1) is1 = true;
EOFRecord.instance,
};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- for (int i = 0; i < recs.length; i++) {
+ for (Record rec : recs) {
try {
- baos.write(recs[i].serialize());
+ baos.write(rec.serialize());
} catch (IOException e) {
throw new RuntimeException(e);
}
private static int countSharedFormulas(HSSFSheet sheet) {
Record[] records = RecordInspector.getRecords(sheet, 0);
int count = 0;
- for (int i = 0; i < records.length; i++) {
- Record rec = records[i];
+ for (Record rec : records) {
if(rec instanceof SharedFormulaRecord) {
count++;
}
} while (attempt++ < MAX_ATTEMPTS);
int count=0;
- for (int i = 0; i < records.length; i++) {
- if (records[i] instanceof SharedFormulaRecord) {
+ for (Record record : records) {
+ if (record instanceof SharedFormulaRecord) {
count++;
}
}
} while (attempt++ < MAX_ATTEMPTS);
int count=0;
- for (int i = 0; i < records.length; i++) {
- if (records[i] instanceof SharedFormulaRecord) {
+ for (Record record : records) {
+ if (record instanceof SharedFormulaRecord) {
count++;
}
}
void checkRecordOrder(List<? extends RecordBase> records, CheckRecord[] check)
{
int recordIdx = 0;
- for ( int checkIdx = 0; checkIdx < check.length; checkIdx++ )
- {
- recordIdx = check[checkIdx].match(records, recordIdx);
+ for (CheckRecord element : check) {
+ recordIdx = element.match(records, recordIdx);
}
}
public void identifyDateFormats() {
// First up, try with a few built in date formats
short[] builtins = new short[] { 0x0e, 0x0f, 0x10, 0x16, 0x2d, 0x2e };
- for(int i=0; i<builtins.length; i++) {
- String formatStr = HSSFDataFormat.getBuiltinFormat(builtins[i]);
- assertTrue( HSSFDateUtil.isInternalDateFormat(builtins[i]) );
- assertTrue( HSSFDateUtil.isADateFormat(builtins[i],formatStr) );
+ for (short builtin : builtins) {
+ String formatStr = HSSFDataFormat.getBuiltinFormat(builtin);
+ assertTrue( HSSFDateUtil.isInternalDateFormat(builtin) );
+ assertTrue( HSSFDateUtil.isADateFormat(builtin,formatStr) );
}
// Now try a few built-in non date formats
builtins = new short[] { 0x01, 0x02, 0x17, 0x1f, 0x30 };
- for(int i=0; i<builtins.length; i++) {
- String formatStr = HSSFDataFormat.getBuiltinFormat(builtins[i]);
- assertFalse( HSSFDateUtil.isInternalDateFormat(builtins[i]) );
- assertFalse( HSSFDateUtil.isADateFormat(builtins[i],formatStr) );
+ for (short builtin : builtins) {
+ String formatStr = HSSFDataFormat.getBuiltinFormat(builtin);
+ assertFalse( HSSFDateUtil.isInternalDateFormat(builtin) );
+ assertFalse( HSSFDateUtil.isADateFormat(builtin,formatStr) );
}
// Now for some non-internal ones
"[BLACK]dddd/mm/yy",
"[yeLLow]yyyy-mm-dd"
};
- for(int i=0; i<formats.length; i++) {
+ for (String format : formats) {
assertTrue(
- formats[i] + " is a date format",
- HSSFDateUtil.isADateFormat(formatId, formats[i])
+ format + " is a date format",
+ HSSFDateUtil.isADateFormat(formatId, format)
);
}
//support elapsed time [h],[m],[s]
"[hh]", "[mm]", "[ss]", "[SS]", "[red][hh]"
};
- for(int i=0; i<formats.length; i++) {
+ for (String format : formats) {
assertTrue(
- formats[i] + " is a datetime format",
- HSSFDateUtil.isADateFormat(formatId, formats[i])
+ format + " is a datetime format",
+ HSSFDateUtil.isADateFormat(formatId, format)
);
}
"[ms]", "[Mh]",
"", null
};
- for(int i=0; i<formats.length; i++) {
+ for (String format : formats) {
assertFalse(
- formats[i] + " is not a date or datetime format",
- HSSFDateUtil.isADateFormat(formatId, formats[i])
+ format + " is not a date or datetime format",
+ HSSFDateUtil.isADateFormat(formatId, format)
);
}
formats = new String[] {
"yyyy:mm:dd",
};
- for(int i=0; i<formats.length; i++) {
+ for (String format : formats) {
// assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
}
}
assertEquals(refA, arefs[0].formatAsString());
assertEquals(refB, arefs[1].formatAsString());
- for(int i=0; i<arefs.length; i++) {
- AreaReference ar = arefs[i];
+ for (AreaReference ar : arefs) {
confirmResolveCellRef(wb, ar.getFirstCell());
confirmResolveCellRef(wb, ar.getLastCell());
}
public void testEmptyRegistry() {
POIFSReaderRegistry registry = new POIFSReaderRegistry();
- for (int j = 0; j < paths.length; j++)
- {
- for (int k = 0; k < names.length; k++)
- {
+ for (POIFSDocumentPath path : paths) {
+ for (String name : names) {
Iterator<POIFSReaderListener> listeners =
- registry.getListeners(paths[ j ], names[ k ]);
+ registry.getListeners(path, name);
assertTrue(!listeners.hasNext());
}
}
}
}
- for (int j = 0; j < listeners.length; j++)
- {
- registry.registerListener(listeners[ j ]);
+ for (POIFSReaderListener listener : listeners) {
+ registry.registerListener(listener);
}
- for (int k = 0; k < paths.length; k++)
- {
- for (int n = 0; n < names.length; n++)
- {
+ for (POIFSDocumentPath path : paths) {
+ for (String name : names) {
Iterator<POIFSReaderListener> listeners =
- registry.getListeners(paths[ k ], names[ n ]);
+ registry.getListeners(path, name);
Set<POIFSReaderListener> registeredListeners =
new HashSet<POIFSReaderListener>();
}
assertEquals(this.listeners.length,
registeredListeners.size());
- for (int j = 0; j < this.listeners.length; j++)
- {
+ for (POIFSReaderListener listener : this.listeners) {
assertTrue(registeredListeners
- .contains(this.listeners[ j ]));
+ .contains(listener));
}
}
}
"ShortLastBlock.qwp", "ShortLastBlock.wps"
};
- for(int i=0; i<files.length; i++) {
+ for (String file : files) {
// Open the file up
OPOIFSFileSystem fs = new OPOIFSFileSystem(
- _samples.openResourceAsStream(files[i])
+ _samples.openResourceAsStream(file)
);
// Write it into a temp output array
public static byte[] decode(String[] hexDataLines) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(hexDataLines.length * 32 + 32);
- for (int i = 0; i < hexDataLines.length; i++) {
- byte[] lineData = HexRead.readFromString(hexDataLines[i]);
+ for (String hexDataLine : hexDataLines) {
+ byte[] lineData = HexRead.readFromString(hexDataLine);
baos.write(lineData, 0, lineData.length);
}
return baos.toByteArray();
public static void confirmEqual(byte[] expected, String[] hexDataLines) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(hexDataLines.length * 32 + 32);
- for (int i = 0; i < hexDataLines.length; i++) {
- byte[] lineData = HexRead.readFromString(hexDataLines[i]);
+ for (String hexDataLine : hexDataLines) {
+ byte[] lineData = HexRead.readFromString(hexDataLine);
baos.write(lineData, 0, lineData.length);
}
if (!Arrays.equals(expected, baos.toByteArray())) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(512
* blocks.length);
- for (int j = 0; j < blocks.length; j++)
- {
- blocks[ j ].writeBlocks(stream);
+ for (BATBlock block : blocks) {
+ block.writeBlocks(stream);
}
byte[] actual = stream.toByteArray();
ByteArrayOutputStream stream = new ByteArrayOutputStream(512
* blocks.length);
- for (int j = 0; j < blocks.length; j++)
- {
- blocks[ j ].writeBlocks(stream);
+ for (BATBlock block : blocks) {
+ block.writeBlocks(stream);
}
byte[] actual = stream.toByteArray();
};
int expectedIndex = 0;
- for (int j = 0; j < blockSizes.length; j++)
- {
- assertEquals(expectedIndex, table.allocateSpace(blockSizes[ j ]));
- expectedIndex += blockSizes[ j ];
+ for (int blockSize : blockSizes) {
+ assertEquals(expectedIndex, table.allocateSpace(blockSize));
+ expectedIndex += blockSize;
}
}
(_testdata_size + 63) / 64, results.length);
ByteArrayOutputStream output = new ByteArrayOutputStream();
- for (int j = 0; j < results.length; j++)
- {
- results[ j ].writeBlocks(output);
+ for (SmallDocumentBlock result : results) {
+ result.writeBlocks(output);
}
byte[] output_array = output.toByteArray();
assertEquals(5, blocks.length);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
- for (int k = 0; k < blocks.length; k++)
- {
- blocks[ k ].writeBlocks(stream);
+ for (SmallDocumentBlock block : blocks) {
+ block.writeBlocks(stream);
}
stream.close();
byte[] output = stream.toByteArray();
}
private static void debugPrint(PrintStream ps, String[] log) {
- for (int i = 0; i < log.length; i++) {
- ps.println('"' + log[i] + "\",");
+ for (String element : log) {
+ ps.println('"' + element + "\",");
}
}
Arrays.sort(keys);
_ps.println("# " + headingText);
- for (int i = 0; i < keys.length; i++) {
- FunctionData fd = _allFunctionsByIndex.get(keys[i]);
+ for (Integer key : keys) {
+ FunctionData fd = _allFunctionsByIndex.get(key);
_ps.println(fd.formatAsDataLine());
}
}
"See the License for the specific language governing permissions and",
"limitations under the License.",
};
- for (int i = 0; i < lines.length; i++) {
+ for (String line : lines) {
ps.print("# ");
- ps.println(lines[i]);
+ ps.println(line);
}
ps.println();
}
int letUsShiftColumn1By1Column=1;
HSSFWorkbook wb = null;
Ptg[] ptgs = HSSFFormulaParser.parse(formula, wb);
- for(int i=0; i<ptgs.length; i++)
- {
- Ptg ptg = ptgs[i];
+ for (Ptg ptg : ptgs) {
if (ptg instanceof AreaPtg )
{
AreaPtg aptg = (AreaPtg)ptg;
HSSFWorkbook wb = new HSSFWorkbook();
SheetWriter sw = new SheetWriter(wb);
ComparisonExample[] ces = NumberComparisonExamples.getComparisonExamples();
- for (int i = 0; i < ces.length; i++) {
- ComparisonExample ce = ces[i];
+ for (ComparisonExample ce : ces) {
sw.addTestRow(ce.getA(), ce.getB(), ce.getExpectedResult());
}
SheetWriter sw = new SheetWriter(wb);
ExampleConversion[] exampleValues = NumberToTextConversionExamples.getExampleConversions();
- for (int i = 0; i < exampleValues.length; i++) {
- ExampleConversion example = exampleValues[i];
+ for (ExampleConversion example : exampleValues) {
sw.addTestRow(example.getRawDoubleBits(), example.getExcelRendering());
}
public static void writeJavaDoc() {
ExampleConversion[] exampleConversions = NumberToTextConversionExamples.getExampleConversions();
- for (int i = 0; i < exampleConversions.length; i++) {
- ExampleConversion ec = exampleConversions[i];
+ for (ExampleConversion ec : exampleConversions) {
String line = " * <tr><td>"
+ formatLongAsHex(ec.getRawDoubleBits())
+ "</td><td>" + Double.toString(ec.getDoubleValue())