added test case and bug fix for (next|previous)(Elements|Siblings) methods

This commit is contained in:
James Strachan
2012-05-22 18:51:44 +01:00
parent 88c4778055
commit a81e40fae2
2 changed files with 59 additions and 6 deletions
+9 -6
View File
@@ -202,23 +202,26 @@ fun Node.nextSiblings() : Iterator<Node> = NextSiblingIterator(this)
class NextSiblingIterator(var node: Node) : AbstractIterator<Node>() {
override fun computeNext(): Unit {
val next = node.getNextSibling()
if (next != null) {
setNext(next)
val nextValue = node.getNextSibling()
if (nextValue != null) {
setNext(nextValue)
node = nextValue
} else {
done()
}
}
}
/** Returns an [[Iterator]] over the next siblings of this node */
fun Node.previousSiblings() : Iterator<Node> = PreviousSiblingIterator(this)
class PreviousSiblingIterator(var node: Node) : AbstractIterator<Node>() {
override fun computeNext(): Unit {
val next = node.getPreviousSibling()
if (next != null) {
setNext(next)
val nextValue = node.getPreviousSibling()
if (nextValue != null) {
setNext(nextValue)
node = nextValue
} else {
done()
}