Issue Details (XML | Word | Printable)

Key: COLLECTIONS-242
Type: Improvement Improvement
Status: Reopened Reopened
Priority: Major Major
Assignee: Stephen Kestle
Reporter: Stephen Kestle
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Collections

Add Equator interface for more powerful collections

Created: 09/Mar/07 10:14 AM   Updated: 20/Oct/09 06:28 AM
Return to search
Component/s: Comparator
Affects Version/s: None
Fix Version/s: 4.0

Time Tracking:
Not Specified


 Description  « Hide
Java has Comparable and Comparator to compare objects, and objects have an equals() method. But there is no interface for when an object has multiple ways of being equal.

e.g.: an database object that has a name, code and a value. Equality could be based on:

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

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.

I propose that it has two methods:
boolean equate();
int hash();

I shall upload some files when I next get some time.

NB: This ticket is a summary of the email conversation begun on 5 Jan 2007: "equator interface" (http://archives.devshed.com/forums/java-118/equator-interface-2126195.html). Stephen C made reference there to creating a FlexiMap, but in my mind, that's additional to this issue (this interface still needs to be created to be able to stand alone).



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Stephen Colebourne added a comment - 09/Mar/07 11:23 PM
I think such an interface is a useful extension to the collections framework.

Stephen Kestle added a comment - 02/Apr/08 07:58 AM
Added Equator interface into functors package

Rahul Akolkar added a comment - 02/Apr/08 07:39 PM
Could you please fix the svn props for files added and make required changes to your svn client's config? See:

http://markmail.org/message/m65kwvj2mrr6zszf


Stephen Kestle added a comment - 25/Jun/08 11:19 PM
Since I keep referring to this ticket from various places...

Equators are also ensure that you are equating the same types - just found some code that was SomeObject.equals(String) (using a legacy constant instead of a SomeObject one).