• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strings - design issue for validation

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a strange requirement.

I have a String like: Meals(veg(soup&starters(price=40 || 50))nonveg(seaFood)delivery=parcel || ready_to_eat)

I parse this string and put all the values with in veg to a string array

example:
String[] veg = {soup,starters}
String[] nonveg = {seafood}
String[] delivery={parcel,ready_to_eat}

Now, my question is:
I need to validate these values.
Example:
Meals = it should be validated against uppercase or lowercase, and correct spelling. if it fails, no need to validate other stuff.

If Meals is validated succssfully, I need to validate veg in such a way that:
veg should have only soup and starters with in that. nothing else.
if it has veg(salad) then, the validation should fails and send "fail" as response.

Is there a best design to do this ? My desing as follows:


My problem is how to call the methods or the sequence of methods? so that the complete Order String is validated.
do i need to put the method calls in if...else or in switch statement or is there any other way? I want the best desing for this issue.




Please help me?
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like a computer science assignment for language tokenizing and syntax analysis.

This task will be broken down to at least 2 steps : tokenizing and syntax-analyzing

e.g.
.
.
.

String[] tokens = tokenize(inputString);
.
.
.

boolean valid = analyzeSyntax(tokens);


tokenize() will break down the string into chunks according to your language.

analyzeSyntax() will check the chunks 1 by 1, if it complies to your language's rules. I have implemented this using recursion.
 
Anu satya
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you for your reply.
I have already done with the coding of analyzing the string and putting it into different String Array.
My problem is for Validation. How to validate each segment ?

Price is with in Veg Segment. Veg Segment is with in Meals.
So, first i need to validate the Meals. IF validation fails there, no need to validate other items.
If validation for Meals is success, Then it should move to veg segment to validate. how to do this....I want to way to call the validation process......
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anu satya wrote:If validation for Meals is success, Then it should move to veg segment to validate. how to do this....I want to way to call the validation process......


Seems to me that what you had looked fine, unless you want to encode your "rules" somehow.

The only suggestion I'd have is for your validation methods to return a boolean indicating whether they worked or not, viz:You can't use a switch statement because each stage depends on the outcome of a previous one.

[Edit] An alternative, if there's no other logic involved, is simply to string them together:because && guarantees that the RHO is only evaluted if the LHO is true.
However it's all dependant on your validation methods returning a result.

HIH

Winston
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that if your problem got too complex to handle with your programmed logic approach, you could graduate to a Business Rules Engine.

Bill
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic