Originally posted by John Le:
I've looked around the system and it does seem to me that the equals method is incorrectly implemented.....however; I'm not allowed to fix it. The set idea is good for eliminating duplicates, but I need to find the duplicates and report the dups back to the user.
I've decided to just loop through the collection, I was just hoping that there was a 'cooler' way to do it.
Thanks for the reply,
John
That is where the cardinality comes in. If you first use the Sets to get the intersection then you can loop through the set, use CollectionUtils.cardinality to determine how many duplicates to report, then add that many duplicates into the final list.
To duplicate the functionality of the CollectionUtils.intersection() method, you would need to check the cardinality of both listA and listB and use the smallest value. Something like:
Or something like that. It should mean you don't have to loop through so many objects, and maybe simplifies things. And of course you could put it all in a method in a utility class all your own that gets called like:
Again, not tested but you get the idea...