I was wondering if there exists any Map<K, V>
implementation that takes a combination of 2 or more enums for its key.
I'll provide a simplified example.
Say I have two enums DiceEyes
and CardSuit
:
public enum DiceEyes {
ONE, TWO, THREE, FOUR, FIVE, SIX
}
public enum CardSuit {
HEARTS, DIAMONDS, SPADES, CLUBS
}
Now I have 6 * 4 = 24 images from which I would like to show exactly one, based on what a user selected in a GUI - he selects a DiceEyes
and a CardSuit
.
I have no control over the filenames of the images. So I cannot be smart by naming the images <DiceType>-<CardSuit>-.png
or whatsoever. Therefore I need a mapping of the combination of a DiceType
and a CardSuit
to the filename.
I have already thought about a solution that operates on an EnumMap
of EnumMap
s:
EnumMap<DiceType, EnumMap<CardSuit, String>> ... = new ...;
But that looks overcomplicated to me. A colleague would then think that DiceType
is more or less important than a CardSuit
, looking at the order of the types.
Introducing a wrapper class for just this purpose also seems like overkill to me. When I have to use it in a Map
, I would need to implement equals()
and hashCode()
which for this purpose seems just too much. With an enum you are already guaranteed of object equality, so I would like to stay with the enums.
How can this be achieved without introducing a specific class or too much overhead?