• 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

NX: Find Requirments

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have moved this to a new topic. Here is a reminder.
The assigment states:


// 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".)
public int[] find(String[] criteria);


What does this really mean?
1) would "Fred" match a record of "Tom, Fred"? i.e should the input be compared against all tokens in the record?
2) would the input "Tom Fred" match the record "Fred"? i.e should each tokens in the input be compare against the each token of the record?
My current idea for this problem involves using the new split method in String with the new regular expression classes. Or would I be better to uses a StringTokenizer instead of the split method?
Andrew answered with:

All you are looking for anything that starts with the search parameter. You are not looking for a "contains" or "ends with".


However one of the records contains "Comma separated list of types of work this contractor can perform." If the user wanted to search for a contractor with a specified type of work, they could only search for the first type of work in the list. I hope you understand what i mean. Is this correct?
Thanks Chris
[ September 26, 2003: Message edited by: Chris Harris ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However one of the records contains "Comma separated list of types of work this contractor can perform." If the user wanted to search for a contractor with a specified type of work, they could only search for the first type of work in the list. I hope you understand what i mean. Is this correct?
Yes, your understanding matches mine here. The find() method specified seems a rather poor API for many types of searches we might want for a real-world application. However, consider these questions:
Does the find() API allow you to return strings which do not begin with the given criteria string?
Will the users of your application ever actually need to provide the type of search you desire? (Look at all your requirements.)
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,

Does the find() API allow you to return strings which do not begin with the given criteria string?


Currently the only way that my find method will return records which do not begin with the given criteria string, is to pass the param null into the method. But i can not decide if this is correct.
Chris
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read the requirments again and have found this line:

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.


Does this mean I only have to provide a search on name and location?
Chris
 
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Chris,
You wrote:


Does this mean I only have to provide a search on name and location?


To be specific, yes. However, you must design your find method so that it works unchanged if another field was included in the search by the GUI client.
The basic algorithm for the find method is rather straightforward: Loop through all fields: for each field, test if it is null? If it is null then this field passes the test and we go on to the next field. If it is not null then you do comparison of the field value with the passed token in the criteria array. The fields are FixedLengthStrings, i.e., they are Strings. What method does the String class have which allows you to test if it begins with a token? -- This is your clue!
Regards.
Bharat
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bharat,
Thanks for the advice. Here is the current match Record method

You suggested using the method startsWith within the class String. However notice that I have used the regular expression API to do this because IMO my method would be more flexible. What do you think?
Chris
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,
The assignment I am doing is the contractors one. In terms of searching from the GUI the specification states the following:


It must allow the user to search the data for all records, or records where the name and/or location fields match values specified by the user.


However, when detailing the background in page 1 of the instructions it states:


….They [customer service representatives] take requests from homeowners for a type of service and offer the homeowners one or more contractors that can provide the required services….


Therefore, I will also include this as a third search field in my GUI. The services pertaining to a record are stored in one field which is comma separated e.g. one record may have “painting, roofing, electrical”. So if a CSR selects roofing in the dropdown search list, and if you apply what Andrew said in the previous thread where you were discussing this, this record will not be found (as it only looks for matches at the start of strings -> “roofing” != “paintin”. However, if you break this field into tokens (in fact I break all the fields up into tokens – this is the only one that has commas, but I may change it so that only this field is broken into tokens), this record will be found for a customer requesting roofing – the second token will provide a match.
Am I incorrect here? What do you guys think? Maybe I should just keep my search to what was explicitly requested. However when I first read the document I remember making a note that one of the search fields must be the service provided – however when I got to the GUI requirements part this requirement was not there!
Bharat pointed out the following


However, you must design your find method so that it works unchanged if another field was included in the search by the GUI client.


I would agree with him here, therefore if I don’t include a search field for services (I probably will) the find method should still be able to handle it if it was added to the GUI at a later stage. Therefore I think the use of tokens for searching the services provided field is necessary anyways.
Please let me know what you guys think.
Regards, John
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

quote:
It must allow the user to search the data for all records


I'm now a little bit confused (that's nothing new ):
I have interpreted this always in the way that we have to search a specified value in all fields. For example if the user types in "N" it would match the smoking flag "N" or the location N for Norfolk etc.
Or did I missinterpret this sentence?
Greetings
Ulrich
 
Ulrich Heeger
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a very similar find-Method to yours; Chris:

As you can see I haven't included the possibility to search for separated words within one field.

"Comma separated list of types of work this contractor can perform."


Have you really such a requirement in your assignement?
Because I can't see something similar in mine (URLyBird 1.3.1).
Bharat, I'm sorry to annoy you once more, but perhaps you can help me, because you have also URLyBird
For example within the location field, we have "Bed & Breakfast", so if I search for "Br" I won't find it. Do you think this is ok?
Thanks in advance
Regards
Ulrich
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
May understanding is that the String [] 'criteria' that i pass to the find method will be the same length as the number of fields in a record. When an element within criteria has a value, it should match the field at the same position as the record. For example
criteria = "Fred",null,null,null,null -> search for name that starts with Fred
criteria = null,"Home",null,null,null -> search for location that starts with Home
criteria = "Fred","Home",null,null,null -> search for name that starts with Fred and a location that starts with Home.
Hope that I have made that understandable. Is this how you are using this
criteria array?
In terms of searching for skills, it sounds like we are doing the same assignment John. It does make sense to allow the user to do this. The statement that you pointed out on page one could be hidden requirement. I think I will re-design my search to handle this.
Thanks
Chris
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulrich,
sandly, yes I have such a field in my database :

Comma separated list of types of work this contractor can perform."



Chris
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic