I am using multi key bags in order to count occurrences of certain combinations of values and I was wondering if there is an elegant way to convert these bags into nested SortedMaps like TreeMaps. The number of nested TreeMaps being equal to the number of components in the multi key. For instance, let's say I have a multi key bag which has a defined key:
multiKey = new String[]{"age", "height", "gender"}
thus, the object I would like to obtain from it would be:
TreeMap<Integer, TreeMap<Integer, TreeMap<Integer, Integer>>>
and populate it with the values from the multi key bag. So, the nested structure would contain the values from the multi key like this:
TreeMap<"age", TreeMap<"height", TreeMap<"gender", count>>>
where "age" is replaced by the corresponding value from the bag, "height" as well and so on.. count is the number of occurrences of that particular combination (which is returned by the multi key bag itself).
Of course, the number of components of the multi key is dynamic. If the multiKey would have only two components, then the resulting object would be:
TreeMap<Integer<TreeMap<Integer, Integer>>
Retrieving the values from the bag and populating the (nested) TreeMaps does not represent an issue. Only the conversion. Any help is appreciated.