File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes CriteriaFind Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "CriteriaFind" Watch "CriteriaFind" New topic
Author

CriteriaFind

Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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???
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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....
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
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?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Why do you think you would lose points?
Mark
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
well, they grade for effieciency. And I thought maybe your code is more effiecient than mine...
.
Chris Chang
Greenhorn

Joined: Sep 02, 2002
Posts: 14
Is it possible to use Regular Expression in JDK1.4 for searching ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CriteriaFind
 
Similar Threads
question on criteriaFind()
criteriaFind().. implementation
criteriaFind with java.util.regex
FBN: criteriaFind(String criteria) method; is this ok ?
criteriaFind review please...