Remove iterating over the number of runs for certain XSSFRichTextString operations. If I didn't overlook something, they can directly access the array element anyway. Seems this was some leftover copy/paste stuff.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
76b750b420
commit
f622530806
@ -279,13 +279,12 @@ public class XSSFRichTextString implements RichTextString {
|
||||
* @return the number of characters this format run covers
|
||||
*/
|
||||
public int getLengthOfFormattingRun(int index) {
|
||||
if(st.sizeOfRArray() == 0) return length();
|
||||
|
||||
for(int i = 0; i < st.sizeOfRArray(); i++){
|
||||
CTRElt r = st.getRArray(i);
|
||||
if(i == index) return r.getT().length();
|
||||
if(st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) {
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
|
||||
CTRElt r = st.getRArray(index);
|
||||
return r.getT().length();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,16 +341,17 @@ public class XSSFRichTextString implements RichTextString {
|
||||
* @return A copy of the font used or null if no formatting is applied to the specified text run.
|
||||
*/
|
||||
public XSSFFont getFontOfFormattingRun(int index) {
|
||||
if(st.sizeOfRArray() == 0) return null;
|
||||
|
||||
for(int i = 0; i < st.sizeOfRArray(); i++){
|
||||
CTRElt r = st.getRArray(i);
|
||||
if(i == index && r.getRPr() != null) {
|
||||
XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr()));
|
||||
fnt.setThemesTable(getThemesTable());
|
||||
return fnt;
|
||||
}
|
||||
if(st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CTRElt r = st.getRArray(index);
|
||||
if(r.getRPr() != null) {
|
||||
XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr()));
|
||||
fnt.setThemesTable(getThemesTable());
|
||||
return fnt;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -400,18 +400,35 @@ public final class TestXSSFRichTextString extends TestCase {
|
||||
Row row = sheet.getRow(0);
|
||||
|
||||
// verify the values to ensure future changes keep the returned information equal
|
||||
assertEquals(0, row.getCell(0).getRichStringCellValue().numFormattingRuns());
|
||||
assertEquals(0, row.getCell(1).getRichStringCellValue().numFormattingRuns());
|
||||
XSSFRichTextString rt = (XSSFRichTextString) row.getCell(0).getRichStringCellValue();
|
||||
assertEquals(0, rt.numFormattingRuns());
|
||||
assertNull(rt.getFontOfFormattingRun(0));
|
||||
assertEquals(-1, rt.getLengthOfFormattingRun(0));
|
||||
|
||||
XSSFRichTextString rt = (XSSFRichTextString) row.getCell(2).getRichStringCellValue();
|
||||
rt = (XSSFRichTextString) row.getCell(1).getRichStringCellValue();
|
||||
assertEquals(0, row.getCell(1).getRichStringCellValue().numFormattingRuns());
|
||||
assertNull(rt.getFontOfFormattingRun(1));
|
||||
assertEquals(-1, rt.getLengthOfFormattingRun(1));
|
||||
|
||||
rt = (XSSFRichTextString) row.getCell(2).getRichStringCellValue();
|
||||
assertEquals(2, rt.numFormattingRuns());
|
||||
assertNotNull(rt.getFontOfFormattingRun(0));
|
||||
assertEquals(4, rt.getLengthOfFormattingRun(0));
|
||||
|
||||
assertNotNull(rt.getFontOfFormattingRun(1));
|
||||
assertEquals(9, rt.getLengthOfFormattingRun(1));
|
||||
|
||||
assertNull(rt.getFontOfFormattingRun(2));
|
||||
|
||||
rt = (XSSFRichTextString) row.getCell(3).getRichStringCellValue();
|
||||
assertEquals(3, rt.numFormattingRuns());
|
||||
assertNull(rt.getFontOfFormattingRun(0));
|
||||
assertEquals(1, rt.getLengthOfFormattingRun(0));
|
||||
|
||||
assertNotNull(rt.getFontOfFormattingRun(1));
|
||||
assertEquals(3, rt.getLengthOfFormattingRun(1));
|
||||
|
||||
assertNotNull(rt.getFontOfFormattingRun(2));
|
||||
assertEquals(9, rt.getLengthOfFormattingRun(2));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user