-1

Updated:-

Problem Statement is-

I need to store these things-

For ID corresponding to 1, I need to Store these things

 - Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

For ID corresponding to 2, I need to Store these things

- Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

For ID corresponding to 3, I need to Store these things

- Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

So for this problem I was thinking to make data structure like this-

public static LinkedHashMap<String, Integer> GUID_VALUES = new LinkedHashMap<String, Integer>();

public static LinkedHashMap<Integer, LinkedHashMap<String, Integer>> GUID_ID_MAPPING = new LinkedHashMap<Integer, LinkedHashMap<String, Integer>>();

Is there any better way to do than this?

AKIWEB
  • 19,008
  • 67
  • 180
  • 294

3 Answers3

2

It's not entirely clear what you're ultimately trying to store.

If you just want a map of maps:

LinkedHashMap<Integer, LinkedHashMap<String, Integer>>

But what's all that "etc etc etc" at the end? Are there multiple "children" IDs per parent ID? If so then you probably want some sort of tree (which could be implemented by maps, but an abstraction over that would seem reasonable.)

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
1

In Java, you could achieve that by using:

public class Data {
    public static LinkedHashMap<String, Integer> GUID_VALUES = new LinkedHashMap<String, Integer>();
    public static LinkedHashMap<Integer, Map<String, Integer>> GUID_ID_MAPPING = new LinkedHashMap<Integer, Map<String, Integer>>();

    static {
        Integer someNumber = 0; //or another value, its for initialize the key
        GUID_ID_MAPPING.put(someNumber,GUID_VALUES);
    }
}

Still, I don't understand why you really need this. I'll suggest you to post your functional requirement and try to choose a better design to solve the problem.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
0

You probably want a multi key map, as the one available in Apache Commons Collections:

http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/MultiKeyMap.html

Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76
  • Hmm, not sure--not clear from the question, but it looks more like a single key, with nested maps--more like a tree. – Dave Newton May 28 '12 at 21:51