Eclipse automated refactor/cleanup: convert for loops to for-each loops

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765736 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-10-20 01:54:56 +00:00
parent ecef10cb7b
commit f14210b101
27 changed files with 178 additions and 190 deletions

View File

@ -577,7 +577,7 @@ public class StringUtil {
// Could be replaced with org.apache.commons.lang3.StringUtils#join
@Internal
public static String join(Object[] array, String separator) {
if (array.length == 0) return "";
if (array == null || array.length == 0) return "";
StringBuilder sb = new StringBuilder();
sb.append(array[0]);
for (int i=1; i<array.length; i++) {
@ -586,6 +586,16 @@ public class StringUtil {
return sb.toString();
}
@Internal
public static String join(Object[] array) {
if (array == null) return "";
StringBuilder sb = new StringBuilder();
for (Object o : array) {
sb.append(o);
}
return sb.toString();
}
@Internal
public static String join(String separator, Object... array) {
return join(array, separator);

View File

@ -66,24 +66,24 @@ public final class TestReWriteSanity extends TestCase {
int pos = 0;
int lastUEPos = -1;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof PersistPtrHolder) {
pp.put(Integer.valueOf(pos), r[i]);
for (final Record rec : r) {
if(rec instanceof PersistPtrHolder) {
pp.put(Integer.valueOf(pos), rec);
}
if(r[i] instanceof UserEditAtom) {
ue.put(Integer.valueOf(pos), r[i]);
if(rec instanceof UserEditAtom) {
ue.put(Integer.valueOf(pos), rec);
lastUEPos = pos;
}
ByteArrayOutputStream bc = new ByteArrayOutputStream();
r[i].writeOut(bc);
rec.writeOut(bc);
pos += bc.size();
}
// Check that the UserEditAtom's point to right stuff
for(int i=0; i<r.length; i++) {
if(r[i] instanceof UserEditAtom) {
UserEditAtom uea = (UserEditAtom)r[i];
for (final Record rec : r) {
if(rec instanceof UserEditAtom) {
UserEditAtom uea = (UserEditAtom)rec;
int luPos = uea.getLastUserEditAtomOffset();
int ppPos = uea.getPersistPointersOffset();

View File

@ -44,8 +44,8 @@ public final class TestRecordCounts extends TestCase {
Record[] r = ss.getRecords();
int count = 0;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof Slide) {
for (final Record rec : r) {
if(rec instanceof Slide) {
count++;
}
}
@ -58,9 +58,8 @@ public final class TestRecordCounts extends TestCase {
Record[] r = ss.getRecords();
int count = 0;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof Notes &&
r[i].getRecordType() == 1008l) {
for (final Record rec : r) {
if (rec instanceof Notes && rec.getRecordType() == 1008l) {
count++;
}
}
@ -74,9 +73,8 @@ public final class TestRecordCounts extends TestCase {
Record[] r = rt[0].getChildRecords();
int count = 0;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof SlideListWithText &&
r[i].getRecordType() == 4080l) {
for (final Record rec : r) {
if (rec instanceof SlideListWithText && rec.getRecordType() == 4080l) {
count++;
}
}

View File

@ -23,6 +23,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.StringUtil;
/**
* Tests that the QuickButCruddyTextExtractor works correctly
@ -80,12 +81,7 @@ public final class TestCruddyExtractor extends TestCase {
String foundText = te.getTextAsString();
// Turn the string array into a single string
StringBuffer expectTextSB = new StringBuffer();
for(int i=0; i<allTheText.length; i++) {
expectTextSB.append(allTheText[i]);
expectTextSB.append('\n');
}
String expectText = expectTextSB.toString();
String expectText = StringUtil.join(allTheText, "\n") + "\n";
// Ensure they match
assertEquals(expectText,foundText);

View File

@ -106,9 +106,9 @@ public final class TestExHyperlink extends TestCase {
Document doc = ss.getDocumentRecord();
// Get the ExObjList
ExObjList exObjList = null;
for(int i=0; i<doc._children.length; i++) {
if(doc._children[i] instanceof ExObjList) {
exObjList = (ExObjList)doc._children[i];
for (final Record rec : doc._children) {
if(rec instanceof ExObjList) {
exObjList = (ExObjList)rec;
}
}
if (exObjList == null) {

View File

@ -153,9 +153,9 @@ public final class TestRecordContainer extends TestCase {
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
Record[] r = hss.getRecords();
for(int i=0; i<r.length; i++) {
if(r[i] instanceof RecordContainer) {
recordContainer = (RecordContainer)r[i];
for (Record rec : r) {
if(rec instanceof RecordContainer) {
recordContainer = (RecordContainer)rec;
return;
}
}

View File

@ -40,9 +40,9 @@ public final class TestSound extends TestCase {
Document doc = ppt.getDocumentRecord();
SoundCollection soundCollection = null;
Record[] doc_ch = doc.getChildRecords();
for (int i = 0; i < doc_ch.length; i++) {
if (doc_ch[i] instanceof SoundCollection) {
soundCollection = (SoundCollection) doc_ch[i];
for (Record rec : doc_ch) {
if (rec instanceof SoundCollection) {
soundCollection = (SoundCollection) rec;
break;
}
}
@ -53,9 +53,9 @@ public final class TestSound extends TestCase {
Sound sound = null;
Record[] sound_ch = soundCollection.getChildRecords();
int k = 0;
for (int i = 0; i < sound_ch.length; i++) {
if (sound_ch[i] instanceof Sound) {
sound = (Sound) sound_ch[i];
for (Record rec : sound_ch) {
if (rec instanceof Sound) {
sound = (Sound) rec;
k++;
}
}

View File

@ -45,20 +45,20 @@ public final class TestTxMasterStyleAtom extends TestCase {
public void testDefaultStyles() {
TxMasterStyleAtom[] txmaster = getMasterStyles();
for (int i = 0; i < txmaster.length; i++) {
int txtype = txmaster[i].getTextType();
for (final TxMasterStyleAtom atom : txmaster) {
final int txtype = atom.getTextType();
switch (txtype){
case TextHeaderAtom.TITLE_TYPE:
checkTitleType(txmaster[i]);
checkTitleType(atom);
break;
case TextHeaderAtom.BODY_TYPE:
checkBodyType(txmaster[i]);
checkBodyType(atom);
break;
case TextHeaderAtom.NOTES_TYPE:
checkNotesType(txmaster[i]);
checkNotesType(atom);
break;
case TextHeaderAtom.OTHER_TYPE:
checkOtherType(txmaster[i]);
checkOtherType(atom);
break;
case TextHeaderAtom.CENTRE_BODY_TYPE:
break;
@ -204,13 +204,11 @@ public final class TestTxMasterStyleAtom extends TestCase {
List<TxMasterStyleAtom> lst = new ArrayList<TxMasterStyleAtom>();
Record[] coreRecs = _ppt.getMostRecentCoreRecords();
for (int i = 0; i < coreRecs.length; i++) {
Record coreRec = coreRecs[i];
for (final Record coreRec : coreRecs) {
if(coreRec.getRecordType() == RecordTypes.MainMaster.typeID){
Record[] recs = coreRec.getChildRecords();
int cnt = 0;
for (int j = 0; j < recs.length; j++) {
Record rec = recs[j];
for (final Record rec : recs) {
if (rec instanceof TxMasterStyleAtom) {
lst.add((TxMasterStyleAtom) rec);
cnt++;
@ -221,10 +219,10 @@ public final class TestTxMasterStyleAtom extends TestCase {
TxMasterStyleAtom txstyle = null;
Document doc = (Document)coreRec;
Record[] rec = doc.getEnvironment().getChildRecords();
for (int j = 0; j < rec.length; j++) {
if (rec[j] instanceof TxMasterStyleAtom) {
for (final Record atom : rec) {
if (atom instanceof TxMasterStyleAtom) {
if (txstyle != null) fail("Document.Environment must contain 1 TxMasterStyleAtom");
txstyle = (TxMasterStyleAtom)rec[j];
txstyle = (TxMasterStyleAtom)atom;
}
}
if (txstyle == null) {

View File

@ -59,8 +59,8 @@ public final class TestRecordSetup {
if(r instanceof RecordContainer) {
RecordContainer rc = (RecordContainer)r;
Record[] children = rc.getChildRecords();
for(int i=0; i<children.length; i++) {
ensureParentAware(children[i], rc);
for (Record rec : children) {
ensureParentAware(rec, rc);
}
}
}

View File

@ -17,20 +17,28 @@
package org.apache.poi.hwpf.extractor;
import junit.framework.TestCase;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.util.StringUtil;
import org.junit.After;
import org.junit.Before;
/**
* Test the different routes to extracting text
*
* @author Nick Burch (nick at torchbox dot com)
*/
public final class TestDifferentRoutes extends TestCase {
private String[] p_text = new String[] {
public final class TestDifferentRoutes {
private static final String[] p_text = new String[] {
"This is a simple word document\r",
"\r",
"It has a number of paragraphs in it\r",
@ -49,14 +57,20 @@ public final class TestDifferentRoutes extends TestCase {
private HWPFDocument doc;
@Override
protected void setUp() {
@Before
public void setUp() {
doc = HWPFTestDataSamples.openSampleFile("test2.doc");
}
@After
public void tearDown() throws IOException {
doc.close();
}
/**
* Test model based extraction
*/
@Test
public void testExtractFromModel() {
Range r = doc.getRange();
@ -66,20 +80,15 @@ public final class TestDifferentRoutes extends TestCase {
text[i] = p.text();
}
assertEquals(p_text.length, text.length);
for (int i = 0; i < p_text.length; i++) {
assertEquals(p_text[i], text[i]);
}
assertArrayEquals(p_text, text);
}
/**
* Test textPieces based extraction
*/
@Test
public void testExtractFromTextPieces() throws Exception {
StringBuffer exp = new StringBuffer();
for (int i = 0; i < p_text.length; i++) {
exp.append(p_text[i]);
}
assertEquals(exp.toString(), doc.getDocumentText());
String expected = StringUtil.join(p_text, "");
assertEquals(expected, doc.getDocumentText());
}
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hwpf.extractor;
import static org.apache.poi.POITestCase.assertContains;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
@ -28,6 +29,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.StringUtil;
import java.io.IOException;
import java.io.InputStream;
@ -47,8 +49,13 @@ public final class TestWordExtractor extends TestCase {
.replaceAll( "\r", "\n" ).trim();
TestCase.assertEquals( newExpected, newActual );
}
private static void assertExtractedContains(String[] extracted, String needle) {
String endnote = StringUtil.join(extracted, "");
assertContains(endnote, needle);
}
private String[] p_text1 = new String[] {
private final String[] p_text1 = new String[] {
"This is a simple word document\r\n",
"\r\n",
"It has a number of paragraphs in it\r\n",
@ -94,9 +101,13 @@ public final class TestWordExtractor extends TestCase {
extractor2 = new WordExtractor(docTests.openResourceAsStream(filename2));
// Build splat'd out text version
for(int i=0; i<p_text1.length; i++) {
p_text1_block += p_text1[i];
}
p_text1_block = StringUtil.join(p_text1, "");
}
@Override
protected void tearDown() throws Exception {
if (extractor != null) extractor.close();
if (extractor2 != null) extractor2.close();
}
/**
@ -189,18 +200,14 @@ public final class TestWordExtractor extends TestCase {
extractor = new WordExtractor(doc);
assertEquals("First header column!\tMid header Right header!\n", extractor.getHeaderText());
String text = extractor.getText();
assertTrue(text.indexOf("First header column!") > -1);
assertContains(extractor.getText(), "First header column!");
// Unicode
doc = HWPFTestDataSamples.openSampleFile(filename5);
extractor = new WordExtractor(doc);
assertEquals("This is a simple header, with a \u20ac euro symbol in it.\n\n", extractor
.getHeaderText());
text = extractor.getText();
assertTrue(text.indexOf("This is a simple header") > -1);
assertEquals("This is a simple header, with a \u20ac euro symbol in it.\n\n", extractor.getHeaderText());
assertContains(extractor.getText(), "This is a simple header");
}
public void testWithFooter() {
@ -209,31 +216,21 @@ public final class TestWordExtractor extends TestCase {
extractor = new WordExtractor(doc);
assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor.getFooterText());
String text = extractor.getText();
assertTrue(text.indexOf("Footer Left") > -1);
assertContains(extractor.getText(), "Footer Left");
// Unicode
doc = HWPFTestDataSamples.openSampleFile(filename5);
extractor = new WordExtractor(doc);
assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\n", extractor
.getFooterText());
text = extractor.getText();
assertTrue(text.indexOf("The footer, with") > -1);
assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\n", extractor.getFooterText());
assertContains(extractor.getText(), "The footer, with");
}
public void testFootnote() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
extractor = new WordExtractor(doc);
String[] text = extractor.getFootnoteText();
StringBuffer b = new StringBuffer();
for (int i = 0; i < text.length; i++) {
b.append(text[i]);
}
assertTrue(b.toString().contains("TestFootnote"));
assertExtractedContains(extractor.getFootnoteText(), "TestFootnote");
assertEquals(0x00, doc.getRange().getSection(0).getFootnoteNumberingFormat()); // msonfcArabic
assertEquals(0x00, doc.getRange().getSection(0).getFootnoteRestartQualifier()); // rncCont
assertEquals(0, doc.getRange().getSection(0).getFootnoteNumberingOffset());
@ -244,13 +241,7 @@ public final class TestWordExtractor extends TestCase {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
extractor = new WordExtractor(doc);
String[] text = extractor.getEndnoteText();
StringBuffer b = new StringBuffer();
for (int i = 0; i < text.length; i++) {
b.append(text[i]);
}
assertTrue(b.toString().contains("TestEndnote"));
assertExtractedContains(extractor.getEndnoteText(), "TestEndnote");
assertEquals(0x02, doc.getRange().getSection(0).getEndnoteNumberingFormat()); // msonfcLCRoman
assertEquals(0x00, doc.getRange().getSection(0).getEndnoteRestartQualifier()); // rncCont
assertEquals(0, doc.getRange().getSection(0).getEndnoteNumberingOffset());
@ -261,13 +252,7 @@ public final class TestWordExtractor extends TestCase {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
extractor = new WordExtractor(doc);
String[] text = extractor.getCommentsText();
StringBuffer b = new StringBuffer();
for (int i = 0; i < text.length; i++) {
b.append(text[i]);
}
assertTrue(b.toString().contains("TestComment"));
assertExtractedContains(extractor.getCommentsText(), "TestComment");
}
public void testWord95() throws Exception {
@ -330,6 +315,8 @@ public final class TestWordExtractor extends TestCase {
String text = extractor.getText();
assertTrue(text.contains("\u0425\u0425\u0425\u0425\u0425"));
assertTrue(text.contains("\u0423\u0423\u0423\u0423\u0423"));
extractor.close();
}
public void testFirstParagraphFix() throws Exception {
@ -351,7 +338,8 @@ public final class TestWordExtractor extends TestCase {
// Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2];
files[0] = (new POIFSFileSystem(docTests.openResourceAsStream("test2.doc"))).getRoot();
POIFSFileSystem poifs = new POIFSFileSystem(docTests.openResourceAsStream("test2.doc"));
files[0] = poifs.getRoot();
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(docTests.getFile("test2.doc"));
files[1] = npoifsFileSystem.getRoot();
@ -368,6 +356,7 @@ public final class TestWordExtractor extends TestCase {
assertEquals(p_text1_block, extractor.getText());
}
poifs.close();
npoifsFileSystem.close();
}
@ -407,10 +396,10 @@ public final class TestWordExtractor extends TestCase {
try {
// Now overall
String text = ext.getText();
assertTrue(text.indexOf("TEMPLATE = Normal") > -1);
assertTrue(text.indexOf("SUBJECT = sample subject") > -1);
assertTrue(text.indexOf("MANAGER = sample manager") > -1);
assertTrue(text.indexOf("COMPANY = sample company") > -1);
assertContains(text, "TEMPLATE = Normal");
assertContains(text, "SUBJECT = sample subject");
assertContains(text, "MANAGER = sample manager");
assertContains(text, "COMPANY = sample company");
} finally {
ext.close();
}

View File

@ -699,11 +699,11 @@ public class TestWrite
return f.getName().startsWith("Test") && TestReadAllFiles.checkExclude(f);
}
});
for (int i = 0; i < fileList.length; i++) {
for (final File file : fileList) {
try {
testRecreate(fileList[i]);
testRecreate(file);
} catch (Exception e) {
throw new IOException("While handling file " + fileList[i], e);
throw new IOException("While handling file " + file, e);
}
}
}
@ -729,10 +729,9 @@ public class TestWrite
copy.deleteOnExit();
final OutputStream out = new FileOutputStream(copy);
final POIFSFileSystem poiFs = new POIFSFileSystem();
for (int i = 0; i < psf1.length; i++)
{
for (POIFile file : psf1) {
final InputStream in =
new ByteArrayInputStream(psf1[i].getBytes());
new ByteArrayInputStream(file.getBytes());
final PropertySet psIn = PropertySetFactory.create(in);
final MutablePropertySet psOut = new MutablePropertySet(psIn);
final ByteArrayOutputStream psStream =
@ -741,7 +740,7 @@ public class TestWrite
psStream.close();
final byte[] streamData = psStream.toByteArray();
poiFs.createDocument(new ByteArrayInputStream(streamData),
psf1[i].getName());
file.getName());
poiFs.writeFilesystem(out);
}
poiFs.close();

View File

@ -28,7 +28,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@ -252,8 +251,8 @@ final class Util {
{
final Properties p = System.getProperties();
final List<String> names = new LinkedList<String>();
for (Iterator<String> i = p.stringPropertyNames().iterator(); i.hasNext();)
names.add(i.next());
for (String name : p.stringPropertyNames())
names.add(name);
Collections.sort(names);
for (String name : names) {
String value = p.getProperty(name);

View File

@ -211,9 +211,9 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
// Check the numbers of the last seen columns
LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[24];
int lrscount = 0;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof LastCellOfRowDummyRecord) {
lrs[lrscount] = (LastCellOfRowDummyRecord)r[i];
for (final Record rec : r) {
if(rec instanceof LastCellOfRowDummyRecord) {
lrs[lrscount] = (LastCellOfRowDummyRecord)rec;
lrscount++;
}
}
@ -351,9 +351,9 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
readRecords("MRExtraLines.xls");
int rowCount=0;
for(int i=0; i<r.length; i++) {
if(r[i] instanceof LastCellOfRowDummyRecord) {
LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) r[i];
for (Record rec : r) {
if(rec instanceof LastCellOfRowDummyRecord) {
LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) rec;
assertEquals(rowCount, eor.getRow());
rowCount++;
}
@ -416,8 +416,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
Record[] rr = r;
int eorCount=0;
int sfrCount=0;
for (int i = 0; i < rr.length; i++) {
Record record = rr[i];
for (Record record : rr) {
if (record instanceof SharedFormulaRecord) {
sfrCount++;
}

View File

@ -429,8 +429,8 @@ public final class TestHyperlinkRecord {
@Test
public void testClone() {
byte[][] data = {data1, data2, data3, data4};
for (int i = 0; i < data.length; i++) {
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data[i]);
for (final byte[] d : data) {
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, d);
HyperlinkRecord link = new HyperlinkRecord(is);
HyperlinkRecord clone = link.clone();
assertArrayEquals(link.serialize(), clone.serialize());

View File

@ -107,10 +107,10 @@ public final class TestTextObjectRecord extends TestCase {
* Test that TextObjectRecord serializes logs records properly.
*/
public void testLongRecords() {
int[] length = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
for (int i = 0; i < length.length; i++) {
StringBuffer buff = new StringBuffer(length[i]);
for (int j = 0; j < length[i]; j++) {
int[] lengths = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
for (int length : lengths) {
StringBuffer buff = new StringBuffer(length);
for (int j = 0; j < length; j++) {
buff.append("x");
}
HSSFRichTextString str = new HSSFRichTextString(buff.toString());

View File

@ -135,8 +135,8 @@ public final class TestFormulas extends TestCase {
String[] operation = new String[] {
"+", "-", "*", "/", "^", "&"
};
for (int k = 0; k < operation.length; k++) {
operationRefTest(operation[k]);
for (final String op : operation) {
operationRefTest(op);
}
}

View File

@ -65,21 +65,21 @@ public final class TestHSSFClientAnchor extends TestCase {
* (Bug 42999 reported that dx1 and dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.)
*/
public void testConvertAnchor() {
HSSFClientAnchor[] anchor = {
HSSFClientAnchor[] anchors = {
new HSSFClientAnchor( 0 , 0 , 0 , 0 ,(short)0, 1,(short)1,3),
new HSSFClientAnchor( 100 , 0 , 900 , 255 ,(short)0, 1,(short)1,3),
new HSSFClientAnchor( 900 , 0 , 100 , 255 ,(short)0, 1,(short)1,3)
};
for (int i = 0; i < anchor.length; i++) {
EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor[i]);
assertEquals(anchor[i].getDx1(), record.getDx1());
assertEquals(anchor[i].getDx2(), record.getDx2());
assertEquals(anchor[i].getDy1(), record.getDy1());
assertEquals(anchor[i].getDy2(), record.getDy2());
assertEquals(anchor[i].getCol1(), record.getCol1());
assertEquals(anchor[i].getCol2(), record.getCol2());
assertEquals(anchor[i].getRow1(), record.getRow1());
assertEquals(anchor[i].getRow2(), record.getRow2());
for (HSSFClientAnchor anchor : anchors) {
EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor);
assertEquals(anchor.getDx1(), record.getDx1());
assertEquals(anchor.getDx2(), record.getDx2());
assertEquals(anchor.getDy1(), record.getDy1());
assertEquals(anchor.getDy2(), record.getDy2());
assertEquals(anchor.getCol1(), record.getCol1());
assertEquals(anchor.getCol2(), record.getCol2());
assertEquals(anchor.getRow1(), record.getRow1());
assertEquals(anchor.getRow2(), record.getRow2());
}
}

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.usermodel;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;
@ -46,8 +45,7 @@ public final class TestHSSFPictureData extends TestCase{
List<HSSFPictureData> lst = (List<HSSFPictureData>)(List<?>)wb.getAllPictures();
//assertEquals(2, lst.size());
for (Iterator it = lst.iterator(); it.hasNext(); ) {
HSSFPictureData pict = (HSSFPictureData)it.next();
for (final HSSFPictureData pict : lst) {
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
if (ext.equals("jpeg")){

View File

@ -340,10 +340,9 @@ public final class TestDocumentInputStream extends TestCase {
while (stream.available() >= buffer.length)
{
assertEquals(_buffer_size, stream.read(buffer));
for (int j = 0; j < buffer.length; j++)
{
for (byte data : buffer) {
assertEquals("in main loop, byte " + offset,
_workbook_data[ offset ], buffer[ j ]);
_workbook_data[ offset ], data);
offset++;
}
assertEquals("offset " + offset, _workbook_size - offset,

View File

@ -213,10 +213,9 @@ public final class TestSmallDocumentBlock extends TestCase {
assertEquals("testing block at offset " + offset, 64,
out_data.length);
for (int j = 0; j < out_data.length; j++)
{
for (byte b : out_data) {
assertEquals("testing byte at offset " + offset,
data[ offset ], out_data[ j ]);
data[ offset ], b);
offset++;
}
}

View File

@ -87,11 +87,10 @@ public final class TestByteField extends TestCase {
// as expected
}
for (int j = 0; j < _test_array.length; j++)
{
for (byte b : _test_array) {
array = new byte[ 1 ];
new ByteField(0, _test_array[ j ], array);
assertEquals(_test_array[ j ], new ByteField(0, array).get());
new ByteField(0, b, array);
assertEquals(b, new ByteField(0, array).get());
}
}
@ -151,11 +150,10 @@ public final class TestByteField extends TestCase {
ByteField field = new ByteField(0);
byte[] array = new byte[ 1 ];
for (int j = 0; j < _test_array.length; j++)
{
field.set(_test_array[ j ]);
for (byte b : _test_array) {
field.set(b);
field.writeToBytes(array);
assertEquals("testing ", _test_array[ j ], array[ 0 ]);
assertEquals("testing ", b, array[ 0 ]);
}
}
}

View File

@ -47,9 +47,8 @@ public final class TestIntList extends TestCase {
0, 1, 2, 3, 5
};
for (int j = 0; j < testArray.length; j++)
{
list.add(testArray[ j ]);
for (int element : testArray) {
list.add(element);
}
for (int j = 0; j < testArray.length; j++)
{

View File

@ -89,11 +89,10 @@ public final class TestIntegerField extends TestCase {
// as expected
}
for (int j = 0; j < _test_array.length; j++)
{
for (int element : _test_array) {
array = new byte[ 4 ];
new IntegerField(0, _test_array[ j ], array);
assertEquals(_test_array[ j ], new IntegerField(0, array).get());
new IntegerField(0, element, array);
assertEquals(element, new IntegerField(0, array).get());
}
}
@ -172,9 +171,8 @@ public final class TestIntegerField extends TestCase {
IntegerField field = new IntegerField(0);
byte[] array = new byte[ 4 ];
for (int j = 0; j < _test_array.length; j++)
{
field.set(_test_array[ j ]);
for (int b : _test_array) {
field.set(b);
field.writeToBytes(array);
int val = array[ 3 ] << 24;
@ -182,7 +180,7 @@ public final class TestIntegerField extends TestCase {
val += (array[ 2 ] << 16) & 0x00FF0000;
val += (array[ 1 ] << 8) & 0x0000FF00;
val += (array[ 0 ] & 0x000000FF);
assertEquals("testing ", _test_array[ j ], val);
assertEquals("testing ", b, val);
}
}
}

View File

@ -93,11 +93,10 @@ public final class TestLongField extends TestCase {
// as expected
}
for (int j = 0; j < _test_array.length; j++)
{
for (long element : _test_array) {
array = new byte[ 8 ];
new LongField(0, _test_array[ j ], array);
assertEquals(_test_array[ j ], new LongField(0, array).get());
new LongField(0, element, array);
assertEquals(element, new LongField(0, array).get());
}
}
@ -201,9 +200,8 @@ public final class TestLongField extends TestCase {
LongField field = new LongField(0);
byte[] array = new byte[ 8 ];
for (int j = 0; j < _test_array.length; j++)
{
field.set(_test_array[ j ]);
for (long element : _test_array) {
field.set(element);
field.writeToBytes(array);
long val = (( long ) array[ 7 ]) << 56;
@ -215,7 +213,7 @@ public final class TestLongField extends TestCase {
val += ((( long ) array[ 2 ]) << 16) & 0x0000000000FF0000L;
val += ((( long ) array[ 1 ]) << 8) & 0x000000000000FF00L;
val += (array[ 0 ] & 0x00000000000000FFL);
assertEquals("testing ", _test_array[ j ], val);
assertEquals("testing ", element, val);
}
}
}

View File

@ -87,11 +87,10 @@ public final class TestShortField extends TestCase {
// as expected
}
for (int j = 0; j < _test_array.length; j++)
{
for (short element : _test_array) {
array = new byte[ 2 ];
new ShortField(0, _test_array[ j ], array);
assertEquals(_test_array[ j ], new ShortField(0, array).get());
new ShortField(0, element, array);
assertEquals(element, new ShortField(0, array).get());
}
}
@ -160,15 +159,14 @@ public final class TestShortField extends TestCase {
ShortField field = new ShortField(0);
byte[] array = new byte[ 2 ];
for (int j = 0; j < _test_array.length; j++)
{
field.set(_test_array[ j ]);
for (short element : _test_array) {
field.set(element);
field.writeToBytes(array);
short val = ( short ) (array[ 1 ] << 8);
val &= ( short ) 0xFF00;
val += ( short ) (array[ 0 ] & 0x00FF);
assertEquals("testing ", _test_array[ j ], val);
assertEquals("testing ", element, val);
}
}
}

View File

@ -191,6 +191,10 @@ public class TestStringUtil {
assertEquals("abc", StringUtil.join(",", "abc")); // degenerate case: one thing to join, no trailing comma
assertEquals("abc|def|ghi", StringUtil.join("|", "abc", "def", "ghi"));
assertEquals("5|8.5|true|string", StringUtil.join("|", 5, 8.5, true, "string")); //assumes Locale prints number decimal point as a period rather than a comma
String[] arr = new String[] { "Apache", "POI", "project" };
assertEquals("no separator", "ApachePOIproject", StringUtil.join(arr));
assertEquals("separator", "Apache POI project", StringUtil.join(arr, " "));
}
@Test