I need to be using an implementation of Set interface for storing objects of type MyObject.
MyObject has two fields: id and score. For equality on MyObject, only id is used. One of the functionality I need to use is to be able to support to be able to add scores when two MyObjects (with same ids) are inserted into this set.
Currently, I am using TreeSet and its isn't working the way I want it to work.
Set<MyObject> container = new TreeSet<MyObject>();
MyObject obj1 = new MyObject(12, 0.345);
container.add(obj1);
MyObject obj2 = new MyObject(12, 0.1);
container.add(obj2);
I want container to have Myobject(12,0.445) but it being a set, the container has MyObject(12, 0.1).
Is there something I can use which will give me what I am looking for?