• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design question

 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a log file that contains records of activity, and the application parses the record into sections like date, time, filename, duration, etc.

My question is about organizing the data. Would it be better to create a List of Maps, or a Map of Lists? Is there a significant performance difference?

I am thinking a List of Maps, and have each map contain a key for each of the parsed sections of the record. e.g.

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about a list of Record objects?

 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had originally not gone that route because I didn't want to just duplicate a Map with a predefined list of keys, which is all the Record class would be in this instance. I probably should do it though, as a matter of good OO practice.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Map of Lists would be a bad idea because it separates all the values that obviously belong together. It would be a lot harder to find all values for one record. Besides, there is no guarantee that the Lists all have the same length - it's up to you to ensure that.
A List of Maps does not have that problem but it does allow for the absence of values for one record. I don't know if that is allowed or not.

I agree with Garrett that a List of Record would be best.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic