Brian Thompson wrote:
Why not do something likeNode node = ... NodeIterator iterator = node.getParent().getNodes(); long numSibs = iterator.getSize(); iterator.skip(numSibs-1); if (node.isSame(iterator.nextNode())) { return /* this is the last sibling */; } else { return /* this is not the last sibling */; } Even if iterator.skip(n) is no more efficient than n calls of iterator.next(), it saves a few operations in the body of the while loop.
I'd also say the above code is considerably more efficient than actually iterating over the nodes because skipping in jackrabbit does not load the node instances but works on the list of child node entries.
please note that getSize() may also return -1 if the size cannot be determined. regards marcel
