Now, my question is:
I need to validate these values.
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.
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
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.
Joined: Mar 17, 2005
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......
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.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here