• 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

The best option for paired data, which has duplicate keys

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am interested in using the right container for a group of paired values, I am unsure what to use. I understand anything which may have a non unique key, it would be wise to stay away from HashMap etc.

The data is in a structure like this, and its way of structuring tracking tags on sites, some are just page source based, and some only appear after an event, so event based:

page based:
homepage; canonical
registration; canonical
faq; DF3768-U
homepage; GA-UFSHS1

event based:
signup; doubleclick
sentmaill; GA-UUA51

Initially I thought of having a two dimensional array, one to store the event based and one to store the page static based. But as the size cannot change, I was unsure.

I plan to iterate over an array dependent on its given event or page basis, drill down on the values that match a page type, say homepage, and scan through all the values for the homepage until it is matched.

I have been reading here, but is there any easy way to do this?

http://stackoverflow.com/questions/1062960/map-implementation-with-duplicate-keys


 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the Guava and Apache versions aren’t suitable for your purposes (they probably are), you can have a Map<Foo, List<Bar>>

Find the Map section in the Java Tutorials, and it has an example about counting words in. Now, instead of incrementing the count, you can insert a List and populate it with your Bar object. Later on, if you encounter the same List, you can add to it.
That is probably how the multi‑map works. When it says it is not a Map, that means it does not return one V if you use the get() method. That sort of thing is probably your best bet. There is something similar in Apache Commons, but the Guava version seems more versatile.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic