jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: Finding out if node is a last child of a parent
Date Tue, 14 Aug 2007 09:41:32 GMT
Brian Thompson wrote:
> Why not do something like
> 
>     Node 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

Mime
View raw message