import org.apache.poi.hdf.model.util.BTreeSet;
import org.apache.poi.hdf.model.util.NumberFormatter;
import org.apache.poi.hdf.model.hdftypes.*;
-
import org.apache.poi.util.LittleEndian;
import java.util.ArrayList;
+import java.util.List;
@Deprecated
public final class EventBridge implements HDFLowLevelParsingListener
BTreeSet _hdrCharacterRuns = new BTreeSet();
int _sectionCounter = 1;
- ArrayList _hdrs = new ArrayList();
+ List<HeaderFooter[]> _hdrs = new ArrayList<HeaderFooter[]>();
private boolean _holdParagraph = false;
private int _endHoldIndex = -1;
- private ArrayList _onHold;
+ private List<PropertyNode> _onHold;
public EventBridge(HDFParsingListener listener)
{
{
for (int x = 1; x < _sectionCounter; x++)
{
- HeaderFooter[] hdrArray = (HeaderFooter[])_hdrs.get(x-1);
+ HeaderFooter[] hdrArray = _hdrs.get(x-1);
HeaderFooter hf = null;
if (!hdrArray[HeaderFooter.HEADER_EVEN - 1].isEmpty())
_holdParagraph = false;
_endHoldIndex = -1;
flushHeldParagraph();
- _onHold = new ArrayList();
+ _onHold = new ArrayList<PropertyNode>();
}
}
CharacterProperties chp = (CharacterProperties)StyleSheet.uncompressProperty(byteChpx, _currentStd.getCHP(), _stsh);
- ArrayList textList = BTreeSet.findProperties(start, end, _text.root);
+ List<PropertyNode> textList = BTreeSet.findProperties(start, end, _text.root);
String text = getTextFromNodes(textList, start, end);
_listener.characterRun(chp, text, start - _fcMin, end - _fcMin);
}
private void flushHeaderProps(int start, int end)
{
- ArrayList list = BTreeSet.findProperties(start, end, _hdrSections.root);
+ List<PropertyNode> list = BTreeSet.findProperties(start, end, _hdrSections.root);
int size = list.size();
for (int x = 0; x < size; x++)
//SepxNode node = new SepxNode(-1, secStart, secEnd, oldNode.getSepx());
//bodySection(node);
- ArrayList parList = BTreeSet.findProperties(secStart, secEnd, _hdrParagraphs.root);
+ List<PropertyNode> parList = BTreeSet.findProperties(secStart, secEnd, _hdrParagraphs.root);
int parSize = parList.size();
for (int y = 0; y < parSize; y++)
PapxNode parNode = new PapxNode(parStart, parEnd, oldParNode.getPapx());
paragraph(parNode);
- ArrayList charList = BTreeSet.findProperties(parStart, parEnd, _hdrCharacterRuns.root);
+ List<PropertyNode> charList = BTreeSet.findProperties(parStart, parEnd, _hdrCharacterRuns.root);
int charSize = charList.size();
for (int z = 0; z < charSize; z++)
}
}
- private String getTextFromNodes(ArrayList list, int start, int end)
+ private String getTextFromNodes(List<PropertyNode> list, int start, int end)
{
int size = list.size();
*
*/
@Deprecated
-public final class BTreeSet extends AbstractSet
+public final class BTreeSet extends AbstractSet<PropertyNode>
{
/*
* Instance Variables
*/
public BTreeNode root;
- private Comparator comparator = null;
+ private Comparator<PropertyNode> comparator = null;
private int order;
int size = 0;
this(6); // Default order for a BTreeSet is 32
}
- public BTreeSet(Collection c)
+ public BTreeSet(Collection<PropertyNode> c)
{
this(6); // Default order for a BTreeSet is 32
addAll(c);
this(order, null);
}
- public BTreeSet(int order, Comparator comparator)
+ public BTreeSet(int order, Comparator<PropertyNode> comparator)
{
this.order = order;
this.comparator = comparator;
/*
* Public Methods
*/
- public boolean add(Object x) throws IllegalArgumentException
+ public boolean add(PropertyNode x) throws IllegalArgumentException
{
if (x == null) throw new IllegalArgumentException();
return root.insert(x, -1);
}
- public boolean contains(Object x)
+ public boolean contains(PropertyNode x)
{
return root.includes(x);
}
- public boolean remove(Object x)
+ public boolean remove(PropertyNode x)
{
if (x == null) return false;
return root.delete(x, -1);
size = 0;
}
- public java.util.Iterator iterator()
+ public java.util.Iterator<PropertyNode> iterator()
{
return new Iterator();
}
- public static ArrayList findProperties(int start, int end, BTreeSet.BTreeNode root)
+ public static List<PropertyNode> findProperties(int start, int end, BTreeSet.BTreeNode root)
{
- ArrayList results = new ArrayList();
+ List<PropertyNode> results = new ArrayList<PropertyNode>();
BTreeSet.Entry[] entries = root.entries;
for(int x = 0; x < entries.length; x++)
if(entries[x] != null)
{
BTreeSet.BTreeNode child = entries[x].child;
- PropertyNode xNode = (PropertyNode)entries[x].element;
+ PropertyNode xNode = entries[x].element;
if(xNode != null)
{
int xStart = xNode.getStart();
{
if(child != null)
{
- ArrayList beforeItems = findProperties(start, end, child);
+ List<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(xNode);
{
if(child != null)
{
- ArrayList beforeItems = findProperties(start, end, child);
+ List<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
break;
}
else if(child != null)
{
- ArrayList afterItems = findProperties(start, end, child);
+ List<PropertyNode> afterItems = findProperties(start, end, child);
results.addAll(afterItems);
}
}
/*
* Private methods
*/
- int compare(Object x, Object y)
+ int compare(PropertyNode x, PropertyNode y)
{
- return (comparator == null ? ((Comparable)x).compareTo(y) : comparator.compare(x, y));
+ return (comparator == null ? x.compareTo(y) : comparator.compare(x, y));
}
* chance of receiving a NullPointerException. The Iterator.delete method is supported.
*/
- private class Iterator implements java.util.Iterator
+ private class Iterator implements java.util.Iterator<PropertyNode>
{
private int index = 0;
- private Stack parentIndex = new Stack(); // Contains all parentIndicies for currentNode
- private Object lastReturned = null;
- private Object next;
+ private Stack<Integer> parentIndex = new Stack<Integer>(); // Contains all parentIndicies for currentNode
+ private PropertyNode lastReturned = null;
+ private PropertyNode next;
private BTreeNode currentNode;
Iterator()
return next != null;
}
- public Object next()
+ public PropertyNode next()
{
if (next == null) throw new NoSuchElementException();
return temp;
}
- private Object nextElement()
+ private PropertyNode nextElement()
{
if (currentNode.isLeaf())
{
else if (!parentIndex.empty())
{ //All elements have been returned, return successor of lastReturned if it exists
currentNode = currentNode.parent;
- index = ((Integer)parentIndex.pop()).intValue();
+ index = parentIndex.pop().intValue();
while (index == currentNode.nrElements)
{
if (parentIndex.empty()) break;
currentNode = currentNode.parent;
- index = ((Integer)parentIndex.pop()).intValue();
+ index = parentIndex.pop().intValue();
}
if (index == currentNode.nrElements) return null; //Reached root and he has no more children
public static class Entry
{
- public Object element;
+ public PropertyNode element;
public BTreeNode child;
}
entries[0] = new Entry();
}
- boolean insert(Object x, int parentIndex)
+ boolean insert(PropertyNode x, int parentIndex)
{
if (isFull())
{ // If full, you must split and promote splitNode before inserting
- Object splitNode = entries[nrElements / 2].element;
+ PropertyNode splitNode = entries[nrElements / 2].element;
BTreeNode rightSibling = split();
if (isRoot())
return false;
}
- boolean includes(Object x)
+ boolean includes(PropertyNode x)
{
int index = childToInsertAt(x, true);
if (index == -1) return true;
return entries[index].child.includes(x);
}
- boolean delete(Object x, int parentIndex)
+ boolean delete(PropertyNode x, int parentIndex)
{
int i = childToInsertAt(x, true);
int priorParentIndex = parentIndex;
* Creates a new BTreeSet.root which contains only the splitNode and pointers
* to it's left and right child.
*/
- private void splitRoot(Object splitNode, BTreeNode left, BTreeNode right)
+ private void splitRoot(PropertyNode splitNode, BTreeNode left, BTreeNode right)
{
BTreeNode newRoot = new BTreeNode(null);
newRoot.entries[0].element = splitNode;
BTreeSet.this.root = newRoot;
}
- private void insertSplitNode(Object splitNode, BTreeNode left, BTreeNode right, int insertAt)
+ private void insertSplitNode(PropertyNode splitNode, BTreeNode left, BTreeNode right, int insertAt)
{
for (int i = nrElements; i >= insertAt; i--) entries[i + 1] = entries[i];
nrElements++;
}
- private void insertNewElement(Object x, int insertAt)
+ private void insertNewElement(PropertyNode x, int insertAt)
{
for (int i = nrElements; i > insertAt; i--) entries[i] = entries[i - 1];
* element is contained in the calling BTreeNode than the position of the element
* in entries[] is returned.
*/
- private int childToInsertAt(Object x, boolean position)
+ private int childToInsertAt(PropertyNode x, boolean position)
{
int index = nrElements / 2;
}
- private void deleteElement(Object x)
+ private void deleteElement(PropertyNode x)
{
int index = childToInsertAt(x, false);
for (; index < (nrElements - 1); index++) entries[index] = entries[index + 1];
}
}
- private void switchWithSuccessor(Object x)
+ private void switchWithSuccessor(PropertyNode x)
{
int index = childToInsertAt(x, false);
BTreeNode temp = entries[index + 1].child;
while (temp.entries[0] != null && temp.entries[0].child != null) temp = temp.entries[0].child;
- Object successor = temp.entries[0].element;
+ PropertyNode successor = temp.entries[0].element;
temp.entries[0].element = entries[index].element;
entries[index].element = successor;
}