• 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

find() logic

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic