• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S final word on trim()

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Does these sound ok (ok in terms of I did it and passed ) ?

1. Is it safe to assume that leading and/or trailing whitespace characters in create/update/find are not allowed, I throw a IAE in such case. My implementation of Data class is rather defensive. If I write " Kate " it's either saved as it is or rejected as invalid and not silently changed to "Kate".
- trailing whitespaces - padding with spaces in db eliminates usage of these
- leading whitespaces - there are none in supplied db file + I don't have implement my own trimTrailing(String) utility method, just a simple trim() does the trick when records are loaded from db. On the other hand goodness knows what the customer wants, perhaps it's safer to allow leading whitespaces to be entered.

2. In GUI I also trim values in search fields (setText(getText().trim())) when user presses the Search button. Since they are internally trimmed for search the user should be aware of that, right ?

3. In GUI empty name/location criteria matches only empty field in db. The * matches any value (translated to null), escape character is \. The * only works as a wildcard if query contains no other characters (requirement for full search matches only).

thanks in advance,
Kate


 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I also used trim() when creating/updating records

2. I just used the search values as provided, no trimming here (and/or internally)

3. My search method is a lot simpler: a null value is ignored, otherwise you have a match if the value starts with the search criterium. You need at least 1 hit to have a match.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic