File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings - design issue for validation

 
Anu satya
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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......
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 1
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic