Class CardArrayList

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<Card>
net.demilich.metastone.game.cards.CardArrayList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Card>, java.util.Collection<Card>, java.util.List<Card>, CardList

public class CardArrayList
extends java.util.AbstractList<Card>
implements java.lang.Cloneable, java.io.Serializable, CardList
An implementation of CardList for easy shuffling, choosing and uniqueness testing of lists of cards.
See Also:
for an example of using this class to return a list of cards from a function. By using this class instead of a plain , the calling code can e.g. easily the results., for a more advanced example of this class., Serialized Form
  • Field Summary

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors 
    Constructor Description
    CardArrayList()  
    CardArrayList​(java.util.Collection<? extends Card> cards)
    Creates this instance from an existing list of cards.
  • Method Summary

    Modifier and Type Method Description
    boolean add​(Card card)  
    CardList addAll​(CardList cardList)
    Adds all the cards from the given list.
    CardList addCard​(Card card)
    Adds the card fluently.
    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.
    Card get​(int index)
    Gets a card at the specified index.
    int getCount()
    Gets the size of this list.
    boolean isEmpty()
    Checks if the instance is empty.
    @NotNull java.util.Iterator<Card> iterator()
    Provides support for Java language features that require an Iterator
    Card peekFirst()
    Gets the first card in this instance.
    Card remove​(int index)  
    boolean remove​(java.lang.Object o)  
    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.
    Card set​(int index, Card element)  
    CardList shuffle()
    Deprecated.
    CardList shuffle​(XORShiftRandom random)
    Shuffles the instance with the given random number generator.
    int size()  
    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 class java.util.AbstractList

    add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList

    Methods inherited from class java.util.AbstractCollection

    addAll, contains, containsAll, removeAll, retainAll, toArray, toArray, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.demilich.metastone.game.cards.CardList

    addCard, containsCard, containsCard, filtered, getCopy, hasCardOfType, peek

    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, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeAll, replaceAll, retainAll, sort, spliterator, subList, toArray, toArray
  • Constructor Details

    • CardArrayList

      public CardArrayList()
    • CardArrayList

      public CardArrayList​(java.util.Collection<? extends Card> cards)
      Creates this instance from an existing list of cards.
      Parameters:
      cards - The list of cards.
  • Method Details

    • add

      public boolean add​(Card card)
      Specified by:
      add in interface java.util.Collection<Card>
      Specified by:
      add in interface java.util.List<Card>
      Overrides:
      add in class java.util.AbstractList<Card>
    • stream

      public java.util.stream.Stream<Card> stream()
      Description copied from interface: CardList
      Gets the Stream API representation of this card list.
      Specified by:
      stream in interface CardList
      Specified by:
      stream in interface java.util.Collection<Card>
      Returns:
      The backing list's Collection.stream().
    • addCard

      public CardList addCard​(Card card)
      Description copied from interface: CardList
      Adds the card fluently.
      Specified by:
      addCard in interface CardList
      Parameters:
      card - The card
      Returns:
      This instance.
    • addAll

      public CardList addAll​(CardList cardList)
      Description copied from interface: CardList
      Adds all the cards from the given list.
      Specified by:
      addAll in interface CardList
      Parameters:
      cardList - The cards to add.
      Returns:
      This instance.
    • clone

      public CardList clone()
      Description copied from interface: CardList
      Calls Card.clone() on every card in this list and returns a new copy of this list.
      Specified by:
      clone in interface CardList
      Overrides:
      clone in class java.lang.Object
      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.
    • set

      public Card set​(int index, Card element)
      Specified by:
      set in interface java.util.List<Card>
      Overrides:
      set in class java.util.AbstractList<Card>
    • contains

      public boolean contains​(Card card)
      Description copied from interface: CardList
      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.
      Specified by:
      contains in interface CardList
      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.
    • get

      public Card get​(int index)
      Description copied from interface: CardList
      Gets a card at the specified index.
      Specified by:
      get in interface CardList
      Specified by:
      get in interface java.util.List<Card>
      Specified by:
      get in class java.util.AbstractList<Card>
      Parameters:
      index - The index.
      Returns:
      The card.
    • getCount

      public int getCount()
      Description copied from interface: CardList
      Gets the size of this list.
      Specified by:
      getCount in interface CardList
      Returns:
      The list size.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CardList
      Checks if the instance is empty.
      Specified by:
      isEmpty in interface CardList
      Specified by:
      isEmpty in interface java.util.Collection<Card>
      Specified by:
      isEmpty in interface java.util.List<Card>
      Overrides:
      isEmpty in class java.util.AbstractCollection<Card>
      Returns:
      true if the list is empty.
    • iterator

      @NotNull public @NotNull java.util.Iterator<Card> iterator()
      Description copied from interface: CardList
      Provides support for Java language features that require an Iterator
      Specified by:
      iterator in interface CardList
      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>
      Overrides:
      iterator in class java.util.AbstractList<Card>
      Returns:
      The iterator.
    • size

      public int size()
      Specified by:
      size in interface java.util.Collection<Card>
      Specified by:
      size in interface java.util.List<Card>
      Specified by:
      size in class java.util.AbstractCollection<Card>
    • peekFirst

      public Card peekFirst()
      Description copied from interface: CardList
      Gets the first card in this instance.
      Specified by:
      peekFirst in interface CardList
      Returns:
      The first card in this instance.
    • remove

      public boolean remove​(java.lang.Object o)
      Specified by:
      remove in interface java.util.Collection<Card>
      Specified by:
      remove in interface java.util.List<Card>
      Overrides:
      remove in class java.util.AbstractCollection<Card>
    • remove

      public boolean remove​(Card card)
      Description copied from interface: CardList
      Removes the specified card instance by reference.
      Specified by:
      remove in interface CardList
      Parameters:
      card - The card to remove.
      Returns:
      true if the card was removed.
    • remove

      public Card remove​(int index)
      Specified by:
      remove in interface java.util.List<Card>
      Overrides:
      remove in class java.util.AbstractList<Card>
    • removeAll

      public void removeAll()
      Description copied from interface: CardList
      Removes all the cards from this instance.
      Specified by:
      removeAll in interface CardList
    • removeFirst

      public Card removeFirst()
      Description copied from interface: CardList
      Removes the first card. Implements PutRandomSecretIntoPlaySpell, used by 3 Hearthstone cards.
      Specified by:
      removeFirst in interface CardList
      Returns:
      The card that is now removed.
    • replace

      public boolean replace​(Card oldCard, Card newCard)
      Description copied from interface: CardList
      Replaces a card by index.
      Specified by:
      replace in interface CardList
      Parameters:
      oldCard - The card to find and replace.
      newCard - The new card to replace it with.
      Returns:
      true if the replacement was successful.
    • shuffle

      @Deprecated public CardList shuffle()
      Deprecated.
    • shuffle

      public CardList shuffle​(XORShiftRandom random)
      Description copied from interface: CardList
      Shuffles the instance with the given random number generator.
      Specified by:
      shuffle in interface CardList
      Parameters:
      random - A XORShiftRandom instance.
    • toList

      public java.util.List<Card> toList()
      Description copied from interface: CardList
      Gets a List that references the contents of this instance.
      Specified by:
      toList in interface CardList
      Returns:
      A List whose contents are the same objects as this instance.