• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: findByCriteria - a different idea??

 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • 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
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic