Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Find method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Find method" Watch "Find method" New topic
Author

Find method

Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
I was confused about the find/search requirment but after searching a few posts, I'm even more confused . Hope you guys can help me clarify it

The requirement in the interface is as follows:

// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int[] find(String[] criteria);

The requirment in the document:
It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.

The way I was going to implment this was too as per Roel's post long time ago:
GUI contains 2 fields: one for location and for name. So the user has 4 possibilities:
- retrieve all hotel rooms (leave both input fields empty)
- search on a name (enter a value in the input field name and leave the input field location empty)
- search on a location (enter a value in the input field location and leave the input field name empty)
- search on both name and location (enter a value in both input fields)

The thing that is confusing me the most is that in the interface states that "value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy".)" but in the document search "records where the name and/or location fields exactly match values specified by the user" - These seem to say the opposite - Any thoughts to clarify this for me

Or how did others implement the search?

Thanks

Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 140

It seems weird, you're right. In the find method in the Data class you do what you have to do there. In the GUI you narrow your search results by filtering on exact matches only.


SCJP, SCWCD, SCJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

It's not the opposite at all. It's just a small difference in how your data class should work and what the business guys (and girls) want. Which happens in real life too.

So I implemented it as required: my Data class will return "beginning with" matches, my GUI will only show exact matches (so my business service does a bit of filtering).


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Rahim Nathwani
Greenhorn

Joined: Sep 19, 2005
Posts: 19
Thanks guys,

Just so I am clear - There is 2 requirements

1. Business where I show the user the exact match via the GUI
2. Data class req, where I return "beginning with" matches

Thanks
Rahim
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12



An example of how I handled this difference in requirements, can be found here.

 
Consider Paul's rocket mass heater.
 
subject: Find method
 
Similar Threads
URLyBird 1.2.1 findByCriteria()
NX: Contactor: Query on Search method
Urly bird find method: are search criteria "and"- or "or"-composed?
Do we need to filter the search result data?
URLyBird: What is "exactly match" in URLyBird?