• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

comparing maps

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well... not correct to call them like that.. )all are unicode only, right?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic