I need a map that has two keys, e.g.
Map2 _employees;
So that I can
_empl
I imagine the main key would be empId
, so I would build a Map
with that as the key, i.e. empId
---> Employee
. All other unique attributes (e.g. ssn
) would be treated as secondary and will use separate Map
s as a lookup table for empId
(e.g. ssn
---> empId
).
This implementation makes it easy to add/remove employees, since you only need to change one Map
, i.e. empId
---> Employee
; the other Map
s can be rebuilt only when needed.
The Spiffy Framework appears to provide exactly what you`re looking for. From the Javadocs:
A two-dimensional hashmap, is a HashMap that enables you to refer to values via two keys rather than one
The relevant class is TwoDHashMap. It also provides a ThreeDHashMap.
My first thought was: the easiest way to do this, I think, would be two maps.
Map< String, Map< String,Employee> > _employees;
But from what it looks like, you just want to be able to look up an employee by either SSN or ID. What's to stop you then from making two maps, or at worst a class that contains two maps?
As a clarification, are you looking for a compound key being employees are uniquely identified by the combination of their SSN and ID, but not either one by itself, or are you looking for two different ways of referencing an employee?