Forums Register Login

criteriaFInd critiques

+Pie Number of slices to send: Send
Hi All,
I have implemented my criteriaFind() method using a brute force technique in the following manner.
I create a StringTokenizer object on the criteria string passed in. I then create a String[] array that contains all the (trimmed) Field names. I also create a HashMap to hold the individual values of the criteria String.
I then loop thru the Tokenizer and create another StringTokenizer on the indvidual tokens. I then check if there are exactly two tokens on the new Tokenizer and if not I imediately return an empty DataInfo[] array. I then check the first token against all the Field names in a loop and if I find a match I create an Integer using the loop index, set a boolean to true to indicate that I have a valid Field name and break. Once out of the loop if my boolean is false I once again return an empty array. If not I get the next token, strip off the quotes then add it to my HashMap using the Integer as key.
Once I have the HashMap loaded, I loop thru all records in the database (calling getRecord) and check each against the values in the Hash and if a record matches everything in the Hash, I add the record to an ArrayList.
Finally I return a DataInfo[] using the toArray method of the ArrayList (of course typecasting it back to DataInfo[]).
Also I am trimming the tokens so that a criteria String could look somethin like this and still work:
" Carrier = ' SpeedyAir ', Origin = ' DFW '"
I appreciate any feedback.
Michael Morris
+Pie Number of slices to send: Send
It's tough to comment on it. I mean if it works than keep it just like that. It is close to what I had.
Mark
+Pie Number of slices to send: Send
Thanks Mark,
What about allowing the whitespace? I've always done this in my real apps. Also I accept 'any' or '*' as a wildcard. In a real app I would probably just use '*'.
Thanks again for all your help
Michael Morris
+Pie Number of slices to send: Send
I never really worry about whitespace, especially since your code is going to create the criteriaString, so therefore you are completely in control as to whether a space can ever get in there. As far as Any or *, I didn't even include them. So if they selected origin as any, arrival as any, and carrier as "My Carrier". My criteria String would be just "carrier="My Carrier"". SOmething like that.
Mark
+Pie Number of slices to send: Send
Thanks again Mark,
Yea because all I'm doing if I get a wildcard is just ignore it (ie not put it in the Hash) anyway.
Michael Morris
I once met a man from Nantucket. He had a tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 598 times.
Similar Threads
please review criteriaFind -> good riddance from hateful "ANY"
search algorithm: clarity and efficiency
empty tokens in String Tokenizer
Please review my criteriaFind method
FBN: criteriaFind(String criteria) method; is this ok ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:31:50.