mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Cleanup - Map.getOrDefault and Map.computeIfAbsent
This commit is contained in:
@@ -15,11 +15,7 @@ public class FTrace {
|
||||
}
|
||||
|
||||
public static FTrace get(String name0) {
|
||||
FTrace trace = traces.get(name0);
|
||||
if (trace == null) {
|
||||
trace = new FTrace(name0);
|
||||
traces.put(name0, trace);
|
||||
}
|
||||
FTrace trace = traces.computeIfAbsent(name0, FTrace::new);
|
||||
return trace;
|
||||
}
|
||||
|
||||
|
||||
@@ -655,7 +655,7 @@ public abstract class CardTraitBase extends GameObject implements IHasCardView,
|
||||
Map<String, String> result = Maps.newHashMap(output);
|
||||
for (Map.Entry<String, String> e : input.entrySet()) {
|
||||
String value = e.getValue();
|
||||
result.put(e.getKey(), output.containsKey(value) ? output.get(value) : value);
|
||||
result.put(e.getKey(), output.getOrDefault(value, value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
|
||||
}
|
||||
Map<CounterType, Integer> alreadyRemoved = column(ge).get(Optional.absent());
|
||||
for (Map.Entry<CounterType, Integer> e : ge.getCounters().entrySet()) {
|
||||
int rest = e.getValue() - (alreadyRemoved.containsKey(e.getKey()) ? alreadyRemoved.get(e.getKey()) : 0);
|
||||
int rest = e.getValue() - (alreadyRemoved.getOrDefault(e.getKey(), 0));
|
||||
if (rest > 0) {
|
||||
result.put(e.getKey(), rest);
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
if (cnum > 0) {
|
||||
src.subtractCounter(cType, cnum, activator);
|
||||
game.updateLastStateForCard(src);
|
||||
countersToAdd.put(cType, (countersToAdd.containsKey(cType) ? countersToAdd.get(cType) : 0) + cnum);
|
||||
countersToAdd.put(cType, (countersToAdd.getOrDefault(cType, 0)) + cnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7950,26 +7950,14 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<String> result = chosenModesTurn.get(original);
|
||||
if (result == null) {
|
||||
result = Lists.newArrayList();
|
||||
chosenModesTurn.put(original, result);
|
||||
}
|
||||
List<String> result = chosenModesTurn.computeIfAbsent(original, k -> Lists.newArrayList());
|
||||
result.add(mode);
|
||||
|
||||
result = chosenModesGame.get(original);
|
||||
if (result == null) {
|
||||
result = Lists.newArrayList();
|
||||
chosenModesGame.put(original, result);
|
||||
}
|
||||
result = chosenModesGame.computeIfAbsent(original, k -> Lists.newArrayList());
|
||||
result.add(mode);
|
||||
|
||||
if (yourCombat) {
|
||||
result = chosenModesYourCombat.get(original);
|
||||
if (result == null) {
|
||||
result = Lists.newArrayList();
|
||||
chosenModesYourCombat.put(original, result);
|
||||
}
|
||||
result = chosenModesYourCombat.computeIfAbsent(original, k -> Lists.newArrayList());
|
||||
result.add(mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,11 +263,7 @@ public class ManaCostBeingPaid {
|
||||
private void increaseShard(final ManaCostShard shard, final int toAdd, final boolean forX) {
|
||||
if (toAdd <= 0) { return; }
|
||||
|
||||
ShardCount sc = unpaidShards.get(shard);
|
||||
if (sc == null) {
|
||||
sc = new ShardCount();
|
||||
unpaidShards.put(shard, sc);
|
||||
}
|
||||
ShardCount sc = unpaidShards.computeIfAbsent(shard, k -> new ShardCount());
|
||||
if (forX) {
|
||||
sc.xCount += toAdd;
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ public class ImportSourceAnalyzer {
|
||||
analyzeListedDir(root, ForgeConstants.CACHE_ICON_PICS_DIR, new ListedAnalyzer() {
|
||||
@Override
|
||||
public String map(final String filename) {
|
||||
return iconFileNames.containsKey(filename) ? iconFileNames.get(filename) : null;
|
||||
return iconFileNames.getOrDefault(filename, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -617,7 +617,7 @@ public class ImportSourceAnalyzer {
|
||||
analyzeListedDir(root, targetDir, new ListedAnalyzer() {
|
||||
@Override
|
||||
public String map(final String filename) {
|
||||
return fileDb.containsKey(filename) ? fileDb.get(filename) : null;
|
||||
return fileDb.getOrDefault(filename, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -826,11 +826,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel implem
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addFilter(final ItemFilter<? extends T> filter) {
|
||||
final Class<? extends ItemFilter<? extends T>> filterClass = (Class<? extends ItemFilter<? extends T>>) filter.getClass();
|
||||
List<ItemFilter<? extends T>> classFilters = this.filters.get(filterClass);
|
||||
if (classFilters == null) {
|
||||
classFilters = new ArrayList<>();
|
||||
this.filters.put(filterClass, classFilters);
|
||||
}
|
||||
List<ItemFilter<? extends T>> classFilters = this.filters.computeIfAbsent(filterClass, k -> new ArrayList<>());
|
||||
if (classFilters.size() > 0) {
|
||||
//if filter with the same class already exists, try to merge if allowed
|
||||
//NOTE: can always use first filter for these checks since if
|
||||
|
||||
@@ -44,7 +44,7 @@ class AsyncSoundRegistry {
|
||||
}
|
||||
|
||||
public synchronized static int getNumIterations(String soundName) {
|
||||
return soundsPlayed.containsKey(soundName) ? soundsPlayed.get(soundName) : 0;
|
||||
return soundsPlayed.getOrDefault(soundName, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -940,11 +940,7 @@ public class FSkin {
|
||||
|
||||
/** @return {@link java.awt.font} */
|
||||
private static Font getFixedFont(final int size) {
|
||||
Font fixedFont = fixedFonts.get(size);
|
||||
if (fixedFont == null) {
|
||||
fixedFont = new Font("Monospaced", Font.PLAIN, size);
|
||||
fixedFonts.put(size, fixedFont);
|
||||
}
|
||||
Font fixedFont = fixedFonts.computeIfAbsent(size, s -> new Font("Monospaced", Font.PLAIN, s));
|
||||
return fixedFont;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class PointOfInterestChanges implements SaveFileContent {
|
||||
|
||||
public void addObjectReputation(int id, int delta)
|
||||
{
|
||||
reputation.put(id, (reputation.containsKey(id)?reputation.get(id):0) + delta);
|
||||
reputation.put(id, (reputation.getOrDefault(id, 0)) + delta);
|
||||
}
|
||||
|
||||
public int getMapReputation(){
|
||||
|
||||
@@ -119,11 +119,7 @@ public class DeckPreferences {
|
||||
|
||||
public static DeckPreferences getPrefs(DeckProxy deck) {
|
||||
String key = deck.getUniqueKey();
|
||||
DeckPreferences prefs = allPrefs.get(key);
|
||||
if (prefs == null) {
|
||||
prefs = new DeckPreferences();
|
||||
allPrefs.put(key, prefs);
|
||||
}
|
||||
DeckPreferences prefs = allPrefs.computeIfAbsent(key, k -> new DeckPreferences());
|
||||
return prefs;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,11 +300,7 @@ public class QuestEventDraft implements IQuestEvent {
|
||||
int value;
|
||||
final String boosterName = FModel.getMagicDb().getEditions().get(boosterSet).getName() + " Booster Pack";
|
||||
|
||||
if (MAP_PRICES.containsKey(boosterName)) {
|
||||
value = MAP_PRICES.get(boosterName);
|
||||
} else {
|
||||
value = 395;
|
||||
}
|
||||
value = MAP_PRICES.getOrDefault(boosterName, 395);
|
||||
|
||||
boosterPrices += value;
|
||||
}
|
||||
@@ -529,11 +525,7 @@ public class QuestEventDraft implements IQuestEvent {
|
||||
|
||||
final String boosterName = booster.getName();
|
||||
|
||||
if (MAP_PRICES.containsKey(boosterName)) {
|
||||
value = MAP_PRICES.get(boosterName);
|
||||
} else {
|
||||
value = 395;
|
||||
}
|
||||
value = MAP_PRICES.getOrDefault(boosterName, 395);
|
||||
|
||||
return value;
|
||||
|
||||
@@ -961,11 +953,7 @@ public class QuestEventDraft implements IQuestEvent {
|
||||
int value;
|
||||
final String boosterName = FModel.getMagicDb().getEditions().get(boosterSet).getName() + " Booster Pack";
|
||||
|
||||
if (MAP_PRICES.containsKey(boosterName)) {
|
||||
value = MAP_PRICES.get(boosterName);
|
||||
} else {
|
||||
value = 395;
|
||||
}
|
||||
value = MAP_PRICES.getOrDefault(boosterName, 395);
|
||||
|
||||
entryFee += value;
|
||||
|
||||
|
||||
@@ -92,11 +92,7 @@ public class QuestPetStorage {
|
||||
* Refactoring this to List<QuestPetController> list = this.petsBySlot.computeIfAbsent(Integer.valueOf(iSlot), k -> new ArrayList<QuestPetController>());
|
||||
* will cause Android not to compile
|
||||
* */
|
||||
List<QuestPetController> list = this.petsBySlot.get(iSlot);
|
||||
if (null == list) {
|
||||
list = new ArrayList<>();
|
||||
this.petsBySlot.put(iSlot, list);
|
||||
}
|
||||
List<QuestPetController> list = this.petsBySlot.computeIfAbsent(iSlot, k -> new ArrayList<>());
|
||||
this.petsByName.put(petCtrl.getName(), petCtrl);
|
||||
list.add(petCtrl);
|
||||
}
|
||||
|
||||
@@ -157,11 +157,8 @@ public class QuestAssets {
|
||||
* @param level int
|
||||
*/
|
||||
public final void setPetLevel(final String name, final int level) {
|
||||
QuestItemCondition cond = this.combatPets.get(name);
|
||||
if (null == cond) {
|
||||
cond = new QuestItemCondition(); // pets have only level that should be serialized for now
|
||||
this.combatPets.put(name, cond);
|
||||
}
|
||||
QuestItemCondition cond = this.combatPets.computeIfAbsent(name, k -> new QuestItemCondition());
|
||||
// pets have only level that should be serialized for now
|
||||
cond.setLevel(level);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,7 @@ public class CardPreferences {
|
||||
|
||||
public static CardPreferences getPrefs(IPaperCard card) {
|
||||
String cardName = card.getName();
|
||||
CardPreferences prefs = allPrefs.get(cardName);
|
||||
if (prefs == null) {
|
||||
prefs = new CardPreferences(cardName);
|
||||
allPrefs.put(cardName, prefs);
|
||||
}
|
||||
CardPreferences prefs = allPrefs.computeIfAbsent(cardName, CardPreferences::new);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user