• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap/Vector Design question  RSS feed

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have some scans that I woudl like to represent as a HashMap to another object.

There are certain types of scans and more than one type can be associated with an object. Also an object can have multiple types of the same scan.

I came up with this approach...

Create a HashMap in which the key is the scan type. The value is a Vector, which will hold all the scans of the same types performed on that object.

That work's, but then I got lazy... I am pulling the scans out of a Databse. SO I will have to use something liek an ORDER BY and then check for when that condition changes, so that I can add scans to the rigth Vector.

Am I taking the right approach, or do you think there is a better approach?
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothign wrong with your approach. However, I have found that ORDER BYs can occassinally be quite expensive in the database and it is often easier to sort things in memory. Even at that, I usually don't actually sort the records before processing them. The following pseudo-code divide them into their appropriate lists:


As a side note, you're using HashMap instead of Hashtable, so why use Vector instead ArrayList? There is really no reason to continue using Vectors (unless you are trying to work with legacy code that you can't change), use Array List instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!