My question is rather a design question. In my program I got to a data structure that looks something like this:
private ConcurrentHashMap<A, ConcurrentHashMap<B, ConcurrentHashMap<Integer, C>>> services = new ConcurrentHashMap<A, ConcurrentHashMap<B, ConcurrentHashMap<Integer, C>>>();
Is there a way to handle such a data structure more elegantly?
Thanks!
edit: A, B and C are business classes. An A instance "can have" (as association) many Bs and a B "can have" many mappings Integer-C.
Best Answer
Create a class
Triple
with fields forA
,B
,Integer
, overridehashCode()
andequals()
, and useMap<Triple,C>
instead ofMap<A,Map<B,Map<Integer,C>>>
In this approach - you put all elements in one map, with a larger possible range of keys.