Add documentation to Cards and CardsImpl (#9019)

* Added minor documentation and TODO questions

* Fixed typo

* Address one set of comments

* merge fix

* remove commented code

---------

Co-authored-by: xenohedron <xenohedron@users.noreply.github.com>
This commit is contained in:
Alex Vasile 2023-07-02 18:20:28 -04:00 committed by GitHub
parent af2d336045
commit 6b5d4abb69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 124 additions and 112 deletions

View file

@ -32,11 +32,11 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
}
public CardsImpl(List<? extends Card> cards) {
this.addAll(cards);
this.addAllCards(cards);
}
public CardsImpl(Set<? extends Card> cards) {
this.addAll(cards);
this.addAllCards(cards);
}
public CardsImpl(Collection<UUID> cardIds) {
@ -79,24 +79,20 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
return this.remove(card.getId());
}
@Override
public void setOwner(UUID ownerId, Game game) {
this.ownerId = ownerId;
for (UUID card : this) {
game.getCard(card).setOwnerId(ownerId);
}
}
@Override
public Card getRandom(Game game) {
if (this.isEmpty()) {
return null;
}
MageObject object = game.getObject(RandomUtil.randomFromCollection(this)); // neccessary if permanent tokens are in the collection
if (object instanceof Card) {
return (Card) object;
}
return null;
// neccessary if permanent tokens are in the collection
Set<MageObject> cardsForRandomPick = this
.stream().map(uuid -> game.getObject(uuid))
.filter(Objects::nonNull)
.filter(mageObject -> mageObject instanceof Card)
.collect(Collectors.toSet());
return (Card) RandomUtil.randomFromCollection(cardsForRandomPick);
}
@Override
@ -134,9 +130,14 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
return cards;
}
// TODO: Why is this used a completely different implementation than the version without the filter?
@Override
public Set<Card> getCards(FilterCard filter, Game game) {
return stream().map(game::getCard).filter(Objects::nonNull).filter(card -> filter.match(card, game)).collect(Collectors.toSet());
return stream()
.map(game::getCard)
.filter(Objects::nonNull)
.filter(card -> filter.match(card, game))
.collect(Collectors.toSet());
}
@Override
@ -176,17 +177,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
}
@Override
public void addAll(List<? extends Card> cards) {
if (cards != null) {
cards.stream()
.filter(Objects::nonNull)
.map(MageItem::getId)
.forEach(this::add);
}
}
@Override
public void addAll(Set<? extends Card> cards) {
public void addAllCards(Collection<? extends Card> cards) {
if (cards != null) {
cards.stream()
.filter(Objects::nonNull)
@ -197,13 +188,15 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
@Override
public Collection<Card> getUniqueCards(Game game) {
Map<String, Card> cards = new HashMap<>();
Map<String, Card> cards = new HashMap<>(this.size());
for (UUID cardId : this) {
Card card = game.getCard(cardId);
if (card != null) {
cards.putIfAbsent(card.getName(), card);
}
}
return cards.values();
}