mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Merge pull request #2760 from ingmargoudt/master
some rewrites to reference putIfAbsent
This commit is contained in:
commit
17dbd996d2
6 changed files with 17 additions and 30 deletions
|
@ -230,9 +230,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
Map<String, Card> cards = new HashMap<>();
|
||||
for (UUID cardId : this) {
|
||||
Card card = game.getCard(cardId);
|
||||
if (!cards.containsKey(card.getName())) {
|
||||
cards.put(card.getName(), card);
|
||||
}
|
||||
cards.putIfAbsent(card.getName(), card);
|
||||
}
|
||||
return cards.values();
|
||||
}
|
||||
|
|
|
@ -35,15 +35,15 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Counters extends HashMap<String, Counter> implements Serializable {
|
||||
|
||||
public Counters() {}
|
||||
public Counters() {
|
||||
}
|
||||
|
||||
public Counters(final Counters counters) {
|
||||
for (Map.Entry<String, Counter> entry: counters.entrySet()) {
|
||||
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
|
||||
this.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
}
|
||||
|
@ -53,16 +53,12 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
|||
}
|
||||
|
||||
public void addCounter(String name) {
|
||||
if (!this.containsKey(name)) {
|
||||
this.put(name, new Counter(name));
|
||||
}
|
||||
putIfAbsent(name, new Counter(name));
|
||||
this.get(name).increase();
|
||||
}
|
||||
|
||||
public void addCounter(String name, int amount) {
|
||||
if (!this.containsKey(name)) {
|
||||
this.put(name, new Counter(name));
|
||||
}
|
||||
putIfAbsent(name, new Counter(name));
|
||||
this.get(name).add(amount);
|
||||
}
|
||||
|
||||
|
@ -100,13 +96,14 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void removeAllCounters(CounterType counterType){
|
||||
public void removeAllCounters(CounterType counterType) {
|
||||
removeAllCounters(counterType.getName());
|
||||
}
|
||||
|
||||
public void removeAllCounters(String name){
|
||||
if (this.containsKey(name)){
|
||||
public void removeAllCounters(String name) {
|
||||
if (this.containsKey(name)) {
|
||||
this.remove(name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,9 +127,9 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
|||
|
||||
public List<BoostCounter> getBoostCounters() {
|
||||
List<BoostCounter> boosters = new ArrayList<>();
|
||||
for (Counter counter: this.values()) {
|
||||
for (Counter counter : this.values()) {
|
||||
if (counter instanceof BoostCounter) {
|
||||
boosters.add((BoostCounter)counter);
|
||||
boosters.add((BoostCounter) counter);
|
||||
}
|
||||
}
|
||||
return boosters;
|
||||
|
|
|
@ -64,9 +64,7 @@ public class LookedAt extends HashMap<String, Cards> implements Serializable, Co
|
|||
}
|
||||
|
||||
public Cards createLookedAt(String name) {
|
||||
if (!this.containsKey(name)) {
|
||||
this.put(name, new CardsImpl());
|
||||
}
|
||||
putIfAbsent(name, new CardsImpl());
|
||||
return this.get(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -208,9 +208,7 @@ public class Library implements Serializable {
|
|||
Map<String, Card> cards = new HashMap<>();
|
||||
for (UUID cardId : library) {
|
||||
Card card = game.getCard(cardId);
|
||||
if (!cards.containsKey(card.getName())) {
|
||||
cards.put(card.getName(), card);
|
||||
}
|
||||
cards.putIfAbsent(card.getName(), card);
|
||||
}
|
||||
return cards.values();
|
||||
}
|
||||
|
|
|
@ -2748,9 +2748,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getUseableActivatedAbilities(permanent, Zone.BATTLEFIELD, game);
|
||||
for (ActivatedAbility ability : useableAbilities.values()) {
|
||||
if (!playableActivated.containsKey(ability.toString())) {
|
||||
playableActivated.put(ability.toString(), ability);
|
||||
}
|
||||
playableActivated.putIfAbsent(ability.toString(), ability);
|
||||
}
|
||||
}
|
||||
// activated abilities from stack objects
|
||||
|
|
|
@ -50,9 +50,7 @@ public class Watchers extends HashMap<String, Watcher> {
|
|||
}
|
||||
|
||||
public void add(Watcher watcher) {
|
||||
if (!this.containsKey(watcher.getKey())) {
|
||||
this.put(watcher.getKey(), watcher);
|
||||
}
|
||||
putIfAbsent(watcher.getKey(), watcher);
|
||||
}
|
||||
|
||||
public void watch(GameEvent event, Game game) {
|
||||
|
|
Loading…
Reference in a new issue