Skip to Content.
Sympa Menu

xom-interest - RE: [XOM-interest] Siblings

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Hallvard Tr�tteberg" <hal AT idi.ntnu.no>
  • To: "Elliotte Rusty Harold" <elharo AT metalab.unc.edu>
  • Cc: <xom-interest AT lists.ibiblio.org>
  • Subject: RE: [XOM-interest] Siblings
  • Date: Wed, 23 Oct 2002 12:33:41 +0200

> > Perhaps instead, both of these methods should be replaced with
> the following:
> >
> > public int position()
> >
> > (Alternate names: indexOf(), index())
>
> Or moved to ParentNode as getNextSibling(Node)/getPreviousSibling(Node)
> since in this model Nodes don't have siblings unless they have a parent.
> For performance the parent could keep last index fetched.
>
> > Open questions (assuming this is a good idea at all):
> >
> > 1. What should position() return if the parent is null? 0? -1? throw
> > an exception?
>
> Or put position(Node) in ParentNode and throw a exception if parent the
Node
> not equal to ParentNode, otherwise it is guaranteed to return a valid
index.

+1

I think I asked for such a method called indexOf, i.e.
ParentNode.indexOf(Node). This was in the context of implementing a Swing
TreeModel, which need to find the index/position of a child within a parent.
Personally I like indexOf best (though I'm used to position from Common
Lisp) and would prefer the method to return -1 if the parent isn't the
child's instead of throwing an exception.

BTW, another argument against the previous/next sibling methods is that they
give the impression of O(1) complexity, since the're considered "primitive",
while the're really O(n) in XOM and in many (most?) implementations
including .

Hallvard





Archive powered by MHonArc 2.6.24.

Top of Page