Interface CardList

All Superinterfaces:
java.util.Collection<Card>, java.lang.Iterable<Card>, java.util.List<Card>, java.io.Serializable
All Known Implementing Classes:
CardArrayList, CardZone

public interface CardList
extends java.lang.Iterable<Card>, java.util.List<Card>, java.io.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 Zones.HAND, Zones.DECK and 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:
for the entity zone that implements this interface., for a implementation of this interface.
  • Method Summary

    Modifier and Type Method Description
    CardList addAll​(CardList cardList)
    Adds all the cards from the given list.
    CardList addCard​(@NotNull Card card)
    Adds the card fluently.
    default CardList addCard​(java.lang.String cardId)  
    CardList clone()
    Calls Card.clone() on every card in this list and returns a new copy of this list.
    boolean contains​(Card card)
    Checks if the list has the specific reference to a card.
    default boolean containsCard​(java.lang.String cardId)
    Checks if there is a card in this list whose Card.getCardId() matches the specified card ID.
    default boolean containsCard​(Card card)
    Checks if there is a card in this list whose Card.getCardId() matches the specified instance of a card.
    default CardList filtered​(java.util.function.Predicate<? super Card> filter)
    Gets a CardList of this instance's cards filtered by filter
    Card get​(int index)
    Gets a card at the specified index.
    default CardList getCopy()
    Copies all the cards in this list and returns a new CardList (possibly of a different implementation) containing those copies.
    int getCount()
    Gets the size of this list.
    default boolean hasCardOfType​(com.hiddenswitch.spellsource.client.models.CardType cardType)
    Checks if this instance contains a Card of the specified type.
    boolean isEmpty()
    Checks if the instance is empty.
    java.util.Iterator<Card> iterator()
    Provides support for Java language features that require an Iterator
    default Card peek()
    Returns the last card in the card list.
    Card peekFirst()
    Gets the first card in this instance.
    boolean remove​(Card card)
    Removes the specified card instance by reference.
    void removeAll()
    Removes all the cards from this instance.
    Card removeFirst()
    Removes the first card.
    boolean replace​(Card oldCard, Card newCard)
    Replaces a card by index.
    CardList shuffle​(XORShiftRandom random)
    Shuffles the instance with the given random number generator.
    default java.util.stream.Stream<Card> stream()
    Gets the Stream API representation of this card list.
    java.util.List<Card> toList()
    Gets a List that references the contents of this instance.

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
  • Method Details

    • addCard

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

      default CardList addCard​(java.lang.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:
      for a more game logic useful version of this method.
    • 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:
      for a more game logic useful version of this method.
    • 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​(java.lang.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 java.util.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.client.models.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 java.util.Collection<Card>
      Specified by:
      isEmpty in interface java.util.List<Card>
      Returns:
      true if the list is empty.
    • iterator

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

      Card peekFirst() throws java.lang.ArrayIndexOutOfBoundsException
      Gets the first card in this instance.
      Returns:
      The first card in this instance.
      Throws:
      java.lang.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 java.lang.Exception
      Removes all the cards from this instance.
      Throws:
      java.lang.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

      java.util.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​(java.util.function.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:
      for more about the difference between a copy and a clone.
    • stream

      default java.util.stream.Stream<Card> stream()
      Gets the Stream API representation of this card list.
      Specified by:
      stream in interface java.util.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.