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

Design question

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about a list of Record objects?

 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic