for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node instanceof Element) {
pos++;
Element domEl = (Element)node;
KnuthElement knuthEl = (KnuthElement)elementList.getElementList().get(pos);
if ("skip".equals(domEl.getLocalName())) {
pos += Integer.parseInt(getElementText(domEl)) - 1;
} else if ("box".equals(domEl.getLocalName())) {
if (!(knuthEl instanceof KnuthBox)) {
fail("Expected KnuthBox"
+ " at position " + pos
+ " but got: " + knuthEl.getClass().getName());
}
if (domEl.getAttribute("w").length() > 0) {
int w = Integer.parseInt(domEl.getAttribute("w"));
if (w != knuthEl.getW()) {
fail("Expected w=" + w
+ " at position " + pos
+ " but got: " + knuthEl.getW());
}
}
if ("true".equals(domEl.getAttribute("aux"))) {
if (!knuthEl.isAuxiliary()) {
fail("Expected auxiliary box"
+ " at position " + pos);
}
}
if ("false".equals(domEl.getAttribute("aux"))) {
if (knuthEl.isAuxiliary()) {
fail("Expected a normal, not an auxiliary box"
+ " at position " + pos);
}
}
} else if ("penalty".equals(domEl.getLocalName())) {
if (!(knuthEl instanceof KnuthPenalty)) {
fail("Expected KnuthPenalty "
+ " at position " + pos
+ " but got: " + knuthEl.getClass().getName());
}
KnuthPenalty pen = (KnuthPenalty)knuthEl;
if (domEl.getAttribute("w").length() > 0) {
int w = Integer.parseInt(domEl.getAttribute("w"));
if (w != knuthEl.getW()) {
fail("Expected w=" + w
+ " at position " + pos
+ " but got: " + knuthEl.getW());
}
}
if (domEl.getAttribute("p").length() > 0) {
if ("<0".equals(domEl.getAttribute("p"))) {
if (knuthEl.getP() >= 0) {
fail("Expected p<0"
+ " at position " + pos
+ " but got: " + knuthEl.getP());
}
} else if (">0".equals(domEl.getAttribute("p"))) {
if (knuthEl.getP() <= 0) {
fail("Expected p>0"
+ " at position " + pos
+ " but got: " + knuthEl.getP());
}
} else {
int p;
if ("INF".equalsIgnoreCase(domEl.getAttribute("p"))) {
p = KnuthPenalty.INFINITE;
} else if ("INFINITE".equalsIgnoreCase(domEl.getAttribute("p"))) {
p = KnuthPenalty.INFINITE;
} else if ("-INF".equalsIgnoreCase(domEl.getAttribute("p"))) {
p = -KnuthPenalty.INFINITE;
} else if ("-INFINITE".equalsIgnoreCase(domEl.getAttribute("p"))) {
p = -KnuthPenalty.INFINITE;
} else {
p = Integer.parseInt(domEl.getAttribute("p"));
}
if (p != knuthEl.getP()) {
fail("Expected p=" + p
+ " at position " + pos
+ " but got: " + knuthEl.getP());
}
}
}
if ("true".equals(domEl.getAttribute("flagged"))) {
if (!pen.isFlagged()) {
fail("Expected flagged penalty"
+ " at position " + pos);
}
} else if ("false".equals(domEl.getAttribute("flagged"))) {
if (pen.isFlagged()) {
fail("Expected non-flagged penalty"
+ " at position " + pos);
}
}
if ("true".equals(domEl.getAttribute("aux"))) {
if (!pen.isAuxiliary()) {
fail("Expected auxiliary penalty"
+ " at position " + pos);
}
} else if ("false".equals(domEl.getAttribute("aux"))) {
if (pen.isAuxiliary()) {
fail("Expected non-auxiliary penalty"
+ " at position " + pos);
}
}
} else if ("glue".equals(domEl.getLocalName())) {
if (!(knuthEl instanceof KnuthGlue)) {
fail("Expected KnuthGlue"
+ " at position " + pos
+ " but got: " + knuthEl.getClass().getName());
}
KnuthGlue glue = (KnuthGlue)knuthEl;
if (domEl.getAttribute("w").length() > 0) {
int w = Integer.parseInt(domEl.getAttribute("w"));
if (w != knuthEl.getW()) {
fail("Expected w=" + w
+ " at position " + pos
+ " but got: " + knuthEl.getW());
}
}
if (domEl.getAttribute("y").length() > 0) {
int stretch = Integer.parseInt(domEl.getAttribute("y"));
if (stretch != knuthEl.getY()) {
fail("Expected y=" + stretch
+ " (stretch) at position " + pos
+ " but got: " + knuthEl.getY());
}
}
if (domEl.getAttribute("z").length() > 0) {
int shrink = Integer.parseInt(domEl.getAttribute("z"));
if (shrink != knuthEl.getZ()) {
fail("Expected z=" + shrink
+ " (shrink) at position " + pos
+ " but got: " + knuthEl.getZ());
}
}
} else {
throw new IllegalArgumentException("Invalid child node for 'element-list': "
+ domEl.getLocalName()