Hello friends, I am facing a problem with the crtiteriaFind method. The first part is easy, using a String Tokeniser. The second part is a little confusing.....below is the my logic fieldName[0]=Carrier; fieldValue[0]=promptAuir; fieldNmae[1]=origin; fieldValue[1]=LAX for(int i=0;i<recordCount;i++) { dinfo=getRecord(i); findo=dinfo.getFields(); String [] values =dinfo.getValues(); for(int p=0;p<findo.length;p++) { if(fieldName[0].equals(finfo[p].getName()) && (fieldValue[0].equals(value[p]))) { /*My problem lies here, did you guys save the datainfo object here and then do a second search for all the second criteria*/ /* *I am saying the second criteria cos if the first one is carrier=prompt air and thats what the above code does. there is still the second left which is origin=lax...etc how did u guys implement that */ } } }//end of for record count any ideas?? i believe I am not on the wrong path.. any ideas???
How about getting the current record, and checking it against all the criteria? And if it matches all of them, putting that record into a return array. Mark
Got it! In The first search I saved all the record numbers that matched the first search criteria and the second time I searched on those record numbers which I got from the first and returned it to a array....
Originally posted by Prakash Krishnamurthy: Got it! In The first search I saved all the record numbers that matched the first search criteria and the second time I searched on those record numbers which I got from the first and returned it to a array....
Not exactly what I proposed. In your algorith you are reading records more than once. In my approach you only look at the record once. Try using a flag/boolean that is set to true, meaning match, then go through the criteria on that one record, and the moment it doesn't match set the boolean to false, then when that criteria loop is finished check the flag if true put that record in the matched collection, if false go to the next record. Mark
Prakash Krishnamurthy
Ranch Hand
Joined: Oct 08, 2002
Posts: 154
posted
0
Yeah, I got that working soon after I posted that question. Your algorithm seems to be more effiecient. But do you think I might lose points for this?
Oh, no actually part of the requirements say that efficiency isn't necessary for you grade. It says that even a less efficient algorithm is better a faster one, if the less efficient one is much more easier to maintain and understand. Mark
Originally posted by Chris Chang: Is it possible to use Regular Expression in JDK1.4 for searching ?
Yes you can, if you want. I tried to use them in the Beta exam, but ended up thinking that the other way described above was easier to implement, write, and understand. But thats not saying that I would never use Regular Expressions. On the contrary, I love regular expressions, they handle so many different tasks that would be near impossible any other way. Mark
lev grevnin
Ranch Hand
Joined: Jan 23, 2003
Posts: 35
posted
0
Actually i did use it for this project. It was a breeze. Not only they let the matching go very smoothly, but the good side effect is that it validated the criteria string. It was awsome. The disadvantage is that the reg exp isn't very easy to understand unless you are familiar with them. The length of the entire criteriaFind(), however, was shortened by A LOT, when i used regexps, as opposed to the matching way most people followed.