File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 19649
    
  18

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
 
Similar Threads
Collections.sort() does not sort my ArrayList
SWT XML Sprite Sheet Utility
Using threads to access data from files
An array name can be changed inside a for statement?
best way to iterate a generic list