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 CardList
Adds the card fluently.clone()
CallsCard.clone()
on every card in this list and returns a new copy of this list.boolean
Checks if the list has the specific reference to a card.default boolean
containsCard
(String cardId) Checks if there is a card in this list whoseCard.getCardId()
matches the specified card ID.default boolean
containsCard
(Card card) Checks if there is a card in this list whoseCard.getCardId()
matches the specified instance of a card.default CardList
Gets aCardList
of this instance's cards filtered byfilter
get
(int index) Gets a card at the specified index.default CardList
getCopy()
Copies all the cards in this list and returns a newCardList
(possibly of a different implementation) containing those copies.int
getCount()
Gets the size of this list.default boolean
hasCardOfType
(com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType) Checks if this instance contains aCard
of the specified type.boolean
isEmpty()
Checks if the instance is empty.iterator()
Provides support for Java language features that require anIterator
default Card
peek()
Returns the last card in the card list.Gets the first card in this instance.boolean
Removes the specified card instance by reference.void
Removes all the cards from this instance.Removes the first card.boolean
Replaces a card by index.shuffle
(XORShiftRandom random) Shuffles the instance with the given random number generator.stream()
Gets theStream
API representation of this card list.toList()
Gets aList
that references the contents of this instance.Methods inherited from interface java.util.Collection
parallelStream, removeIf, toArray
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
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.id
or itsCard.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
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:
true
if 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:
true
if 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:
true
if 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:
true
if the replacement was successful.
-
shuffle
Shuffles the instance with the given random number generator.- Parameters:
random
- AXORShiftRandom
instance.
-
toList
Gets aList
that references the contents of this instance.- Returns:
- A
List
whose contents are the same objects as this instance.
-
filtered
Gets aCardList
of this instance's cards filtered byfilter
- Parameters:
filter
- A predicate.- Returns:
- A new
CardList
filtered.
-
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 theStream
API representation of this card list.- Specified by:
stream
in 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
.
-