Interface CardList
- All Superinterfaces:
Collection<Card>,Iterable<Card>,List<Card>,Serializable
- All Known Implementing Classes:
CardArrayList,CardZone
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.
-
Method Summary
Modifier and TypeMethodDescriptionAdds all the cards from the given list.default CardListAdds the card fluently.clone()CallsCard.clone()on every card in this list and returns a new copy of this list.booleanChecks if the list has the specific reference to a card.default booleancontainsCard(String cardId) Checks if there is a card in this list whoseCard.getCardId()matches the specified card ID.default booleancontainsCard(Card card) Checks if there is a card in this list whoseCard.getCardId()matches the specified instance of a card.default CardListGets aCardListof this instance's cards filtered byfilterget(int index) Gets a card at the specified index.default CardListgetCopy()Copies all the cards in this list and returns a newCardList(possibly of a different implementation) containing those copies.intgetCount()Gets the size of this list.default booleanhasCardOfType(com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType) Checks if this instance contains aCardof the specified type.booleanisEmpty()Checks if the instance is empty.iterator()Provides support for Java language features that require anIteratordefault Cardpeek()Returns the last card in the card list.Gets the first card in this instance.booleanRemoves the specified card instance by reference.voidRemoves all the cards from this instance.Removes the first card.booleanReplaces a card by index.shuffle(XORShiftRandom random) Shuffles the instance with the given random number generator.stream()Gets theStreamAPI representation of this card list.toList()Gets aListthat references the contents of this instance.Methods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods 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
Adds the card fluently.- Parameters:
card- The card- Returns:
- This instance.
-
addCard
-
addAll
Adds all the cards from the given list.- Parameters:
cardList- The cards to add.- Returns:
- This instance.
-
clone
CardList clone()CallsCard.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
Checks if the list has the specific reference to a card. Does not use the card'sEntity.idor itsCard.getCardId(), which may be more helpful.- Parameters:
card- The card instance to check.- Returns:
trueif the specific instance is inside this list.- See Also:
-
containsCard
Checks if there is a card in this list whoseCard.getCardId()matches the specified instance of a card.- Parameters:
card- The card instance to compare.- Returns:
trueif the there is a card with a matchingCard.getCardId().
-
containsCard
Checks if there is a card in this list whoseCard.getCardId()matches the specified card ID.- Parameters:
cardId- The card ID- Returns:
trueif the there is a card with a matchingCard.getCardId().
-
get
Gets a card at the specified index. -
getCount
int getCount()Gets the size of this list.- Returns:
- The list size.
-
isEmpty
boolean isEmpty()Checks if the instance is empty. -
iterator
Provides support for Java language features that require anIterator -
peekFirst
Gets the first card in this instance.- Returns:
- The first card in this instance.
- Throws:
ArrayIndexOutOfBoundsException- if the list is empty.
-
remove
Removes the specified card instance by reference.- Parameters:
card- The card to remove.- Returns:
trueif the card was removed.
-
removeAll
Removes all the cards from this instance.- Throws:
Exception
-
removeFirst
Card removeFirst()Removes the first card. ImplementsPutRandomSecretIntoPlaySpell, used by 3 Hearthstone cards.- Returns:
- The card that is now removed.
-
replace
Replaces a card by index.- Parameters:
oldCard- The card to find and replace.newCard- The new card to replace it with.- Returns:
trueif the replacement was successful.
-
shuffle
Shuffles the instance with the given random number generator.- Parameters:
random- AXORShiftRandominstance.
-
toList
Gets aListthat references the contents of this instance.- Returns:
- A
Listwhose contents are the same objects as this instance.
-
filtered
Gets aCardListof this instance's cards filtered byfilter- Parameters:
filter- A predicate.- Returns:
- A new
CardListfiltered.
-
getCopy
Copies all the cards in this list and returns a newCardList(possibly of a different implementation) containing those copies.- Returns:
- A copied list of cards.
- See Also:
-
stream
Gets theStreamAPI representation of this card list.- Specified by:
streamin interfaceCollection<Card>- Returns:
- The backing list's
Collection.stream().
-
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()is0.
-