Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data/criteriaFind() - couple of questions

 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chaps
Just starting on the project, and thought that I'd start with criteriaFind(). I'm modifying Data to do this (as it seems the right place to put it), and my implementation is very simple: I use a private method to tokenize the criteria String into a Map of name/value pairs (searchMap), and then I loop over all the records and use a second private method to turn each record into a second map (recordMap). I compare the two with

The whole implementation is about 25 lines of code. This seems to work fine, and implicitly satisfies the requirement that a criteria string with invalid field names returns no entries (as containsAll will never match). However, I'm wondering how much sanity checking I should do when parsing the criteria String? The GUI should always drive it correctly, but as criteriaFind is completely generic it should presumably defend against invalid criteria Strings (e.g. "Origin ="), duplicates ("Origin='LHR',Origin='SFO'", although I guess it could OR), nulls etc. How far do I need to go with this, and is it better to treat invalid selectors as producing no matches (i.e. return an empty DataInfo array, as is the case for unknown field names) or should I throw an InvalidSelector exception back to the user?
Also, I presume that it *is* OK to add short private utility methods to the Data class? It remains completely generic, and splitting criteriaFind up makes the code much easier to read.
Finally, as an aside, I ran the Data class through JTest and there are 5 uncaught Runtime exceptions (NullPointer, ArrayIndexOutOfBounds, NegativeArraySize). Are these worth fixing?
 
Brian Blignaut
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that yes, you should protect against invalid search strings. I personally would rather throw an exception than just return an empty array as different clients might want handle this differently i.e if the client has entered the search string manually they might want to be informed of an invalid string. Also as to the runtime exceptions, these indicate a condition that should never occur and therefore should not be handled. They should instead be handled by the VM.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic