package at.reisinger; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; /** * Verwaltet eine Liste vo at.reisinger.Cards */ @JsonAutoDetect public class Cards { @JsonDeserialize(as = ArrayList.class, contentAs = Card.class) private ArrayList cards; /** * Erstellt ein nues obj mit gegebenen Karten * @param cardsArrayList Die at.reisinger.Cards zum erstellen des Obj */ @JsonCreator public Cards(@JsonProperty("cards") ArrayList cardsArrayList) { this.cards = cardsArrayList; } /** * Fügt eine neue at.reisinger.Card hinzu * @param newCard neue at.reisinger.Card */ @JsonSetter public void addCard(Card newCard) { this.cards.add(newCard); } /** * Holt alle at.reisinger.Cards * @return Alle at.reisinger.Cards */ @JsonGetter public ArrayList getCards() { return this.cards; } /** * Löscht die gegebene at.reisinger.Card * @param delCard at.reisinger.Card zum löschen */ public void delCard(Card delCard) { this.cards.removeIf(obj -> obj.equals(delCard)); } /** * Prüft ob eine at.reisinger.Card in den at.reisinger.Cards vorhanden ist * @param toCeck at.reisinger.Card nach der in den at.reisinger.Cards gesucht werden soll * @return True wenn die at.reisinger.Card in den at.reisinger.Cards ist */ public boolean containsCard(Card toCeck){ AtomicBoolean returnval = new AtomicBoolean(false); this.cards.forEach(item -> { if(item.getElementTyp().equals(toCeck.getElementTyp()) && item.getCardType().equals(toCeck.getCardType()) && item.getName().equals(toCeck.getName()) && item.getDamage() == toCeck.getDamage()){ returnval.set(true); }else{ returnval.set(false); } }); return returnval.get(); } /** * Vergleicht 2 at.reisinger.Cards Obj miteinander * @param toCompare at.reisinger.Cards zum vergleichen * @return True wenn es aus den selben at.reisinger.Cards besteht */ public boolean equals(Cards toCompare){ if (this.cards == null && toCompare.getCards() == null){ return true; }else if ((this.cards == null && toCompare.getCards() != null) || (this.cards != null && toCompare.getCards() == null)){ return false; }else if(this.cards.containsAll(toCompare.getCards()) && toCompare.getCards().containsAll(this.cards)){ return true; }else { return false; } } }