xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Wolfgang Hoschek <whoschek AT lbl.gov>
- To: Elliotte Harold <elharo AT metalab.unc.edu>
- Cc: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] indexOf O(1) patch?
- Date: Mon, 31 Jan 2005 19:06:54 -0800
And even then, I might push this off into a separate Ant target.
That wouldd be absolutely fine with me :-)
If you'd seriously consider the O(1) patch, here are the remaining puzzle pieces where nodes are removed or inserted, and hence the sibling position needs to be updated as well (internally factoring out the commonality would help). Grep for "// WH".
Element.java:
public Nodes removeChildren() {
int length = this.getChildCount();
Nodes result = new Nodes();
for (int i = 0; i < length; i++) {
Node child = getChild(i);
if (child.isElement()) fillInBaseURI((Element) child);
child.setParent(null);
child.setSiblingPosition(-1); // WH
result.append(child);
}
this.children = null;
return result;
}
Document.java:
public void setDocType(DocType doctype) {
DocType oldDocType = getDocType();
if (doctype == null) {
throw new NullPointerException("Null DocType");
}
else if (doctype == oldDocType) return;
else if (doctype.getParent() != null) {
throw new MultipleParentException("DocType belongs to another document");
}
if (oldDocType == null) insertChild(doctype, 0);
else {
int position = indexOf(oldDocType);
children.remove(position);
children.add(position, doctype);
oldDocType.setParent(null);
oldDocType.setSiblingPosition(-1);
doctype.setParent(this);
doctype.setSiblingPosition(position); // WH
for (int i=children.size(); --i > position; ) { // WH
((Node)children.get(i)).setSiblingPosition(i);
}
}
}
public void setRootElement(Element root) {
Element oldRoot = this.getRootElement();
if (root == oldRoot) return;
else if (root == null) {
throw new NullPointerException("Root element cannot be null");
}
else if (root.getParent() != null) {
throw new MultipleParentException(root.getQualifiedName()
+ " already has a parent");
}
fillInBaseURI(oldRoot);
int index = indexOf(oldRoot);
oldRoot.setParent(null);
oldRoot.setSiblingPosition(-1); // WH
children.remove(index);
children.add(index, root);
root.setParent(this);
root.setSiblingPosition(index); // WH
for (int i=children.size(); --i > index; ) { // WH
((Node)children.get(i)).setSiblingPosition(i);
}
}
-
[XOM-interest] indexOf O(1) patch?,
Wolfgang Hoschek, 01/31/2005
- Re: [XOM-interest] indexOf O(1) patch?, Wolfgang Hoschek, 01/31/2005
-
Re: [XOM-interest] indexOf O(1) patch?,
Elliotte Harold, 01/31/2005
-
Re: [XOM-interest] indexOf O(1) patch?,
Wolfgang Hoschek, 01/31/2005
- Re: [XOM-interest] indexOf O(1) patch?, Wolfgang Hoschek, 01/31/2005
-
Re: [XOM-interest] indexOf O(1) patch?,
Wolfgang Hoschek, 01/31/2005
Archive powered by MHonArc 2.6.24.