mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Updated codes
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package forge.ai;
|
||||
/**
|
||||
* Refactoring this class to use List sort (Instead of Collection) causes Android build not to compile...
|
||||
* */
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.*;
|
||||
@@ -130,7 +128,7 @@ public class ComputerUtilMana {
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(orderedCards, new Comparator<Card>() {
|
||||
orderedCards.sort(new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(final Card card1, final Card card2) {
|
||||
return Integer.compare(manaCardMap.get(card1), manaCardMap.get(card2));
|
||||
@@ -153,7 +151,7 @@ public class ComputerUtilMana {
|
||||
System.out.println("Unsorted Abilities: " + newAbilities);
|
||||
}
|
||||
|
||||
Collections.sort(newAbilities, new Comparator<SpellAbility>() {
|
||||
newAbilities.sort(new Comparator<SpellAbility>() {
|
||||
@Override
|
||||
public int compare(final SpellAbility ability1, final SpellAbility ability2) {
|
||||
int preOrder = orderedCards.indexOf(ability1.getHostCard()) - orderedCards.indexOf(ability2.getHostCard());
|
||||
@@ -172,8 +170,7 @@ public class ComputerUtilMana {
|
||||
}
|
||||
|
||||
return ability1.compareTo(ability2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return preOrder;
|
||||
}
|
||||
}
|
||||
@@ -346,6 +343,10 @@ public class ComputerUtilMana {
|
||||
payMultipleMana(cost, manaProduced, ai);
|
||||
|
||||
// remove from available lists
|
||||
/*
|
||||
* Refactoring this code to sourcesForShards.values().removeIf((SpellAbility srcSa) -> srcSa.getHostCard().equals(saPayment.getHostCard()));
|
||||
* causes Android build not to compile
|
||||
* */
|
||||
Iterator<SpellAbility> itSa = sourcesForShards.values().iterator();
|
||||
while (itSa.hasNext()) {
|
||||
SpellAbility srcSa = itSa.next();
|
||||
@@ -489,6 +490,10 @@ public class ComputerUtilMana {
|
||||
payMultipleMana(cost, manaProduced, ai);
|
||||
|
||||
// remove from available lists
|
||||
/*
|
||||
* Refactoring this code to sourcesForShards.values().removeIf((SpellAbility srcSa) -> srcSa.getHostCard().equals(saPayment.getHostCard()));
|
||||
* causes Android build not to compile
|
||||
* */
|
||||
Iterator<SpellAbility> itSa = sourcesForShards.values().iterator();
|
||||
while (itSa.hasNext()) {
|
||||
SpellAbility srcSa = itSa.next();
|
||||
@@ -519,6 +524,10 @@ public class ComputerUtilMana {
|
||||
|
||||
if (hasConverge) { // hack to prevent converge re-using sources
|
||||
// remove from available lists
|
||||
/*
|
||||
* Refactoring this code to sourcesForShards.values().removeIf((SpellAbility srcSa) -> srcSa.getHostCard().equals(saPayment.getHostCard()));
|
||||
* causes Android build not to compile
|
||||
* */
|
||||
Iterator<SpellAbility> itSa = sourcesForShards.values().iterator();
|
||||
while (itSa.hasNext()) {
|
||||
SpellAbility srcSa = itSa.next();
|
||||
|
||||
@@ -547,7 +547,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;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class Game {
|
||||
if (c == null) {
|
||||
return null;
|
||||
}
|
||||
return changeZoneLKIInfo.containsKey(c.getId()) ? changeZoneLKIInfo.get(c.getId()) : c;
|
||||
return changeZoneLKIInfo.getOrDefault(c.getId(), c);
|
||||
}
|
||||
public final void clearChangeZoneLKIInfo() {
|
||||
changeZoneLKIInfo.clear();
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game;
|
||||
/**
|
||||
* Refactoring this class to use List sort (Instead of Collection) causes Android build not to compile...
|
||||
* */
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.*;
|
||||
import forge.GameCommand;
|
||||
@@ -826,7 +824,7 @@ public class GameAction {
|
||||
.result();
|
||||
}
|
||||
};
|
||||
Collections.sort(staticAbilities, comp);
|
||||
staticAbilities.sort(comp);
|
||||
|
||||
final Map<StaticAbility, CardCollectionView> affectedPerAbility = Maps.newHashMap();
|
||||
for (final StaticAbilityLayer layer : StaticAbilityLayer.CONTINUOUS_LAYERS) {
|
||||
|
||||
@@ -136,13 +136,13 @@ public class GameLogFormatter extends IGameEventVisitor.Base<GameLogEntry> {
|
||||
for (final GameOutcome game : gamesPlayed) {
|
||||
RegisteredPlayer player = game.getWinningPlayer();
|
||||
|
||||
int amount = winCount.containsKey(player) ? winCount.get(player) : 0;
|
||||
int amount = winCount.getOrDefault(player, 0);
|
||||
winCount.put(player, amount + 1);
|
||||
}
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (Entry<RegisteredPlayer, String> entry : players.entrySet()) {
|
||||
int amount = winCount.containsKey(entry.getKey()) ? winCount.get(entry.getKey()) : 0;
|
||||
int amount = winCount.getOrDefault(entry.getKey(), 0);
|
||||
|
||||
sb.append(entry.getValue()).append(": ").append(amount).append(" ");
|
||||
}
|
||||
|
||||
@@ -311,8 +311,8 @@ public final class AbilityFactory {
|
||||
}
|
||||
|
||||
private static final TargetRestrictions readTarget(Map<String, String> mapParams) {
|
||||
final String min = mapParams.containsKey("TargetMin") ? mapParams.get("TargetMin") : "1";
|
||||
final String max = mapParams.containsKey("TargetMax") ? mapParams.get("TargetMax") : "1";
|
||||
final String min = mapParams.getOrDefault("TargetMin", "1");
|
||||
final String max = mapParams.getOrDefault("TargetMax", "1");
|
||||
|
||||
|
||||
// TgtPrompt now optional
|
||||
|
||||
@@ -1330,7 +1330,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
int counterAmount = 0;
|
||||
if (countersAddedBy.containsKey(source)) {
|
||||
final Map<CounterType, Integer> counterMap = countersAddedBy.get(source);
|
||||
counterAmount = counterMap.containsKey(counterType) ? counterMap.get(counterType) : 0;
|
||||
counterAmount = counterMap.getOrDefault(counterType, 0);
|
||||
countersAddedBy.remove(source);
|
||||
}
|
||||
return counterAmount;
|
||||
@@ -6189,7 +6189,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return numberTurnActivations.containsKey(original) ? numberTurnActivations.get(original) : 0;
|
||||
return numberTurnActivations.getOrDefault(original, 0);
|
||||
}
|
||||
|
||||
public int getAbilityActivatedThisGame(SpellAbility ability) {
|
||||
@@ -6204,7 +6204,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return numberGameActivations.containsKey(original) ? numberGameActivations.get(original) : 0;
|
||||
return numberGameActivations.getOrDefault(original, 0);
|
||||
}
|
||||
|
||||
public void resetTurnActivations() {
|
||||
|
||||
@@ -449,11 +449,7 @@ public class CardState extends GameObject {
|
||||
return sVars;
|
||||
}
|
||||
public final String getSVar(final String var) {
|
||||
if (sVars.containsKey(var)) {
|
||||
return sVars.get(var);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
return sVars.getOrDefault(var, "");
|
||||
}
|
||||
public final boolean hasSVar(final String var) {
|
||||
if (var == null) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class CostAdjustment {
|
||||
return;
|
||||
}
|
||||
|
||||
final String scost = params.containsKey("Cost") ? params.get("Cost") : "1";
|
||||
final String scost = params.getOrDefault("Cost", "1");
|
||||
Cost part = new Cost(scost, sa.isAbility());
|
||||
int count = 0;
|
||||
|
||||
|
||||
@@ -598,12 +598,12 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
view.updateCommanderDamage(this);
|
||||
}
|
||||
|
||||
int old = assignedDamage.containsKey(source) ? assignedDamage.get(source) : 0;
|
||||
int old = assignedDamage.getOrDefault(source, 0);
|
||||
assignedDamage.put(source, old + amount);
|
||||
source.getDamageHistory().registerDamage(this);
|
||||
|
||||
if (isCombat) {
|
||||
old = assignedCombatDamage.containsKey(source) ? assignedCombatDamage.get(source) : 0;
|
||||
old = assignedCombatDamage.getOrDefault(source, 0);
|
||||
assignedCombatDamage.put(source, old + amount);
|
||||
for (final String type : source.getType().getCreatureTypes()) {
|
||||
source.getController().addProwlType(type);
|
||||
|
||||
@@ -89,8 +89,8 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
public AbilityManaPart(final Card sourceCard, final Map<String, String> params) {
|
||||
this.sourceCard = sourceCard;
|
||||
|
||||
origProduced = params.containsKey("Produced") ? params.get("Produced") : "1";
|
||||
this.manaRestrictions = params.containsKey("RestrictValid") ? params.get("RestrictValid") : "";
|
||||
origProduced = params.getOrDefault("Produced", "1");
|
||||
this.manaRestrictions = params.getOrDefault("RestrictValid", "");
|
||||
this.cannotCounterSpell = params.get("AddsNoCounter");
|
||||
this.addsKeywords = params.get("AddsKeywords");
|
||||
this.addsKeywordsType = params.get("AddsKeywordsType");
|
||||
@@ -98,7 +98,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
this.addsCounters = params.get("AddsCounters");
|
||||
this.triggersWhenSpent = params.get("TriggersWhenSpent");
|
||||
this.persistentMana = (null != params.get("PersistentMana")) && "True".equalsIgnoreCase(params.get("PersistentMana"));
|
||||
this.manaReplaceType = params.containsKey("ManaReplaceType") ? params.get("ManaReplaceType") : "";
|
||||
this.manaReplaceType = params.getOrDefault("ManaReplaceType", "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,7 +81,7 @@ public class StaticAbilityCantBeCast {
|
||||
|
||||
if (params.containsKey("NumLimitEachTurn") && activator != null) {
|
||||
int limit = Integer.parseInt(params.get("NumLimitEachTurn"));
|
||||
String valid = params.containsKey("ValidCard") ? params.get("ValidCard") : "Card";
|
||||
String valid = params.getOrDefault("ValidCard", "Card");
|
||||
List<Card> thisTurnCast = CardUtil.getThisTurnCast(valid, card);
|
||||
if (CardLists.filterControlledBy(thisTurnCast, activator).size() < limit) {
|
||||
return false;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class StaticAbilityPreventDamage {
|
||||
|
||||
if (params.containsKey("Optional")) { //Assume if param is present it should be optional
|
||||
if (!isTest) {
|
||||
final String logic = params.containsKey("AILogic") ? params.get("AILogic") : "";
|
||||
final String logic = params.getOrDefault("AILogic", "");
|
||||
final String message = "Apply the effect of " + hostCard + "? (Affected: " + target + ")";
|
||||
boolean confirmed = hostCard.getController().getController().confirmStaticApplication(hostCard, target, logic, message);
|
||||
|
||||
|
||||
@@ -446,7 +446,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
|
||||
@@ -618,7 +618,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
|
||||
|
||||
@@ -857,11 +857,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<ItemFilter<? extends T>>();
|
||||
this.filters.put(filterClass, classFilters);
|
||||
}
|
||||
List<ItemFilter<? extends T>> classFilters = this.filters.computeIfAbsent(filterClass, k -> new ArrayList<ItemFilter<? extends T>>());
|
||||
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
|
||||
|
||||
@@ -36,7 +36,7 @@ class AsyncSoundRegistry {
|
||||
}
|
||||
|
||||
public synchronized static int getNumIterations(String soundName) {
|
||||
return soundsPlayed.containsKey(soundName) ? soundsPlayed.get(soundName) : 0;
|
||||
return soundsPlayed.getOrDefault(soundName, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -294,11 +294,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;
|
||||
|
||||
@@ -518,11 +514,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;
|
||||
|
||||
@@ -949,11 +941,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;
|
||||
|
||||
|
||||
@@ -89,6 +89,10 @@ public class QuestPetStorage {
|
||||
*/
|
||||
private void addToMap(final QuestPetController petCtrl) {
|
||||
final int iSlot = petCtrl.getSlot();
|
||||
/*
|
||||
* 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(Integer.valueOf(iSlot));
|
||||
if (null == list) {
|
||||
list = new ArrayList<QuestPetController>();
|
||||
|
||||
Reference in New Issue
Block a user