Skip to content

Commit

Permalink
move content of byNameAndTextRec into separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
bodewig committed May 10, 2015
1 parent 6d2e4ee commit 81bb26a
Showing 1 changed file with 1 addition and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,79 +213,7 @@ public boolean canBeCompared(Element controlElement,
* and child elements and nested text at each level (if any) can
* be compared.
*/
public static final ElementSelector
byNameAndTextRec = new ElementSelector() {
@Override
public boolean canBeCompared(Element controlElement,
Element testElement) {
if (!byNameAndText.canBeCompared(controlElement,
testElement)) {
return false;
}
NodeList controlChildren = controlElement.getChildNodes();
NodeList testChildren = testElement.getChildNodes();
final int controlLen = controlChildren.getLength();
final int testLen = testChildren.getLength();
int controlIndex, testIndex;
for (controlIndex = testIndex = 0;
controlIndex < controlLen && testIndex < testLen;
) {
// find next non-text child nodes
Node c = controlChildren.item(controlIndex);
while (isText(c) && ++controlIndex < controlLen) {
c = controlChildren.item(controlIndex);
}
if (isText(c)) {
break;
}
Node t = testChildren.item(testIndex);
while (isText(t) && ++testIndex < testLen) {
t = testChildren.item(testIndex);
}
if (isText(t)) {
break;
}

// different types of children make elements
// non-comparable
if (c.getNodeType() != t.getNodeType()) {
return false;
}
// recurse for child elements
if (c instanceof Element
&& !byNameAndTextRec.canBeCompared((Element) c,
(Element) t)) {
return false;
}

controlIndex++;
testIndex++;
}

// child lists exhausted?
if (controlIndex < controlLen) {
Node n = controlChildren.item(controlIndex);
while (isText(n) && ++controlIndex < controlLen) {
n = controlChildren.item(controlIndex);
}
// some non-Text children remained
if (controlIndex < controlLen) {
return false;
}
}
if (testIndex < testLen) {
Node n = testChildren.item(testIndex);
while (isText(n) && ++testIndex < testLen) {
n = testChildren.item(testIndex);
}
// some non-Text children remained
if (testIndex < testLen) {
return false;
}
}
return true;
}
};
public static final ElementSelector byNameAndTextRec = new ByNameAndTextRecSelector();

/**
* Negates another ElementSelector.
Expand Down

0 comments on commit 81bb26a

Please sign in to comment.