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

find() logic

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I am looking at my find(), and I am not sure if I have things like they want them. The find() Javadocs state:

// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. 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 am unclear as to what the following code should return:


Should the method return records that only contain both "Castle" in the first column of the database and "Smallville" in the second, or that contain either?

I'm confused as to what they want exactly. It seems to me to make more sense that if both are provided, both should match in that order if there is to be a match.

Thanks for your input.
Matt
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt: I read the requirement as applied to your example to mean that each record number
returned must begin with "Castle' in the first column and "Smallville" in the second and the
other column values don't matter. Also, the return type must be int[] rather than String[].
For example, the record number of a record with "Castle747" and "SmallvilleOnTheLake"
should be included.

Jim ...
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the areas where interpretations often differ.

I implemented the low level search as inclusively as possible (any term, starts with) and then imposed further filtering (e.g., any or every term, exact match) in a higher layer.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like David already indicated: this one is certainly one of the areas where interpretations are very different. I implemented for the find-logic a case-insensitive startsWith search where 1 matching criterium is enough to have the record number be included in the int[] (null criteria are just ignored)
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used Roel's approach too. To clarify a bit, the case-insensitive
startsWith() must pass for each (non-null && non-blank) criteria.

Jim ...
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your input. I originally had it pretty lax and then decided to make it very restrictive. Sounds like it may have been unnecessary. So be it...

Thanks again guys...
Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic