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

Why int[] find(String[] criteria) and not String[][] find(String[] criteria) ?

 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm working on Bodgitt and Scarper version 2.1.3 and I have this method signature to the find method "public int[] find(String[] criteria)".

I'll have to do the search and then read all the records again ?
Why not just read all the record in the find method ?
Why not "public String[][] find(String[] criteria)" ?

Thanks for your help.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that your should return a group of record number rather than record itself. I think in your specification, there must be some description about this issue.

BTW. I think regexp is a good way to perform this.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and I think when u finish your initialization, you can cache it in an Array and it will be much easier and efficient to get the proper record
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to write some unnecessary methods if you have already all that you need?
Write a wrapper for your Data and define your method there. And this method will call find(..) and read(..) method from you Data and create a String[][] object.

Am I right?
Olena
 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Olena,
Yes, I can execute the find 1 time then the read n times. Why not just 1 find ?
Is this the way to go ? n reads ?

Thanks.
 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zee,
My specification only says
"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.".
I must use a cache of records ? If I have a cache, I must keep it up to date. Then, what is the diference between show the cache and return the String[][] ?

Thanks.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my project, I don't keep it always "update to date", like a web design, after you load the page, it became "static"
, it will only be refreshed when you perform insert/update/delete

for the insert action, if the record already exist, throw out the DuplicateKeyException

update a already updated record will let it update again

It will be ignored if user delete a already deleted record.

if user perform any of 3 above action, the UI will be refreshed, that means the changes made by other user will take effect now.

Actually, This is my approach, hope this can help u, it will be great if any one else can post better way to do this.
 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zee,
First I was thinking about keep the records in a cache (HashMap) but my specification says :
"The company's IT department has a data file that contains the essential information for the company, but because the data must continue to be manipulated for reports another custom-written application, the new system must reimplement the database code from scratch without altering the data file format".
If I use a cache my system may never see a update did by the anothers aplications.

What do you think ?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Silva:

I'll have to do the search and then read all the records again ?
Why not just read all the record in the find method ?
Why not "public String[][] find(String[] criteria)" ?


Hi William,

As you get more involved with your assignment you'll notice that the interface you were given by SUN is less than perfect and that you'll have to make decisions to overcome or to live with this less than perfect interface. Part of the SCJD assigment is testing your ability to code and at the same to make conscious decisions and understand why you made them.

Hope this explaination helps,

Matt.
 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,

Do you agree with me ?

Thanks.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There've been a few members on here who've implemented record caching and got good marks and there are others who've not implemented record caching and got good marks. So the choice is up to you.

I've not implemented any recording caching and write all updates directly to disk. I didn't see any benefits in implementing a cache although I'm sure others will disagree.
 
William Silva
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,
Then... you did the same thing ?

int[] recodsNo = find...

for (int recNo=0; recNo<recodsNo.lenght;recNo++){
String[] data = read(recNo);
.......
}

Thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, I implemented something similar on the client side of things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic