I have the following data structure for the entity relationships:
Map<Integer, Map<Integer, Map<PAXType, BigDecimal>>>
Entity Relationships:
- 1
Package(P) has ManyVariants(V) - 1
Variants(V) has ManyPricedata-points Priceis based on thePAXType(which is an enum: Adult, Child, Infant)
I modelled this using:
Map<Package, Map<Variant, Map<PAXType, BigDecimal>>>
for the purpose of quick price lookup based on
- package
- package variant
The way I’m using this right now is:
As I read data from the db, I create/update the above map. After I get all the info, for each variant, I need to transform the price map, from Map<PAXType, BigDecimal> to Map<OccupancyType, BigDecimal>, where OccupancyType is another enum. This is the final price format which I need to output for serialization etc.
Is there any data structure in guava which would be a good fit for the ugly map construct I have and support the operations I suggested above ?
In addition to Tomasz’s answer suggesting encapsulating
Map<PAXType, BigDecimal>in classPriceByType(note that ifPAXTypeis an enum, you should use EnumMap) I think you should consider using Guava’s Table as substitution forMap<Integer, Map<Integer, PriceByType>>. Table use case:Your indexes are package and package variant, both Integers, so table should end up with
Table<Integer, Integer, PriceByType>.