[jdom-interest] Problem with 'setChildren' on JDOM B8

duncan.loveday at bt.com duncan.loveday at bt.com
Tue Dec 10 02:23:08 PST 2002


Jason,

> Cloning the list should accomplish this.  That's what we'd have to do to
add such a method, and it seems a waste when it's so easy.

Forgive my ignorance. How would I clone a List ? There's no 'clone()' method
on that interface and I wouldn't want to make assumptions about the
underlying implementation would I ?

Also, I'd be concerned about making a deep clone that recursively clones all
the elements and sub-elements within the List from a point of view of run
time cost. There ought to be a way of just returning a static list of
references to the content.

Cheers,

Duncan.

-----Original Message-----
From: Jason Hunter [mailto:jhunter at acm.org]
Sent: 09 December 2002 18:34
To: Loveday,DAH,Duncan,YEE24 R
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Problem with 'setChildren' on JDOM B8


> Thanks for this. A couple of observations
> 
> (1) I get no deprecation warnings for setChildren() on compilation and
don't
> see it as deprecated at
>
http://www.jdom.org/docs/apidocs/org/jdom/Element.html#setChildren(java.util
> .List)

Yes, it was deprecated after b8.  Sorry I didn't notice that.  I'm
running with latest CVS, and it's deprecated there.

> (3) What you suggest would equate in my case to
> 
> elem.setContent(elem.getChildren());
> 
> but this clears both text and element content because of the "live" List
> returned by getChildren(). When 'setContent()' clears the old content, it
> also clears the new content it is about to replace it with. It might be
nice
> to have the option to obtain "non-live" Lists that provide a static
snapshot
> of the content.

Cloning the list should accomplish this.  That's what we'd have to do to
add such a method, and it seems a waste when it's so easy.

> (4) I would suggest it might also be nice to have methods to clear
specific
> types of content. For example
> 
>     public void removeText()

That might be nice, but it's a slippery slope.  I think using the
general Filter mechanism is a better solution than specific methods for
every type of filter.  With filters you could just apply a filter that
prefers everything but text.

> Hope nobody is offended by any of this.

No way, comments like yours are great.  Hope you're not offended by my
answers.  :-)

-jh-





More information about the jdom-interest mailing list