public final class CHPBinTable
{
/** List of character properties.*/
- protected ArrayList _textRuns = new ArrayList();
+ protected ArrayList<CHPX> _textRuns = new ArrayList<CHPX>();
/** So we can know if things are unicode or not */
private TextPieceTable tpt;
int endMark = offset + length;
int endIndex = listIndex;
- CHPX chpx = (CHPX)_textRuns.get(endIndex);
+ CHPX chpx = _textRuns.get(endIndex);
while (chpx.getEnd() < endMark)
{
- chpx = (CHPX)_textRuns.get(++endIndex);
+ chpx = _textRuns.get(++endIndex);
}
if (listIndex == endIndex)
{
- chpx = (CHPX)_textRuns.get(endIndex);
+ chpx = _textRuns.get(endIndex);
chpx.setEnd((chpx.getEnd() - endMark) + offset);
}
else
{
- chpx = (CHPX)_textRuns.get(listIndex);
+ chpx = _textRuns.get(listIndex);
chpx.setEnd(offset);
for (int x = listIndex + 1; x < endIndex; x++)
{
- chpx = (CHPX)_textRuns.get(x);
+ chpx = _textRuns.get(x);
chpx.setStart(offset);
chpx.setEnd(offset);
}
- chpx = (CHPX)_textRuns.get(endIndex);
+ chpx = _textRuns.get(endIndex);
chpx.setEnd((chpx.getEnd() - endMark) + offset);
}
for (int x = endIndex + 1; x < size; x++)
{
- chpx = (CHPX)_textRuns.get(x);
+ chpx = _textRuns.get(x);
chpx.setStart(chpx.getStart() - length);
chpx.setEnd(chpx.getEnd() - length);
}
}
else
{
- CHPX chpx = (CHPX)_textRuns.get(listIndex);
+ CHPX chpx = _textRuns.get(listIndex);
if (chpx.getStart() < cpStart)
{
// Copy the properties of the one before to afterwards
public void adjustForInsert(int listIndex, int length)
{
int size = _textRuns.size();
- CHPX chpx = (CHPX)_textRuns.get(listIndex);
+ CHPX chpx = _textRuns.get(listIndex);
chpx.setEnd(chpx.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
- chpx = (CHPX)_textRuns.get(x);
+ chpx = _textRuns.get(x);
chpx.setStart(chpx.getStart() + length);
chpx.setEnd(chpx.getEnd() + length);
}
}
- public List getTextRuns()
+ public List<CHPX> getTextRuns()
{
return _textRuns;
}
endingFc += fcMin;
- ArrayList overflow = _textRuns;
+ ArrayList<CHPX> overflow = _textRuns;
do
{
PropertyNode startingProp = (PropertyNode)overflow.get(0);
while (overflow != null);
tableStream.write(binTable.toByteArray());
}
-
-
-
-
-
}
{
private static final int FC_SIZE = 4;
- private ArrayList _chpxList = new ArrayList();
- private ArrayList _overFlow;
+ private ArrayList<CHPX> _chpxList = new ArrayList<CHPX>();
+ private ArrayList<CHPX> _overFlow;
public CHPFormattedDiskPage()
public CHPX getCHPX(int index)
{
- return (CHPX)_chpxList.get(index);
+ return _chpxList.get(index);
}
- public void fill(List filler)
+ public void fill(List<CHPX> filler)
{
_chpxList.addAll(filler);
}
- public ArrayList getOverflow()
+ public ArrayList<CHPX> getOverflow()
{
return _overFlow;
}
int index = 0;
for (; index < size; index++)
{
- int grpprlLength = ((CHPX)_chpxList.get(index)).getGrpprl().length;
+ int grpprlLength = (_chpxList.get(index)).getGrpprl().length;
// check to see if we have enough room for an FC, the grpprl offset,
// the grpprl size byte and the grpprl.
// see if we couldn't fit some
if (index != size)
{
- _overFlow = new ArrayList();
+ _overFlow = new ArrayList<CHPX>();
_overFlow.addAll(_chpxList.subList(index, size));
}
package org.apache.poi.hwpf.model;
-import org.apache.poi.hwpf.model.io.HWPFOutputStream;
-import org.apache.poi.poifs.common.POIFSConstants;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
+import org.apache.poi.hwpf.model.io.HWPFOutputStream;
+import org.apache.poi.poifs.common.POIFSConstants;
+
/**
* The piece table for matching up character positions to bits of text. This
* mostly works in bytes, but the TextPieces themselves work in characters. This
* @author Ryan Ackley
*/
public final class TextPieceTable implements CharIndexTranslator {
- protected ArrayList _textPieces = new ArrayList();
+ protected ArrayList<TextPiece> _textPieces = new ArrayList<TextPiece>();
// int _multiple;
int _cpMin;
// In the interest of our sanity, now sort the text pieces
// into order, if they're not already
- TextPiece[] tp = (TextPiece[]) _textPieces.toArray(new TextPiece[_textPieces.size()]);
+ TextPiece[] tp = _textPieces.toArray(new TextPiece[_textPieces.size()]);
Arrays.sort(tp);
for (int i = 0; i < tp.length; i++) {
_textPieces.set(i, tp[i]);
return _cpMin;
}
- public List getTextPieces() {
+ public List<TextPiece> getTextPieces() {
return _textPieces;
}
public boolean isUnicodeAtCharOffset(int cp) {
boolean lastWas = false;
- Iterator it = _textPieces.iterator();
- while (it.hasNext()) {
- TextPiece tp = (TextPiece) it.next();
+ for(TextPiece tp : _textPieces) {
// If the text piece covers the character, all good
if (tp.getStart() <= cp && tp.getEnd() >= cp) {
return tp.isUnicode();
public boolean isUnicodeAtByteOffset(int bytePos) {
boolean lastWas = false;
- Iterator it = _textPieces.iterator();
- while (it.hasNext()) {
- TextPiece tp = (TextPiece) it.next();
+ for(TextPiece tp : _textPieces) {
int curByte = tp.getPieceDescriptor().getFilePosition();
int pieceEnd = curByte + tp.bytesLength();
int size = _textPieces.size();
for (int x = 0; x < size; x++) {
- TextPiece next = (TextPiece) _textPieces.get(x);
+ TextPiece next = _textPieces.get(x);
PieceDescriptor pd = next.getPieceDescriptor();
int offset = docStream.getOffset();
public int adjustForInsert(int listIndex, int length) {
int size = _textPieces.size();
- TextPiece tp = (TextPiece) _textPieces.get(listIndex);
+ TextPiece tp = _textPieces.get(listIndex);
// Update with the new end
tp.setEnd(tp.getEnd() + length);
public int getCharIndex(int bytePos) {
int charCount = 0;
- Iterator it = _textPieces.iterator();
- while (it.hasNext()) {
- TextPiece tp = (TextPiece) it.next();
+ for(TextPiece tp : _textPieces) {
int pieceStart = tp.getPieceDescriptor().getFilePosition();
if (pieceStart >= bytePos) {
break;