nekomata_saren@tg says to YSITD
for (Upgrade u: upgrades) { if (duplicateSet.contains(u)) throw new Exception("Duplicate"); duplicateSet.add(u); Integer maxLevelInt = typeMaxLevels.get(u.getType()); int maxLevel = maxLevelInt == null ? 0 : maxLevelInt; typeMaxLevels.put(u.getType(), Math.max(u.getLevel(), maxLevel)); Integer countInt = typeCounts.get(u.getType()); int count = countInt == null ? 0 : countInt; count++; typeCounts.put(u.getType(), count); }