This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Implementing 'AND' and 'OR' logic in Find method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Implementing Watch "Implementing New topic
Author

Implementing 'AND' and 'OR' logic in Find method.

Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi everyone,

I�ve read a number of posts regarding the find mechanism and have ended up making myself more uncertain than before.

I�ve tried to make my database layer as generic as possible, therefore I written my find method to support searching of criteria against all fields, and limit the search to name/location within the GUI layer.

The doubt that I�ve got ringing in the back of my head is do we need to support logical �AND� and �OR� conditions. I�ve currently only implemented the �AND� condition, so any records must match criteria for all fields that are not null.

My reason for this is that I can not see a sensible (or simple) way of implementing the �OR� condition with the current find method signature, and from an application point of view it doesn�t make sense to me to support a search where you could allow the user to select a name of a hotel OR and location.

However one of my must requirements is :

Must allow the user to search data for all records, or for records where the name and/or location.

To me this requirement just means that the user can select :

  • Just the name
  • Just the location
  • Both name and location


  • Is this how you have interpreted the requirement? I�m trying to keep everything as simple as possible, and feel that the find method signature does enable the support of a complex search that you may find in a SQL database.

    Thanks

    Jason
    [ March 13, 2006: Message edited by: Jason Moors ]
    Xiao Di
    Ranch Hand

    Joined: Dec 23, 2005
    Posts: 31
    Originally posted by Jason Moors:

    To me this requirement just means that the user can select :

  • Just the name
  • Just the location
  • Both name and location



  • That is it, do not overthink it.


    SCJP, SCJD, SCEA
    Jason Moors
    Ranch Hand

    Joined: Dec 04, 2001
    Posts: 188
    Thanks for the clarification!

    I'm really enjoying this assignment, and I'm doing my best to keep it simple! However sometimes I think Sun are playing mind games with the requirements, as one minute I think I clearly understand everything and the next minute I start second guessing myself!

    Jason.
    Mike Tilling
    Ranch Hand

    Joined: Feb 17, 2006
    Posts: 86
    Hi

    It was mentionned in my assignement that

    "It Must allow the user to search data for all records, or for records where the name and/or location..."

    I understand that the user can select :

    Just the name
    Just the location
    Both name and location

    is there anyone who passed the exam and implemented the search method as I understand it

    Best Regards
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11465
        
      94

    Hi Mike,

    Many people have passed with that assumption.

    Regards, Andrew


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Jeroen T Wenting
    Ranch Hand

    Joined: Apr 21, 2006
    Posts: 1847
    Just think of the implications otherwise.
    It would mean you would enter for example "name: Teddy, Location: Xanadu" and get all records where either the person is called Teddy OR the person is located in Xanadu.
    That's just not logical, you want persons called Teddy who live in Xanadu.


    42
     
    GeeCON Prague 2014
     
    subject: Implementing 'AND' and 'OR' logic in Find method.