You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Kestle <st...@orionhealth.com> on 2007/01/05 02:26:06 UTC
Re: [Collections] Equator interface (methods)
Stephen Colebourne wrote:
> Stephen Kestle wrote:
>> If an Equator is determined to be something worthwhile for the next
>> (generic) version of Collections, I can provide interfaces, default
>> implementations tests etc.
>
> I certainly think that there are multiple ways to to equals checks. In
> my day job we compare by ==, equals and id.
>
> Done well, this would make a good enhancement in the 'new' collections.
Ok - having got some positive feedback, I will go on to the first issue:
the Equator interface design.
I propose two methods: one for equality checking, and another for hash
codes. This ensures that when used, the general contract of
Object.equals() and Object.hashCode() are followed in a similar fashion.
There is also the problem of naming here - what should the methods be
called? We want it to read well, so we'll start by listing the java
equals and compare methods. Summary of the rest of the post: I prefer
boolean equate() and int hash().
if ( object1.equals(object2) )
"if object1 equals object2 then..." - pretty simple
if ( object1.compareTo(object2) > 1 )
"if object1 compare to object2 is greater than 1 then..." -
"compared to" would make more sense in a sentence, but we favour active
tenses, since methods are an instruction on an object. Probably better
is to phrase it like:
"if (object1: compare [yourself] to object2) is greater than 1 then..."
if ( comparator.compare(object1, object2) > 1 )
"if (comparator: compare object1 and object2) is greater than 1 then..."
Getting hash out of the way is easy: hash(). But what's the correct
verb for equality?
if ( equator.equate(object1, object2) )
"if (equator: equate object1 and object2) then..." - I prefer this
one at the moment
if ( equator.equalTo(object1, object2) )
"if (equator: is object1 equal to object2) then ..." - I have this
at the moment, but it requires reshuffling of the sentence.
So this post is a bit verbose, but naming is one of the most important
tasks of development, and since this is rather foundational...
Cheers
Stephen (K)
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org