This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Trying to understand the results I am getting from object equality ...
Ok first let me describe the problem..
The is multiple i need to filter duplicates objects from two two tables from db (Hibenate all of the cluses are set up) preset condition is firstName, lastName, dateOfbirth. Not shure about best practices I have created an Class to hold a equality object
So in my service class I call Query on 2 tables and create custom list Iterate over list and objects
So as you can see I have implemented a an equality and wiz.addAll on the list here is the funny result
2012-09-01 18:49:09,198 INFO [com.equality.service.CopareToServices] - < Size from wizard 392> (thread 1008 invoke CopareToServices.compareObjects)
After itteration >>>>
2012-09-01 18:49:09,910 INFO [com.equality.service.CopareToServices] - <List tow size 391 List hash set size > (thread 1008 invoke CopareToServices.compareObjects)
Equality method only found a single duplicate record >>>
And this is after Implementing removeAll on the heshSet
2012-09-01 18:49:09,918 INFO [com.equality.service.CopareToServices] - <Added assignors to the list 216> (thread 1008 invoke CopareToServices.compareObjects)
171 Duplicates were removed which sound about right...
I have tried with Apache commons and guava equality implementation ... for equality
Why native removeAll on the list removes duplicates but the equality does not return true ???
Will appreciate any help I can get on this
Just found out That ound out that loop with in the loop it's like testing against the last element ...
What would be the proper way to itterate over two lists and perform equality check of an element agains other list ..
If your requirement is just to have a a collection of distinct objects and not to perform any deletion to the tables, you may consider just adding all the elements from both the tables into a Set. By definition of Set, it will not have any duplicates and even if there are duplicates as you are overriding the equals method, there will be only one instance of the object.
SCJP 1.6,Preparing (Tryin to prepare) for scwcd
Joined: Sep 01, 2012
Thank you for you response Harsha Ka
Yes I did that while testing ..
But I need to preform an operation on the duplicate objects ...