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

Search method

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo,

My search record metod is somethig like :


To put it in words I use only one RAF to to brief all the records or to brief the records starting with a specific index.
The srategy is simple I check each record with a specific criteria( checkCriteria(criterias, record) ) and if the test is passed then the recNo(record index) is registered to the result List(here I think to use the in/out box features from java 1.5 ).

What I don't like on it is that the method is to long and it contains to many nested blocks (a try with a for with a if with a if with a if).

What you think about guys ?It is to complex ?

Now I see that I forget to close the RAF (probaly in a finaly bock)

Thanks,

Mihai

[ July 07, 2005: Message edited by: Mihai Radulescu ]
[ July 07, 2005: Message edited by: Mihai Radulescu ]
 
Yevgeniy Treyvus
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mihai,

I think your search method is a bit long. I think there are some quick ways you can make your code less complex and more intuitive.

For example, you could have a method that given an offset in the file, it would read a record from the database. Incidently, it would also have to handle any IO exceptions it may encounter.

In fact, doesn't your assignment specification require you to have a read method?? Mine did. If you already have a read method then why not use it and call it in your search method?

I think you can get rid of this code:




and replace it with a single call to a read method...Hope this helps.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yevgeniy,

You right the method is a little bit to long.
Why I don't use the read ? God question !
Because the read method at open/close a RAF for each record and this is not so nice.

Regards,

Mihai
 
Yevgeniy Treyvus
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mihai,

I guess it all depends on your implementation. But it does not seem intuitive to me to have to open/close the RandomAccessFile every time you have to read a record. Why not open your RAF in the constructor once, and only close it in the finalize?

In my implementation I did just that and passed.

Yevgeniy.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yevgeniy,

Opppps you are right I can use a a global RAF and close it in filaize, I can also use a "safety net" and implement a close method on my DataAccess class.

ThanX a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic