[jdom-interest] Element comparison
Alex Chaffee
guru at edamame.stinky.com
Fri Aug 4 07:17:51 PDT 2000
On Mon, Jul 31, 2000 at 12:52:37PM -0700, Jason Hunter wrote:
> > I need some function to compare the element I created with the
> > element in the existing document so that I can remove it.
>
> Standard thing to do is get the List of content, then remove the
> offending element. How you determine the "offending element" is your
> decision, and if you want to compare against an existing element in some
> way, then just write that code. We didn't write .equals() because to do
> a .equals() on an Element is potentially fully recursive down the
> document, and odds are you really just want to compare names and
> namespaces or something.
Yeah, I haven't mentioned it yet, but I think this equals thing is a
flaw. "odds are" is loaded; when I say "element1.equals(element2)" I'm
usually thinking deep compare, though I see the performance problem
with standard Hashtable implementations.
One possible amelioration would be to write a set of Comparators
that can be passed to the java.util sort and compare functions, that
do
Shallow/Deep Full Compare
Shallow/Deep Element-Name-Only Compare With/Without Namespace
or just one comparator with a set of flags for what criteria it uses.
(I haven't come against a situation yet in my short time using JDOM
where I need such a comparator; maybe once I do I'll write it :-)
--
Alex Chaffee mailto:alex at jguru.com
jGuru - Java News and FAQs http://www.jguru.com/alex/
Creator of Gamelan http://www.gamelan.com/
Founder of Purple Technology http://www.purpletech.com/
Curator of Stinky Art Collective http://www.stinky.com/
More information about the jdom-interest
mailing list