我需要从多维哈希映射的内部哈希映射的整数值(AtomicInteger)进行查询。我需要知道LocalStore有什么游戏的库存。我有单独的inStock哈希映射。。。这是PasteBin上的代码。。。
请帮助我如何继续!
一个简单的解决方案是迭代inStock
映射。如果你没有成百上千的商店,性能会很好。
public static List<LocalStore> checkInStock(String gameTitle) {
return checkInStock(new Game(gameTitle));
}
public static List<LocalStore> checkInStock(Game g) {
List<LocalStores> stores = new ArrayList<LocalStores>();
for (Map.Entry<LocalStore, HashMap<Game, AtomicInteger>> entry : inStock.entrySet()) {
HashMap<Game, AtomicInteger> tmp = entry.getValue();
AtomicInteger anInt = tmp.get(g);
if (anInt != null && anInt.get() > 0) {
stores.add(entry.getKey());
}
}
return stores;
}