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 Search function 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 "Search function" Watch "Search function" New topic

Search function

Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
I'm currently banging out the search method for the Data class.
Here's what I'm doing:
I have a vector for search results that match the query(to later be converted into a array of DataInfo objects)
Extracting the Values - no problem, used string tokenizer and substring to get the field name and value then put them in an array of strings.
searching - for loop with getRecord(i). retreives array of strings and fieldInfo from the DataInfo to two separate arrays, respectively.(will use getName() on fieldInfos later)
My problem now lies in acutally comparing the Strings. Coding this will be easy(if a bit tedious), but is there a better way to due this than having a kazillion nested for loops?
Feel free to correct me on the above also.

Adam Roberts - SCJP2, SCJD<br />insert witty something here
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Adam,
I have a post on the same subject. I pulled mine off with 3 loops and about 50 lines of code. Instead of matching every field name, I keyed on the index of each field and put the criteria value into a HashMap thereby eliminating one of the loops.
Anyway here's the post:
Hope this helps
Michael Morris
[ March 26, 2002: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Search function
It's not a secret anymore!