equals
hashcode
OccupancyType
roomPrice
像这样的东西:
Map<OccupancyType, BigDecimal> filteredPrices = new HashMap<OccupancyType, BigDecimal>(); for(OccupancyType key : roomPrice.keySet()) { if(policy.contains(key) { filteredPrices.put(key, roomPrice.get(key)); } }
的 更新 强>
在Google Guava上阅读了一下之后,您应该可以执行以下操作:
Predicate<OccupancyType> priceFilter = new Predicate<OccupancyType>() { public boolean apply(OccupancyType i) { return policy.contains(i); } };
然后
return Maps.filterValues(roomPrice, priceFlter);
应该做的伎俩。
由于您有一组键,您应该使用 Maps.filterkeys() 另外,Guava提供了一组非常好的谓词,你可以开箱即用。在你的情况下像 Predicates.in() 应该管用。
所以基本上你最终得到:
Map<OccupancyType, BigDecimal> filteredMap = Maps.filterKeys(roomPrice, Predicates.in(policy));
希望能帮助到你。