Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Three cosmetic patches

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Three cosmetic patches
  • Date: Mon, 09 Feb 2004 15:42:41 -0800

Here are some cosmetic patches against d24.
The first two avoid some code duplication, and the third makes it a bit more efficient.

Wolfgang.

in class ParentNode:
public Node removeChild(Node child) {

//if (children == null) {
// throw new NoSuchChildException(
// "Child does not belong to this node"
// );
//}
// This next line is a hotspot
//int position = children.indexOf(child);
int position = this.indexOf(child);
if (position == -1) {
throw new NoSuchChildException(
"Child does not belong to this node"
);
}
return removeChild(position);
//checkRemoveChild(child, position);
//children.remove(position);

//child.setParent(null);
//return child;
}

public final void replaceChild(Node oldChild, Node newChild) {
//if (children == null) {
// throw new NoSuchChildException(
// "Reference node is not a child of this node."
// );
//}
//int position = children.indexOf(oldChild);
int position = this.indexOf(oldChild);
if (position == -1) {
throw new NoSuchChildException(
"Reference node is not a child of this node."
);
}
removeChild(position);
insertChild(newChild, position);
}


in class Element:
private static boolean isAncestor(Node parent, Node child) {
//if (child == parent) return true;
//if (parent == null) return false;
//else return isAncestor(parent.getParent(), child);
// for efficiency avoid recursion in favour of iteration
while (true) {
if (child == parent) return true;
if (parent == null) return false;

parent = parent.getParent();
}
}





Archive powered by MHonArc 2.6.24.

Top of Page