Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparing maps

 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
I have used tokenizers and parsed the criteria string "Flight number = 'SA001',Origin airport = 'SFO', Destination airport = 'DEN',Carrier = 'SpeedyAir'".
I have 2 maps(TreeMap), one (Map1)for storing the field names and values retrieved from the db.db file and another map(Map2) storing the field names and the corresponding values got from the criteria string.
When I read the values from the 'readRecord()' and then try to test for equality between the maps, Map1 seems to contain only the 'flight number' as a match and says it doesn't contain other fields. Can someone advise?
I have taken care of trimming spaces and case-sensitive issues.
 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could that be because I see some unicode characters in front of the fields other than the 'flight number'?
 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... not correct to call them like that.. )all are unicode only, right?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nandini
because I see some [ ... ] characters in front of the fields other than the 'flight number'?

Are you sure the strange characters are in front of the other fields? I suspect what you are seeing is the "filler" which follows the field. The database has fixed length fields, so if the data to go into the field is less than the size of the field, then the remainder of the field is filled with nulls (in the C sense: value zero).
So if you had a field which is 5 characters long, and you wanted to put the value "123" into it, then in the file it would be stored as "123\0\0", or in hex: 3132330000.
If you just take the read value of the field, then those nulls still exist. If you try and print them to screen, then they may appear as little boxes following your data (for example: "123��"). And, of course, if you try and compare them to data that does not have these nulls, then the comparison will fail.
That was a long way of trying to confirm what I suspect your problem is. And the solution is really simple:
String.trim()
Regards, Andrew
 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew. Infact I used the method trim() earlier to trim off those boxes. But what I don't understand is this - both the maps have exactly similar keys, but Map1 doesn't seem to contain anything other than the 'Flight Number'key of Map2. So I thought those boxes might still be a problem. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic