• 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

NX: findByCriteria - a different idea??

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen some posts out here regarding an approach to the findByCriteria "equality vs. starts with" dilemma. One approach was to overload the findByCriteria and have the overloaded method accept a start and end range. Then pad them with 0x00 for start range and 0xFF for end range to get the "starts with" search to work. If need equality, pad both start and end with 0x00.
Here's another idea:
Overload the method, but have the original method call the second worker method with a boolean indicating that it should not do the equality check. Then the worker method knows based on boolean whether to use String.equals or String.startsWith. I thought this might be easier to understand and maintain.

Opinions???
TJ
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How bout having your find function take a java.util.Comparator object as a parameter instead? Then the caller can pass in whatever comparison method he wants by implementing his own specification for the compare(Obj o1, Obj o2) method and passing it in with his criteria. The find function wouldn't know the difference in comparison methods; it'd just be calling compare(str1, str2) regardless of the type.
I started out with your idea but went with this since it was more extensible. Just my $0.02

Regards,
Paul
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Terry,
I edited my post in this thread, explaining why I do it that way. I needed criteria ranges for another purpose than the original wild-card search we have to implement. So, using ranges even in the "simple" findByCriteria() method lets me reuse my "extended" find code.
Paul, I use something similar to your idea (String.compareTo()).
Best,
Phil.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the good ideas. I'll consider using a comparator. I also need to think through the 48 hours rule which you mention in the other post. I haven't given that any thought yet.
TJ
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic