I’m using google guava 12 and have a map:
Map<OccupancyType, BigDecimal> roomPrice;
I have a Set:
Set<OccupancyType> policy;
How can I filter entries in the roomPrice map based on policy and return the filtered map ?
filteredMap needs to have all the values from policy. In case, roomPrice map doesnt have an entry from policy, I’d like to input default value instead.
Since you have a Set of keys you should use Maps.filterkeys(), also Guava provides a pretty good set of predicates that you can use out of the box. In your case something like Predicates.in() should work.
So basically you end up with:
Hope it helps.