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

Strange criteriaFind

 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team
The instruction says that the criteriastring should of the follwoing format:
<field name>=<value to match>,<field name>=<value to match>,.............

However they have given the example as:
Carrier='XYZ',Origin='SFO',........
The confusion of having single quotes around the value to match in the example which are not there in the syntax of the criteria string.
Should i parse the single quotes also around the <value to match> of criteria string
Amit
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had my parser work with or without single quotes just to be on the safe side.
 
Gosling Gong
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you guys handle the case as
Carrier='XYZ,AB',Origin='SFO'
there is a comma in the value.
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I didn't handle that. That would require a more complicated parser routine.
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Robin
How others have handled it ???
Amit
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Kr Kumar:
Thanks Robin
How others have handled it ???
Amit

I just use JComboBoxes for the input and that way I put the input together the way I want it. That way the user doesnt have to worry about the criteria string being right either.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Kr Kumar:
Thanks Robin
How others have handled it ???
Amit


Hi Amit,
If you use J2SE 1.4 for the exam, you can take advantge of regular expressions, in which case the above search becomes trival.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Max
But i am using jdk1.3 for the assignment. So please guide me whether i should conside singlequotes while buolding or parsing the criteria string???
Pls guide, This will be a gr8 help. As mark is not here, i am not able to find perfect solutions to this query..

Amit
 
Eduard Jodas
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a StreamTokenizer instead of a StringTokenizer. The StreamTokenizer is much more powerful, flexible and difficult to manage.
For example, it treads quoted Strings like "This is a String" as one token. So, no problem if there is a ',' in the middle. You can change the quotation character to be '.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
If you're going to use 1.3, then I suggest overriding the toString method in your DataInfo method so that you have an easily parsable output String per record: say, "Desintation=SFO,Carrier=TWA,...".
Then strip out single or double quotes in the search string, convert everything to a similar case, and do your string comparison. Of course, there will be details you'll have to work out(say, spaces before and after the '=' sign, etc.,), but this should get you started.
Just out of curiosity, why are you using 1.3? Do you just feel that 1.4 might require a bigger learning curve then you want to take on right now?
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankas Max
This means that i need to take care of single quotes in the beginning and end of the value to match and strip them off?
Am i right ???

Will there be any case when single quotes are not coming. If so, should i considred them as a valid param and skip the step of stripping them off.

I am using JDK1.3 as i started my assignment long time back with this version only and now i am going to upload it next week.

Amit
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
Originally posted by Amit Kr Kumar:
Thankas Max
This means that i need to take care of single quotes in the beginning and end of the value to match and strip them off?
Am i right ???

That's one way to do it, sure. There are a lot of ways to go about this: I don't want to give you the impression that the way I suggested is the only 'right' way.

Will there be any case when single quotes are not coming. If so, should i considred them as a valid param and skip the step of stripping them off.

That depends on how you allow the users to enter their data. The GUI layer can(and probably should) do some data validation. There's no requirement that you have to deal with data that has quotes where it shouldn't: I don't see a need for you to impose the requirement on yourself.

I am using JDK1.3 as i started my assignment long time back with this version only and now i am going to upload it next week.

Amit
That's certainly reasonable. I would be curious to see if it compiled and worked under 1.4 however.
Good Luck!
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic