I'm programming an algorythm which is going to receive rows from a database, those rows will be defined within an object that has attributes that identify them and a "ranking" attribute. I have to use a collection (or find a way) to keep all those objects sorted by the ranking value, HOWEVER if I receive another object that is equal to other already in the collection (except for the ranking), I need to update the ranking value (adding up both objects' rankings) and keep the collection sorted.
I was thinking about a TreeSet, but there's no way I can update a value that is not on the root...
Okay let's say my collection is like:
(name='Federer', id='131', ranking='3000')
(name='Nadal', id='234', ranking='2500')
(name='Del Potro', id='180', ranking='1800')
If I receive this:
(name='Nadal', id='234', ranking='1000')
The collection should end up like this:
(name='Nadal', id='234', ranking='3500')
(name='Federer', id='131', ranking='3000')
(name='Del Potro', id='180', ranking='1800')
Thanks a lot in advance.