Hi Dane

From: "Dane Foster" <[EMAIL PROTECTED]>
> I have a recommendation for a new method to be added to the org.dom4j.Node
> interface:
> public boolean hasChildren().
>
> hasChildren should return true if this node has children and false if it
> doesn't.  The reason for this request is, if you are creating a tree
walking
> class hasChildren simplifies the process of figuring out how deep the
> nesting of nodes go.  If anyone needs justification via code sample I will
> gladly whip one up.

Just a thought, how about this:-

Node node = ..;

boolean hasChildren = false;
if ( node instanceof Branch ) {
    Branch branch = (Branch) node;
    hasChildren = branch.nodeCount() > 0;
}

The same thing could be done in one line of code (albeit a bit messy)

if ( node instanceof Branch && ((Branch) node).nodeCount() > 0 ) {
    // I have children...
}

Would having the hasChildren() make your code much simpler?

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to