commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] EqualsBuilder
Date Thu, 12 Sep 2002 22:13:52 GMT
Code committed to new Builder subpackage in commons proper. Thanks Steve..

I changed the formatting to four spaces, plus fixed a bug in append(Object)
method where the false flag wasn't set. Plus a few javadoc tidies and source
reorder to be in line with HashCodeBuilder.

HashCodeBuilder has also been brought up to scratch following the principles
from EqualsBuilder. It now handles multi dimensional arrays and reflection
too.

ToStringBuilder is mostly there (in sandbox), but CompareToBuilder is still
needed ;-)

Stephen

----- Original Message -----
From: "Steve Downey" <steve.downey@netfolio.com>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Sent: Thursday, September 12, 2002 1:11 PM
Subject: Re: [lang] EqualsBuilder


On Thursday 12 September 2002 05:20 am, scolebourne@btopenworld.com wrote:
> >  from:    Steve Downey <steve.downey@netfolio.com>
> >
> > > 1) I think that the reflection method should be static, and take the
> > > transient flag as a boolean parameter. The two techniques are
distinct.
> > > this way forces it.
> > > return EqualsBuilder.reflectionEquals(obj1, obj2);
> > > return EqualsBuilder.reflectionEquals(obj1, obj2, boolean
> > > includeTransient);
> >
> > I thought that too, at first, but the reflectionEquals (good name)
method
> > needs to call append(), and append() is NOT side effect free. It sets
the
> > isEquals flag on the EqualsBuilder object.
> >
> > Also, since the normal case requires an object, it's possible to call
> > reflectionEquals on an instance. If by some means reflectionEquals
didn't
> > use the isEquals property, it could lead to subtle errors, since
isEquals
> > would always be true.
>
> The solution is to create a new EqualsBuilder instance within the static
> reflectionEquals method. This fully keeps the separation, and avoids those
> subtle errors.
>

EqualsBuilder eb = new EqualsBuilder();
eb.reflectionEquals(this, that);
assert (eb.isEquals());

Static methods can be called on instances. You don't even get a warning for
it.
And creating an instance within a static method is a little odd.

Nonetheless:




----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message