commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nelson, Laird" <Laird.Nel...@FMR.COM>
Subject RE: [BeanUtils] "Diff" for beans?
Date Wed, 29 Jan 2003 18:59:26 GMT
> -----Original Message-----
> From: Henri Yandell [mailto:bayard@generationjava.com]
> Any reason why this is "Diff" for beans and not just "Diff" for Java
> classes?

Well, I wanted to do it at the object level, not the class level.  Maybe
that's not what you're talking about?  I mean, a, say, Dog class differs
from its, say, Animal superclass because it has extra methods (presumably)
and properties.  I'm not interested in that.  I'm more interested in taking
two Dog objects, and programmatically comparing the values of their
properties.  Dog's equals() method may only, for example, compare his name
property, but not *all* of his properties--I want to enforce by-value
semantics.  Actually, I don't *want* to do *any* of this, but that's a
different story.  :-)

So, for the itch I'm scratching, the graphs that I need to compare are
horrendously, ridiculously, stupendously complicated and designed by folks
who don't have a grasp of normalized data, but, miraculously, they're all
comprised entirely of fully-compliant Javabeans.  So I figured the easiest
(read: laziest) way to do this was to do it via PropertyDescriptors and the
like: that seems the only way to compare two Java beans "fully by value" as
opposed to letting their equals() methods figure it out.

(Additionally, the graphs are all constituted of generated classes, and I am
not permitted to modify the generator to output
by-value-semantics-preserving equals() methods.  So there goes that
approach.)

So, suppose I have two object graphs like this, where the first one is the
"reference" model, and the second is the one that is being compared against
it:

          (1)                        (2)
    Mark (Manager)             Mark (Manager)
Jim (Emp.)  Jane (Emp.)    Jim (Emp.)  Jane (Emp.)
Contractor (type)          Fulltimer (type)

...by which I mean: Mark is an instance of Manager.  He has two Employee
instances.  In graph 1, Jim has a "type" property of "Contractor", whereas
in graph 2, Jim has a "type" property of "Fulltimer".  Given these two
graphs, I need to produce a graph that has only the path to the differing
node, viz:

    Mark (Manager)
Jim (Emp.)
Fulltimer (type)

Note that Jane is not present in graph 3--I've (hopefully, unless I've
botched this example) only reproduced the path that contains a difference.

Is that more clear?  Hope I'm making some sense.

Laird

Mime
View raw message