| Michael Bouschen 2005-08-15, 5:45 pm |
| Hi Craig, hi Karan,
my $0.02:
I like the idea of adding a new parameter to the EqualityHelper.equals
method specifying the instance and the field being compared.
The EqualityHelper could manage a list of differences. The list is
updated each time EqualityHelper.equals returns false. A new method
getDifferences (maybe you know a better name) returns th current list of
differences managed by the EqualityHelper instance. This allows us to
give a better error message in case the CompletenessTest fails because
of unexpected instances in the datastore.
As Craig already pointed out: any == comparison needs to be replaced by
EqualityHelper.equals calls. That means, we need to add equals methods
for primitives types. And we cannot use a conditional and (&&) anymore,
because we want to know all the differences.
Regards Michael
> Hi,
>
> So here's the deepEquals method for Address, updated from:
>
> public boolean deepCompareFields(DeepEquality other,
> EqualityHelper helper) {
> Address otherAddress = (Address)other;
> return (addrid == otherAddress.addrid) &&
> helper.equals(street, otherAddress.street) &&
> helper.equals(city, otherAddress.city) &&
> helper.equals(state, otherAddress.state) &&
> helper.equals(zipcode, otherAddress.zipcode) &&
> helper.equals(country, otherAddress.country);
> }
>
> to:
>
> public boolean deepCompareFields(DeepEquality other,
> EqualityHelper helper) {
> Address otherAddress = (Address)other;
> String instanceId = "Address." + addrid + " "; // instance identifier
> return helper.equals(addrid, otherAddress.addrid, instanceId +
> "addrid") &
> helper.equals(street, otherAddress.street, instanceid +
> "street") &
> helper.equals(city, otherAddress.city, instanceid + "city &
> helper.equals(state, otherAddress.state, instanceid +
> "state") &
> helper.equals(zipcode, otherAddress.zipcode, instanceid +
> "zipcode") &
> helper.equals(country, otherAddress.country, instanceid +
> "country");
> }
>
> A few notes. The && is replaced with & to guarantee that all of the
> equals methods are executed and there is not an early return from the
> method because of an inequality. This way, all inequalities can be
> reported, not just the first one.
>
> The helper.equals method needs another parameter that tell what
> instance and field are being compared.
>
> Craig
>
> On Aug 13, 2005, at 12:05 PM, Craig Russell wrote:
>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
--
Michael Bouschen Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de http://www.tech.spree.de/
Tel.:++49/30/235 520-33 Buelowstr. 66
Fax.:++49/30/2175 2012 D-10783 Berlin
|