wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Confuse the findByCriteria() 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 "Confuse the findByCriteria()" Watch "Confuse the findByCriteria()" New topic
Author

Confuse the findByCriteria()

Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all
After looking up relational posts,I found some difficulties to understand the findByCriteria() method.

According to the part of code,I guess that is the following presentation:

What do you think of the implementation about this for details?
Regards,
Richard


Regards, Richard
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
what does the long[] represent
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
I am assuming an array of UNIQUE record numbers
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,Bill

what does the long[] represent ?

Because the "findByCriteria()" method will return a array with long values.

What's your useful opinion to implement the method?
Does all I written have some shortages?
Welcome other people to join us and criticize the topic.
Regards,
Richard
Seid Myadiyev
Ranch Hand

Joined: Jul 02, 2002
Posts: 196
Hello Richard,
You need to consider three more points in your search algorithm:
1. ANY - value which means that any value for the field which is part of the criteria, and this is completely different from �a null value in criteria[n] matches any field value �null for any� if criteria includes more than 2 (two) fields.
2. AND/OR - logical condition between the two field values as a pat of your criteria.
3. Upper/Lower case � String.startsWith(�) is case-sensitive; (is this acceptable by your specifications?)
Please share you ideas on these points!
+Seid
[ November 16, 2003: Message edited by: Seid Myadiyev ]

Seid Myadiyev<br />SCJP, SCWCD, SCBCD, SCEA-Part 1
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hello,Seid
Thank you analyze for details.
3. Upper/Lower case � String.startsWith(�) is case-sensitive; (is this acceptable by your specifications?)

I will study the 'startsWith()' and other methods in Java2 API,and then use them
What ways to implement it in your project?Would you like to give notes?
In my Assignment,there are not limitation statements about CASE-SENSITIVE.
Please join us. - other experts
Regards,
Richard
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Richard Jackson:
In my Assignment,there are not limitation statements about CASE-SENSITIVE.

Hi Richard,
Are you sure case-sensitivity may not be implied by your specifications? I have the Contractors 2.1.1 assignment and they state that the user interface "must allow the user to search the data... for records where the name and/or location fields exactly match values specified by the user." (Please note that the emphasis on the word "exactly" was placed by me.)
Of course, how you interpet an "exact" search can be a discussion left for your design document, but it is my opinion after reading a bunch of threads on this search criteria issue that it is probably a safe bet that "exact" means a "case-sensitive" search.
Offering search criteria choices in JComboBoxes provides a nice clean way to implement this functionality.

Regards,
Paul
[ November 16, 2003: Message edited by: Paul Tongyoo ]

Sun Certified Java Web Component Developer for J2EE v1.4<br />Sun Certified Java Developer for J2SE v1.4<br />Sun Certified Java Programmer for J2SE v1.4
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,Paul
Sorry.
Are you sure case-sensitivity may not be implied by your specifications?

I am ashamed of about this point.I dont exactly understand the "implied" meaning.
In my instructions.html,
All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field.

I think that all text values also contain the "criteria" string,and all fields strings present every field values of record.
I really do this not easily.
Please each one clarify the findByCriteria() with your experiences.
Regards,
Richard
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Hi Richard,
I apologize -- I was referring to the implied meaning of the specifications listed under the "User Interface" section of the specifications document. You are correct to not see any implied meaning in the statements you cite above; they are definitely straight to the point.
Could you restate your questions about the findByCriteria method? I'm afraid I do not understand what exactly you are finding difficult to understand.

Regards,
Paul
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,Paul
Here,I repost the part of my instructions.html file,

// 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 long[] findByCriteria(String[] criteria);

I ensure that:
A. The criteria[n] is the search key value that we might enter it into a text field.We use it to search those required records/fields.
B. When we enter null value in the criteria text field,this mean that we select all records.
When we enter a value starts with criteria[n] (like "Rich" matches "Richard" or "Richman" ),the method will return relational record numbers (into array).
My misunderstanding problems are:
1) How to judge whether the criteria[n] is valid? (only by startsWith() method ?)
2) Must I read records firstly ?Do I need know the length of "record number array"?
3) Am I still use String.match() method?
Regards,
Richard
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Richard Jackson:
My misunderstanding problems are:
1) How to judge whether the criteria[n] is valid? (only by startsWith() method ?)
2) Must I read records firstly ?Do I need know the length of "record number array"?
3) Am I still use String.match() method?

Hi Richard--
For your first question, I do not believe there exists any notion of a valid search criteria; if you are asking how to check if criteria[n] matches a field value in your record, then, yes, String.startsWith() is the operation that most closely matches the specified functionality. If you can justify your decision in your design document, however, you can use what ever means you'd like to determine a criteria match.
For your second question, you'll know the length of the returned record number array after traversing your entire list and comparing your criteria array against each record to determine if the two "match". The length of your return array will equal the number of matches you encounter. Reading the entire database in memory is a design decision; I personally read all the data contents of the file into a linked-list "cache" and used a list iterator to traverse the list and find all my matches. I am definitely sure there are more efficient ways to do this, however efficiency is not a requirement of my specifications so I believe my implementation is sufficient.
For your last question, if you are referring to the String.matches(String regex) operation, this is also a design decision. To satisfy the criteria match requirements on server-side, IMO String.startsWith(String) is sufficient. On client-side you'll find the criteria specifications differ, and it will be your call on what route to follow (which API function(s) to use).

HTH
Regards,
Paul
[ November 17, 2003: Message edited by: Paul Tongyoo ]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Paul,

For your last question, if you are referring to the String.matches(String regex) operation, this is also a design decision. To satisfy the criteria match requirements on server-side, IMO String.startsWith(String) is sufficient. On client-side you'll find the criteria specifications differ, and it will be your call on what route to follow (which API function(s) to use).

So, should I create a new function, say search(), in order to fulfill the client requirements, i.e. using String.indexOf(String) instead of String.startsWith(String)?
Or, I can simply use String.startsWith(String) as the search operation for the client?
Thanks


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Nicholas Cheung:
So, should I create a new function, say search(), in order to fulfill the client requirements, i.e. using String.indexOf(String) instead of String.startsWith(String)?
Or, I can simply use String.startsWith(String) as the search operation for the client?

Hi Nicholas--
You are on "a" right track; performing a filtering process on client-side is a possible solution to the criteria specification descrepency issue. Have you considered what Swing widgets you will be using to capture the user's search criteria? A nice solution that ranchers in this forum have come up with is choosing a widget that allows the user to submit exact values to the db.find(String[] criteria) function so that the server (which still only uses the String.startsWith(String) operation) will return only the records clients wanted and nothing more.
Regards,
Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confuse the findByCriteria()
 
Similar Threads
Should findByCriteria method return true if searching empty string for criteria[n]
URLyBird findByCriteria
URLBird find by Hotel or Name
NX: findByCriteria Method
a question about requirement, findByCriteria