Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

criteriaFind Attack Plan, Comments Welcomed

 
Jason Stortz
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to post a description of my planned attack to implement the criteriaFind method and see what kind of comments you all want to issue. Please note I decided to implement the method in the Data class, not extend the data class.
Pseudo Concept:

The first thing I do in my criteriaMethod is use ONE StringTokenizer to break down the criteria String object into field/value pairs such as Origin airport/SFO.
The second thing I did was to use the description array to make sure that the fields passed into the criteriaFind method all exist, if not, I return back a zero length array.
Then, use a method which I put into the DataInfo class that returns true if that DataInfo object indeed contains field/value pairs you can pass into the method. You actually pass String arrays, not just Strings. That way you can test for more than one field/value pair at a time. For Example, the following code would print "Has fields and values!", assuming record three indeed had an Origin airport field with the value of SFO.

Thus, I loop through each record calling the hasFieldsWithValues method passing in the data I parsed from the criteria String parameter. If the DataInfo method call returns true I add that "record" to a vector.
In the end I convert the vector to an array of DataInfo objects and I return it.
Comments and suggestions?
Thanks,
Jason
SCJP
[ February 03, 2002: Message edited by: Jason Stortz ]
[ February 03, 2002: Message edited by: Jason Stortz ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds pretty sound. Try to implement it, and lets see what happens.
Mark
 
tom mcmorrow
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also modified Data class. However i added a new method find(String field,String value), which returns a ArrayList of DataInf, for arbitary field in Data and I called this in my criteriaFind(String criteria) method.
It seems to work ok. However i now question the efficiency of my search algorithm it is something of a brute force approach. How much does efficiency way in importance.
tom
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we all took the brute force. Becuase of how small this project is, and the small data file, you can take this approach and not worry about being docked any points.
We all looped through the entire database record by record, and checking each one to see if they matched.
Mark
 
Jason Stortz
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented the original outlined plan above. I have, however, made one change. I was originally using the description array to make sure all the fields in the criteria string where actually in existance. But then as I implemented the methods into DataInfo to make it smart enough to say whether it has a certain field with a certain value I found I was double checking the field argument.
So, I removed the code to check if fields are valid as that is essentially already checked in the methods of DataInfo. Those methods take a field name and a value. If no field name exists with the specified value it returns false. So if I pass a non existing field into the method it returns false.
Otherwise the outlined attack above has worked wonderfully. I think I am done with criteriaFind now. Thanks for the comments.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic