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 Exact match and starts with 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 "Exact match and starts with" Watch "Exact match and starts with" New topic
Author

Exact match and starts with

Mike Vess
Ranch Hand

Joined: Aug 25, 2004
Posts: 41
Why should the client search for exact match and the DBMain interface find method search for records that starts with the values?

Client requrement:
"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."

DBMain requirement (find method):
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".)

This seems really strange because then you have to implement two different search functions? One in Data class and one somewhere else. I have solved this but i wanted to hear what you have to say about this anyway.


What you thought was right today may need a refactoring tomorrow...
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Mike Vess:
Why should the client search for exact match and the DBMain interface find method search for records that starts with the values?

Client requrement:
"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."

DBMain requirement (find method):
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".)

This seems really strange because then you have to implement two different search functions? One in Data class and one somewhere else. I have solved this but i wanted to hear what you have to say about this anyway.


Actually you only need the one that does the "starts with" since the spec also says that the fields are zero delimited. If you want an exact match all you need to do is append a zero to the end of the search string. This only works if you also trim the fields read from the data base and append a zero to them before the compare.
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by Mike Vess:
Why should the client search for exact match and the DBMain interface find method search for records that starts with the values?

Client requrement:
"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."

DBMain requirement (find method):
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".)

This seems really strange because then you have to implement two different search functions? One in Data class and one somewhere else. I have solved this but i wanted to hear what you have to say about this anyway.


Your Data class' find method must search on partial match, and your business logic must convert those searches into exact-match outcomes.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exact match and starts with
 
Similar Threads
search requirement in B&S
URLyBird 1.2.1 findByCriteria()
[NX] Question about the findByCriteria.
URLyBird 1.3.2 : find method ambiguos
URLyBird: What is "exactly match" in URLyBird?