This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes find() in URLyBIRD - returning all records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "find() in URLyBIRD - returning all records" Watch "find() in URLyBIRD - returning all records" New topic
Author

find() in URLyBIRD - returning all records

Rafal Kawecki
Ranch Hand

Joined: Feb 08, 2011
Posts: 30


Hi ranchers,

I need help with the find method because I am all confused now.

Correct me if I'm wrong but:
  • find() method in Data class should not know anything about the view (as as the whole Data class), espacially that the view is interested in searching by name/location only
  • find() is responsible for returning record numbers that match the specified criteria
  • Specification says: 'A null value in criteria[n] matches any field value' - in other words (in my opinion) if there is at least one null then all records should be returned
  • view will be able to look only for: location, name, name or location so it will create:

  • so as you can see the find method will always return ALL records beacuse there will always be at least one null (of course I know there is additional filtering required becasue view expects exact matches)
  • if someday I'll add searching by all fields than no changes to the find() will be required

  • Am I missing somethig?

    Thanks in advance

    Rafal
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5449
        
      13

    I decided to ignore null values in the criteria array. If all values in criteria array are null I return all valid records. That's how I interpreted things and how I implemented the find-method of the Data class


    SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
    http://www.javaroe.be/
    Rafal Kawecki
    Ranch Hand

    Joined: Feb 08, 2011
    Posts: 30


    Thanks for extremely fast response.
    Roel De Nijs wrote:I decided to ignore null values in the criteria array.

    I don't get it. Can you please elaborate more on that? An example would be useful ;).

    Thanks in advance.
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5449
        
      13

    It's not hard: only non-null values are used to search the records.

    For example: using String[] criteria = {"par", null, null, ..., null }; will return all non-deleted records which name starts with "par".
    Rafal Kawecki
    Ranch Hand

    Joined: Feb 08, 2011
    Posts: 30

    Roel De Nijs wrote:using String[] criteria = {"par", null, null, ..., null }; will return all non-deleted records which name starts with "par".

    and String[] criteria = {"par", "loc", null, ..., null }; will return all non-deleted records which name starts with "par" OR location starts with "loc"?

    One more question: ignoring null values in the criteria array isn't breaking the requirements ?
    String[] criteria = {"par", "loc", null, ..., null }; shouldn't return all the records according to the specification ?

    Thanks
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5449
        
      13

    Rafal Kawecki wrote:and String[] criteria = {"par", "loc", null, ..., null }; will return all non-deleted records which name starts with "par" OR location starts with "loc"?


    Rafal Kawecki wrote:One more question: ignoring null values in the criteria array isn't breaking the requirements ?
    String[] criteria = {"par", "loc", null, ..., null }; shouldn't return all the records according to the specification ?
    I passed with that approach, so I assume it's not against the requirements But that's of course a decision you have to document in choices.txt (and maybe also a bit in javadoc). The javadoc of my find-method mentions that passing a String[] with all null-values will result in all non-deleted records being returned.
    Rafal Kawecki
    Ranch Hand

    Joined: Feb 08, 2011
    Posts: 30

    Thanks man !!!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: find() in URLyBIRD - returning all records