I’d like to get anyone’s take on this. In Bodgitt and Scraper database, a Sub Contractors tasks are given as a list of jobs, in that a contractor can do Painting, Air Conditioning. The problem I’m facing here is in the findbyCriteria method whereby I must match the criteria passed for the field number that holds tasks and do a match.
If the user types in nothing, it will return true. No problem there. If the user types in “Painting” and matches it with “Painting, air conditioning” I think that it should return true. If the user types in “Air Conditioning, Painting” it should compare with “Painting, Air Conditioning”. If the user types in “Painting, Electrical” it should match with “Painting, Air Conditioning” because the user is searching for “Painting” and that contractor provides the job.
Anyone who had B & S and passed the Java Developers, how did any of ye go about this?
I didn't do the B&S assignment, but the URLyBird one and in that assignment the find-method has the following comment (in the provided interface by Sun):So that's what I implemented: a case-insensitive starts-with matching.
Doesn't your assignment have similar instructions? Because otherwise (like you demonstrated) the matching would become quiet complex. If you have same (similar) instructions as the URLyBird assignment it will make things a lot easier. Otherwise the only thing I can think of is using "," as a splitting char:
I'm doing B&S, haven't submitted yet though (thank goodness for Xmas holidays, can finally get back to finishing this off )
For this feature, my GUI instructions (which may or may not be similar to yours) states "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user."
That's the GUI search, not the findByCriteria method from the provided interface (by Sun). If the assignments are similar (and I guess they will be) the instructions of the findByCriteria will be a "starts with" search (for a String array of the same size as a record array), and the searching by the user (in the GUI) requires to return only the exact matches (just for name and location, just 2 fields out of a possible 6 or 7).
Joined: Jul 19, 2009
Ehsan, I have to warn you this. Roel De Nijs is right. Although the Interface for B & S states "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user." the actual findbyCriteria function states:
This meaning that the findbyCriteria must do a search for all fields in a record and not just what is specified for the interface. You have to remember somewhere in the documentation that some of the code that you develop must be adoptable for a future application.
Roel, I have the same idea as you have on searching for a list of tasks. My JobList is of an ArrayList and I'm wondering if this is the best list to use being that its not synchronised. What do you think?
Once again Guys, Roel and Ehsan, I want to say thank you very much for your kind input & I wish you all a merry christmas.
My JobList is of an ArrayList and I'm wondering if this is the best list to use being that its not synchronised. What do you think?
If this "list of jobs" is just a database field like name and location then I would simply keep it by a "starts with" search, because that's how the find-method is supposed to work and there is no requirement at all to do an advanced search on the "list of jobs".
My advice (for the complete assignment): if it is not required, don't do it and spend your valuable time on it, because you will not get extra credit for implementing a feature that is not required (but might loose some points when your implementation has a flaw).
Gents, you are absolutely right. I should have been more explicit in writing that, because there need to be exact matches, getting a user to write “Painting, Electrical” for an exact match would be annoying (if one chooses to use purely an input text box for searching). But this is besides the point, apologies for any confusion.
I agree with Roel in implementing the method as described, i.e. begins with match. Though, I do take your point Kevin about future compatibility, in which case I think it is fine to apply the open-close-principle here and allow this find method to be over-rided in the future I.e. NewData extends Data and allow a developer to re-implement the find() method so that when searching the specialties array index, the searching algorithm is updated to also return records where there are task matches as described in the very first post. I'm considering mentioning this in my choices.txt.