aspose file tools*
The moose likes Java in General and the fly likes Design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Design question" Watch "Design question" New topic
Author

Design question

Wesley Baker
Ranch Hand

Joined: Aug 20, 2008
Posts: 45
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

Joined: Jan 17, 2006
Posts: 1296
What about a list of Record objects?



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Wesley Baker
Ranch Hand

Joined: Aug 20, 2008
Posts: 45
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

Joined: Oct 27, 2005
Posts: 19785
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design question