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
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