/** Is 'sub' a subtree of this list?
* The siblings of the root are NOT ignored.
*/
public boolean equalsListPartial(AST sub) {
AST sibling;
// the empty tree is always a subset of any tree.
if (sub == null) {
return true;
}
// Otherwise, start walking sibling lists. First mismatch, return false.
for (sibling = this;
sibling != null && sub != null;
sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) {
// as a quick optimization, check roots first.
if (!sibling.equals(sub)) return false;
// if roots match, do partial list match test on children.
if (sibling.getFirstChild() != null) {
if (!sibling.getFirstChild().equalsListPartial(sub.getFirstChild())) return false;
}
}
if (sibling == null && sub != null) {
// nothing left to match in this tree, but subtree has more
return false;