atom feed3 messages in org.jdom.jdom-interest[jdom-interest] Element comparison
FromSent OnAttachments
Bo Wang (Borders Online)Jul 31, 2000 11:28 am 
Jason HunterJul 31, 2000 12:52 pm 
Alex ChaffeeAug 4, 2000 7:17 am 
Subject:[jdom-interest] Element comparison
From:Alex Chaffee (
Date:Aug 4, 2000 7:17:29 am

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 :-)