[jdom-interest] Moving elements

Alex Rosen arosen at novell.com
Thu May 1 14:12:53 PDT 2003


I agree that removeContent() is better than getContentDetatched().

But I like the idea of removing the requirement that you detach before
adding. It always struck me as a little weird. It's hard to imagine how
the IllegalAddExceptions have helped anyone a whole lot, and they sure
have gotten in the way. The only benefit is if someone wants to copy a
node but forgets to clone() it first. But much of the time, when they
get this exception, they really want to move it instead, and just get
annoyed. (When Stroustrop was implementing the C++ compiler, his rule of
thumb was to not report a warning unless it actually indicated an error
at least 90% of the time. Otherwise people just get annoyed. I think we
should follow the same rule.)

The sort() problem is huge, and this change would fix it. If we don't
make this change, then the obvious way to sort elements,
Collections.sort(parent.getContent()), will always fail.

> I wouldn't either,  and besides
>    List list = anchorList.removeContent();
>    // do the sort
>    heading.setContent(list);
> is very clear about what is actual being done.

That's not really the problem - usually people want to move elements,
or sort them in place, I haven't heard of anyone wanting to do both.
Right now to do this you have to remove them from the parent, sort them,
and then re-add them to the same parent, which is totally unobvious.

This change would be backwards-compatible right?

Alex




More information about the jdom-interest mailing list