Java
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists Java

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old January 5th, 2007, 01:00 AM
Stephen Kestle
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Equator interface

Java has Comparable and Comparator to compare objects. has an
equals() method. But what are we meant to do when and object has
multiple ways of being equal?

Consider an database row that has a name, code and a value. Equality
could be based on

* database id
* code
* name and code
* case-insensitive name

Any of these could be appropriate in different situations - in the same
way we use Comparators, we should be able to use Equators.

When extended to collections, this allows us to search for specific
values (with an EqualsPredicate that takes an Equator), and implement
Maps and Sets that use specific equators to determine uniqueness (a
HashEquator interface may also be defined for this).

However, it is also useful for general coding and equality checking.
Does this mean it's suitable for Lang (not really knowing anything about
that project)? Is there a Predicate class in Lang?

If an Equator is determined to be something worthwhile for the next
(generic) version of Collections, I can provide interfaces, default
implementations tests etc.

Cheers

Stephen Kestle



To unsubscribe, e-mail: commons-dev-unsubscribe (AT) jakarta (DOT) apache.org
For additional commands, e-mail: commons-dev-help (AT) jakarta (DOT) apache.org

Reply With Quote
  #2  
Old January 5th, 2007, 09:30 AM
Stephen Colebourne
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Equator interface

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.

BTW, I favour trying to create a 'FlexiMap' map implementation, which
has pluggable So, if
anyone wants to give that a go feel free!

Stephen


To unsubscribe, e-mail: commons-dev-unsubscribe (AT) jakarta (DOT) apache.org
For additional commands, e-mail: commons-dev-help (AT) jakarta (DOT) apache.org

Reply With Quote
  #3  
Old January 5th, 2007, 10:00 AM
Stephen Kestle
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.
- 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
() and Code() 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 (AT) jakarta (DOT) apache.org
For additional commands, e-mail: commons-dev-help (AT) jakarta (DOT) apache.org

Reply With Quote
  #4  
Old January 5th, 2007, 10:00 AM
Stephen Kestle
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Equator interface (and FlexiMap)

Stephen Colebourne wrote:
BTW, I favour trying to create a 'FlexiMap' map implementation, which
has pluggable So, if
anyone wants to give that a go feel free!
>

Stephen
In my current code, I have an Equator (equalTo()) method, and a
HashEquator (extends Equator and adds a hash() method), but now that
I've gone and implemented stuff, it comes down to the fact that nothing
uses Equator directly, because so many things use hash codes etc, that
you're just shooting yourself in the foot later by not following a
similar contract to the () method. Thus there will only be
one plug for hashcode/equals implementation (hopefully just clarifying
what you were thinking).

What I also was going to say is that you can use an EquatorMap and
ReferenceMap to decorate each other, but they're going to extend from
different classes, so that's no good.

So, are you talking about one Map to rule them all? Sounds convenient.

Stephen (not C :)



To unsubscribe, e-mail: commons-dev-unsubscribe (AT) jakarta (DOT) apache.org
For additional commands, e-mail: commons-dev-help (AT) jakarta (DOT) apache.org

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists Java > Equator interface


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT