aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes The bug-prone findByCriteria 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 "The bug-prone findByCriteria" Watch "The bug-prone findByCriteria" New topic
Author

The bug-prone findByCriteria

Jianping Wang
Ranch Hand

Joined: May 29, 2010
Posts: 60
findByCriteria takes an array of String. While some data are not String, they may be numeric, like size or money, so the search result may not be what we want. For example, client want a room low that $30, what we return are anything begining with "$30" such as $300, $302..

So I can just show the String field and hide numeric and other fields in search panel? Or be complex, introduce two-stage criteria search: return all matches that meet string criteria, and then in business layer, filter out those not meet numeric criteria?


SCJP 6 with 93%
Oracle Database SQL Expert with 98%
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
I didn't search for rooms but for contrators, and for me I was required to provide search by name and location. Do you need to search by price? If not, you can omit that problem altogether (I also noticed the same thing, but learned to live with it and ignored it).
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

No need to search on prices. My find-methods just returns the startsWith matches for any criterium (as described by the comments in the required interface).


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Jianping Wang
Ranch Hand

Joined: May 29, 2010
Posts: 60
So I only include name and location in search section of client GUI.
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 "exactly match" seems more restrict than "start with". Should I ignore "exactly match" and adopt "start with" instead?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Your find method in Data class should adopt a startsWith search, but you should only show the exact matches in the JTable. So you have to do some extra filtering in the client or the business layer
Jianping Wang
Ranch Hand

Joined: May 29, 2010
Posts: 60
That's a safe and accurate way!!!

Thank you.
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Jianping Wang wrote:So I only include name and location in search section of client GUI.
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 "exactly match" seems more restrict than "start with". Should I ignore "exactly match" and adopt "start with" instead?

I understood this differently - my GUI must allow searching by this, but it never says it is the only way, so I concluded I might provide something additional, a superset of this must. As a result, I implemented a case-insensitive search using String.contains(), which will work for the mentioned requirement (if someone puts an exact location, it will be found), will work for the example in the DB interface (for "Fred" find "Fred" and "Freddy"), but also is more user-friendly.
Generally, I see now that in y assignment I did a lot of things may way, a lot of decisions is made based on how I understood the requirements, not how this forum interprets them. For example, my assignment never says that I cannot use java.nio classes, so I used java.nio.Charset. We will see ;d
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Raf Szczypiorski wrote:As a result, I implemented a case-insensitive search using String.contains()

That's a nice alternative to solve the issue of startsWith and exact match

Raf Szczypiorski wrote:For example, my assignment never says that I cannot use java.nio classes, so I used java.nio.Charset.

That's a "requirement" which can be found on the official SCJD page:
The following APIs and facilities may not be used:
* Enterprise JavaBeans
* Servlets, JSP technology, or any other web-oriented APIs
* NIO, the New IO facilities
* Java DataBase Connectivity (JDBC) and SQL
* Java IDL API and CORBA
* Third party software libraries or tools (such as browsers)
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Roel De Nijs wrote:That's a "requirement" which can be found on the official SCJD page

Well, now I know it, I never looked at that page. But, I understand it that the instructions.html is the alpha and omega, and it is the document that states the requirement, overriding anything else. After all, it's called "instructions.html", right? If I fail for that reason, this will be really stupid (both on my and Suns part) and will try to take actions ;d But let's wait.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: The bug-prone findByCriteria