File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using regex in criteriaFind Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using regex in criteriaFind" Watch "Using regex in criteriaFind" New topic

Using regex in criteriaFind

Venita Glasfurd

Joined: Sep 11, 2002
Posts: 12
After reading many posts here, I've decided to go with jdk1.4 for my assignment and have this question regarding regex.
I've modified the toString method in DataInfo to return a String which can be parsed using regex. I have the following code as part of my criteriaFind.

Is there some way I can eliminate the for loop above and use an And condition instead?
Sample data for the criteriaArray is below.
{"Carrier='SpeedyAir'", "Origin airport='*'"}
[ November 03, 2002: Message edited by: Venita Glasfurd ]
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
There is no way to use a single Regex to get the AND logic you need for matching, AFAIK. Remember that the instructions explicitly allow you to do case-sensitive matching, which implies String.equals(). Your approach seems backward in that you have a nicely structured hunk of data that you put into a String, which you then run regular expressions against. Ususally, when you must parse string inputs, you try to parse them into a nice data structure and do your manipulation on that; your code does the opposite. I would Keep It Simple and re-implement your matching code for three reasons: it's round-about and somewhat inefficient, it's harder for a novice programmer to understand than a simpler matching mechanism, and it is a minor violation of the convention for toString(), which Sun says is supposed to be suitable for debugging purposes (not necessarily identification purposes).
It is sorta covered in the JavaRanch Style Guide.
subject: Using regex in criteriaFind