Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

The bug-prone findByCriteria

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jianping Wang
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a safe and accurate way!!!

Thank you.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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's a teeny, tiny, wafer thin ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic