foul-magics/Mage/src/main/java/mage/game/LookedAt.java
Susucre f75b1c9f0a
Code cleanup: protect all copy constructors (#10750)
* apply regex to change public copy constructors to protected
* cleanup code using now protected constructors
* fix manaBuilder weird casting of Mana into ConditionalMana
2023-08-04 19:34:58 -04:00

61 lines
1.3 KiB
Java

package mage.game;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.util.Copyable;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author nantuko
*/
public class LookedAt extends HashMap<String, Cards> implements Serializable, Copyable<LookedAt> {
public LookedAt() {
}
protected LookedAt(final LookedAt lookedAt) {
for (Map.Entry<String, Cards> entry : lookedAt.entrySet()) {
this.put(entry.getKey(), entry.getValue().copy());
}
}
public void add(String name, Card card) {
this.createLookedAt(name).add(card);
}
public void add(String name, Cards cards) {
if (!this.containsKey(name)) {
createLookedAt(name);
}
this.put(name, cards.copy());
}
public Cards createLookedAt(String name) {
putIfAbsent(name, new CardsImpl());
return this.get(name);
}
public void reset() {
this.clear();
}
public Card getCard(UUID cardId, Game game) {
for (Cards cards : this.values()) {
if (cards.contains(cardId))
return game.getCard(cardId);
}
return null;
}
@Override
public LookedAt copy() {
return new LookedAt(this);
}
}