cancel
Showing results for 
Search instead for 
Did you mean: 

Duplication

c_arunrathnakum
Champ in-the-making
Champ in-the-making
Hi,

I m currently facing this problem. Please let me know whether the approach is correct or not.

I have 2 lists of tasks:
list1 has tasks : {Task[1001],Task[1002],Task[1003],Task[1004]}
list2 has tasks : {Task[1005],Task[1006],Task[1001],Task[1002]}

I m adding list1 to list2 : list2.addAll(list1)

Now list2 contains : {Task[1001],Task[1002],Task[1003],Task[1004],Task[1005],Task[1006],Task[1001],Task[1002]}

I create a set with list2 :

Set<Task> tasksSet = new HashSet<Task>(list2);    //Imagining that the duplicates would be removed

tasksSet still contains the entries of list2, without removing the duplicates. :?  :?  :?



Can anybody help me?


Thanks,
Arun…
5 REPLIES 5

gokceng1
Champ in-the-making
Champ in-the-making
I suggest you to test with == whatever you think duplicate. I think both Task[1001] tasks are not same.

c_arunrathnakum
Champ in-the-making
Champ in-the-making
Hi,
How come it wont be same? I m picking them from the same table.. When i try to print the hashcode, they are different.. Is this an issue?

frederikherema1
Star Contributor
Star Contributor
You're picking them from the same table BUT they are fetched from a different activiti-context (each API-call builds up context with internal cache of entities). So the second entity returned is a different object. The equals and hash code aren't overridden, so it makes sense they are not equal.

As an alternative, use a hash map with key=id, value=task and make the put(..) conditional, based on whether or not the map already contains the task-id.

c_arunrathnakum
Champ in-the-making
Champ in-the-making
Thank u fred..
Will this be resolved/hash is the only way?

frederikherema1
Star Contributor
Star Contributor
We're not planning on implementing the equals/hashcode on the entities for now, so this is the only way around this problem…