Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should findByCriteria method return true if searching empty string for criteria[n]

 
pkinuk Buler
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

The following is the findByCriteria method in the DBAccess interface.


I use the String.startsWith method to judge the condition:
A non-null value in criteria[n] matches any field value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy"
.

But I found that if the criteria[n] is an empty string, the String.startsWith returns ture.

for example:


My question is if the parameter criteria is array like , should it return the matched record?


 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Pkinuk!

My question is if the parameter criteria is array like , should it return the matched record?


Well, interesting thing you found out. I myself didn't make such verification. Here's what I did:



So I just verify if it isn't null. In my implementation, this record would be returned.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,

by applying the String method toLowerCase() you realize matching in a case-insensitive style.

Is this a requrement or do you just go fine having just a case-sensitive match without using methods like toUpperCase / toLowerCase?

Regards,
Andy
 
Roel De Nijs
Sheriff
Posts: 9838
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have similar code as Roberto.

@Andy: I used the toLowerCase function too. It's not a must requirement, so you don't have to do it at all. But I'd just decided to implement case insensitive searching in my Data class. That's all

Kind regards,
Roel
 
pkinuk Buler
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I also use similar code as Roberto to match the criteria. Since you all can pass the exam by using same theory to implement the findByCriteria method, I don't think I will fail.

Thank you all.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic