Interface CardList

All Superinterfaces:
Collection<Card>, Iterable<Card>, List<Card>, Serializable
All Known Implementing Classes:
CardArrayList, CardZone

public interface CardList extends Iterable<Card>, List<Card>, Serializable
An interface describing common actions for a collection of cards. This abstracts away the difference between an EntityZone, which enforces that its containing Entity objects can only be in one EntityZone at a time, versus a plain CardArrayList, which is just an array of cards that various pieces of logic might want to addCard(Card) to.

Use CardZone for the Spellsource.ZonesMessage.Zones.HAND, Spellsource.ZonesMessage.Zones.DECK and Spellsource.ZonesMessage.Zones.DISCOVER zones--when a card should only be in one place at a time. Use a CardArrayList for situations where you need to e.g., get a list of cards from an EntityFilter, shuffle them, and choose one from the top.

See Also:
  • Method Details

    • addCard

      CardList addCard(@NotNull @NotNull Card card)
      Adds the card fluently.
      Parameters:
      card - The card
      Returns:
      This instance.
    • addCard

      default CardList addCard(String cardId)
    • addAll

      CardList addAll(CardList cardList)
      Adds all the cards from the given list.
      Parameters:
      cardList - The cards to add.
      Returns:
      This instance.
    • clone

      CardList clone()
      Calls Card.clone() on every card in this list and returns a new copy of this list.
      Returns:
      A clone of the list and all its contents. Generally only helpful for "immutable views" of this list.
      See Also:
    • contains

      boolean contains(Card card)
      Checks if the list has the specific reference to a card. Does not use the card's Entity.id or its Card.getCardId(), which may be more helpful.
      Parameters:
      card - The card instance to check.
      Returns:
      true if the specific instance is inside this list.
      See Also:
    • containsCard

      default boolean containsCard(Card card)
      Checks if there is a card in this list whose Card.getCardId() matches the specified instance of a card.
      Parameters:
      card - The card instance to compare.
      Returns:
      true if the there is a card with a matching Card.getCardId().
    • containsCard

      default boolean containsCard(String cardId)
      Checks if there is a card in this list whose Card.getCardId() matches the specified card ID.
      Parameters:
      cardId - The card ID
      Returns:
      true if the there is a card with a matching Card.getCardId().
    • get

      Card get(int index)
      Gets a card at the specified index.
      Specified by:
      get in interface List<Card>
      Parameters:
      index - The index.
      Returns:
      The card.
    • getCount

      int getCount()
      Gets the size of this list.
      Returns:
      The list size.
    • hasCardOfType

      default boolean hasCardOfType(com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType)
      Checks if this instance contains a Card of the specified type.
      Parameters:
      cardType - The type to check.
      Returns:
      true if this instance contains a card of the specified type.
    • isEmpty

      boolean isEmpty()
      Checks if the instance is empty.
      Specified by:
      isEmpty in interface Collection<Card>
      Specified by:
      isEmpty in interface List<Card>
      Returns:
      true if the list is empty.
    • iterator

      Iterator<Card> iterator()
      Provides support for Java language features that require an Iterator
      Specified by:
      iterator in interface Collection<Card>
      Specified by:
      iterator in interface Iterable<Card>
      Specified by:
      iterator in interface List<Card>
      Returns:
      The iterator.
    • peekFirst

      Gets the first card in this instance.
      Returns:
      The first card in this instance.
      Throws:
      ArrayIndexOutOfBoundsException - if the list is empty.
    • remove

      boolean remove(Card card)
      Removes the specified card instance by reference.
      Parameters:
      card - The card to remove.
      Returns:
      true if the card was removed.
    • removeAll

      void removeAll() throws Exception
      Removes all the cards from this instance.
      Throws:
      Exception
    • removeFirst

      Card removeFirst()
      Removes the first card. Implements PutRandomSecretIntoPlaySpell, used by 3 Hearthstone cards.
      Returns:
      The card that is now removed.
    • replace

      boolean replace(Card oldCard, Card newCard)
      Replaces a card by index.
      Parameters:
      oldCard - The card to find and replace.
      newCard - The new card to replace it with.
      Returns:
      true if the replacement was successful.
    • shuffle

      CardList shuffle(XORShiftRandom random)
      Shuffles the instance with the given random number generator.
      Parameters:
      random - A XORShiftRandom instance.
    • toList

      List<Card> toList()
      Gets a List that references the contents of this instance.
      Returns:
      A List whose contents are the same objects as this instance.
    • filtered

      default CardList filtered(Predicate<? super Card> filter)
      Gets a CardList of this instance's cards filtered by filter
      Parameters:
      filter - A predicate.
      Returns:
      A new CardList filtered.
    • getCopy

      default CardList getCopy()
      Copies all the cards in this list and returns a new CardList (possibly of a different implementation) containing those copies.
      Returns:
      A copied list of cards.
      See Also:
    • stream

      default Stream<Card> stream()
      Gets the Stream API representation of this card list.
      Specified by:
      stream in interface Collection<Card>
      Returns:
      The backing list's Collection.stream().
    • peek

      default Card peek()
      Returns the last card in the card list. This is the top of the deck.
      Returns:
      The last card, or null if the List.size() is 0.