• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap with Key/Value pairs at same address  RSS feed

 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeking ideas how to trouble shoot this HashMap.

EAS-30024=org.client.payroll.model.Respite@2abfb998,
EAS-300072=org.client.payroll.model.Respite@3f2807ce,
EAS-817=org.client.payroll.model.Respite@3f2807ce,
EAS-300073=org.client.payroll.model.Respite@1131c015,

Note that the middle two Key/Values have the same @address.

The code that generates the HashMap:
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know, but please tell us what goes wrong.
It appears that you have added the same “V” to two “K”s. Is that an error?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say that was a problem. You've got four entries in the Map, and two of them have the same toString() value, but so what?
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That is the error. Each K/V is unique. It had just occurred to me to think of it that simply as I am tracing through the HashMap creation.

The original respite HashMap is populated from a database. This code is looping through the database HashMap to create a HashMap that is then updated from time cards, then the updated HashMap is used to update the database.

When I saw the same two @address I thought corrupted HashMap not "same 'V' to two 'K's" . Not sure where it's happening. There are no duplicate records in the table and it's a simple query for all the records.

Anyhow, thanks for unscrambling my thinking.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no guarantee that the toString() value provided by Object is unique. It would be far better if you provided the Respite class with a proper toString() method so that we can have a sensible discussion about what's going on there.
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul. Somehow I'm getting the wrong record (value) from the database consitently matched up to that key out of a hundred. I spent most of the day trying to figure out why results were being calculated wrong instead of looking for bad initial values. I needed a second set of eyes. Hopefully, it will be straight forward to figure it out in the morning.
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This turned out to be a very good lesson in variable scope - pmo - (Variables should be defined with the least amount of scope possible IMHO). Thanks for the sanity checks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!