• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

B&S: Does anyone care about find()?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

first of all, I used the forum'd search function and found a lot of threads dealing with the find() method. I'm sorry if I missed one already answering my question.
In my Bodgitt an Scarper 2.1.1 assignment I have to implement a database find(String[] criteria) method which supports prefix matching for each array index. The simple implementation would obviously be to iterate the complete database and perform a String.startsWith() for each record entry.
Obviously, this implementation does not scale very well.
In real life, I would add some kind of createIndex(int recordFieldIndex) method to my database which creates some sort of suffix tree as a Trie for instance. However, for the SCJD, such an implementation seems to be a little out of scope, don't you think?
Has anyone of you spent time on implementing a find() method which is at least a little smarter than the complete database iteration?

Best regards,
Thomas
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My requirements state that code simplicity is more important than performance, so I decided to just iterate over my entire db. I a solution using Trie is a bit overcomplicated for the SCJD.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I have implemented case insensitive search: fieldStr.toUpperCase().startsWith(...) and I believe it should be fine for the current task. First of all because there are many more things that deserve greater attention, secondly any other implementation would require greater complexity which is not welcome as you wont get extra points for extended, more reliable, more efficient or whatever functionality
 
Thomas Thevis
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

thanks for your answers. I think, I'll stick with a simple solution as well.
@Roman: Is this case-insensitive search something requested in your assignment? If not, don't you think that this is kind of risky in case your database access class is tested automatically?

Regards,
Thomas
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My assignment has no case specific requirements, as far as I know non of the assignments actually have anything like that. I don't think it is risky to do something specific unless you are asked not to do that, so even if some automated testing software fails because of this (which I highly doubt) it would not fail my assignment, most likely they would not even subtract points for this ... at least hope they would not, but really, this is not what I care much about
 
Thomas Thevis
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Thanks.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic