|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--inonit.domain.game.card.CardArray
An ordered collection of Card
objects, which can be manipulated in various ways.
CardArray
instances are mutable, but can acquire some of the benefits of
immutability by using the copy
method to create new copies
for clients who should not change the original CardArray
.
CardArray
objects can contain duplicate Card
s as necessary, and can be
filtered and sorted in various ways.
CardArray
objects are not currently thread-safe, and should only be accessed by a single thread at a time.
Constructor Summary | |
CardArray()
Creates a new, empty CardArray . |
|
CardArray(Card[] cards)
Creates a new CardArray , initialized with the given Card s. |
Method Summary | |
CardArray |
add(Card card)
Appends the given Card to the end of this CardArray . |
CardArray |
add(CardArray array)
Appends the Card s (if any) in the given CardArray to the end of this CardArray . |
static CardArray |
combine(CardArray[] arrays)
Returns the aggregation of the given CardArray s. |
boolean |
contains(Card card)
Returns whether this CardArray contains the given Card . |
boolean |
containsAll(CardArray array)
Returns whether this CardArray contains all of the Card s in the given
CardArray . |
boolean |
containsOne(CardArray array)
Returns whether this CardArray contains at least one Card which is also contained in the
given CardArray . |
CardArray |
copy()
Returns a copy of this CardArray . |
Card[] |
get()
Returns an array containing the Card s in this CardArray . |
Card |
get(int index)
Returns the Card at the given index in this CardArray . |
CardArray |
get(Suit suit)
Returns a CardArray containing the Card s in this CardArray which are of the given
Suit . |
int |
getCount(Suit suit)
Returns the number of cards in this CardArray which are of the given Suit . |
int |
getLength()
Returns the current number of Card s in this CardArray . |
static CardArray |
intersection(CardArray[] arrays)
Returns a CardArray containing all of the Card s that are found in all the
argument CardArray s. |
boolean |
isEmpty()
Returns whether this CardArray is currently empty. |
CardArray |
remove(Card card)
Removes at most one instance (the first) of the given Card from this CardArray . |
CardArray |
remove(CardArray array)
Removes all of the Card s in the given CardArray from this CardArray . |
CardArray |
shuffle()
Shuffles the Card s in this CardArray into random order. |
CardArray |
sort(Sort.Order order)
Sorts the Card s in this CardArray into the given Sort.Order . |
java.lang.String |
toString()
Returns a String which lists the Card s in this CardArray , which may be useful for
debugging. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public CardArray(Card[] cards)
CardArray
, initialized with the given Card
s.cards
- The Card
s to put into the CardArray
. Must not be null
. Must not
contain null
elements.public CardArray()
CardArray
.Method Detail |
public static CardArray combine(CardArray[] arrays)
CardArray
s. If the component CardArray
s
contain duplicate cards, the CardArray
returned will contain the duplicates. The returned
CardArray
will preserve order from the individual CardArray
s; the first
Card
in the result will be the first Card
from the first CardArray
,
followed by the second Card
from the first CardArray
, and so on, until the
first CardArray
is exhausted. The next Card
will be the first Card
from the second CardArray
, and so on.arrays
- The CardArray
s which will be combined to create the result. Must not be null
.
Must not contain null
elements.CardArray
containing all of the Card
s from the individual CardArray
objects in arrays
.public java.lang.String toString()
String
which lists the Card
s in this CardArray
, which may be useful for
debugging.toString
in class java.lang.Object
Card
s in this CardArray
.public int getLength()
Card
s in this CardArray
.Card
s in this CardArray
.public boolean isEmpty()
CardArray
is currently empty. Equivalent to getLength() == 0
.true
if this CardArray does not contain any cards; false
otherwise.public CardArray get(Suit suit)
CardArray
containing the Card
s in this CardArray
which are of the given
Suit
.suit
- The Suit
for which to search this CardArray
.CardArray
containing all the cards (if any) of the given Suit
in this
CardArray
.public int getCount(Suit suit)
CardArray
which are of the given Suit
.suit
- A Suit
. Must not be null
.CardArray
which are of the given Suit
.public CardArray remove(Card card)
Card
from this CardArray
.card
- the Card
to be removed. If null
, this method will have no effect.CardArray
(for convenience); the CardArray
is not
copied.public CardArray remove(CardArray array)
Card
s in the given CardArray
from this CardArray
.
Does not remove
duplicates unless they are also in the argument; for example, if this CardArray
contains two
instances equals to Card.TWO_CLUBS
, and the argument CardArray
contains one,
only the first instance equal to Card.TWO_CLUBS
will be removed from this CardArray
array
- A CardArray
containing the Card
s to be removed from this
CardArray
. Must not be null
.CardArray
(for convenience); the CardArray
is not
copied.public CardArray add(Card card)
Card
to the end of this CardArray
.card
- The card to add to this CardArray
. If null
, this method will have no effect.CardArray
(for convenience); the CardArray
is not
copied.public CardArray add(CardArray array)
Card
s (if any) in the given CardArray
to the end of this CardArray
.array
- A CardArray
containing the Card
s to add to this CardArray
. Must not
be null
.CardArray
(for convenience); the CardArray
is not
copied.public Card get(int index)
Card
at the given index in this CardArray
.index
- the index of the Card
to return. Indices are zero-based; i.e., an argument of 0 will
return the first Card
in the array. Must be not be negative. Must be less than the length of
this CardArray
, as returned by getLength
.Card
at index
in this CardArray
.public boolean contains(Card card)
CardArray
contains the given Card
.card
- The card for which to search this CardArray
. If null
, this method will
always return false
.true
if this CardArray
contains at least one Card
equal
to card
; false
otherwise.public boolean containsAll(CardArray array)
CardArray
contains all of the Card
s in the given
CardArray
. This CardArray
must contain at least as many instances of every
Card
as the argument CardArray
in order to return true
.
For example, if the argument CardArray
contains two Card
s equal to
Card.TWO_CLUBS
, this CardArray
must also contain two cards equal to
Card.TWO_CLUBS
.array
- The CardArray
which may be contained within this CardArray
.true
if this CardArray
contains at least as many copies of each Card
as array
; false
otherwise.public boolean containsOne(CardArray array)
CardArray
contains at least one Card
which is also contained in the
given CardArray
.array
- The CardArray
containing the Card
s for which to search this
CardArray
.true
if this CardArray
contains one of the Card
s contained in
array
.public Card[] get()
Card
s in this CardArray
.Card
s in this CardArray
, in the same order in which they
are contained.public CardArray copy()
CardArray
. This may be useful in situations when it is undesirable to allow a
CardArray
to be mutated.CardArray
.public CardArray sort(Sort.Order order)
Card
s in this CardArray
into the given Sort.Order
. The Card
s
are sorted in place; this method mutates this CardArray
.order
- The order into which to sort the Card
s. It may be convenient to use an subclass
of Card.Order
as the argument.CardArray
(for convenience); the CardArray
is not
copied.public CardArray shuffle()
Card
s in this CardArray
into random order. The Card
s are sorted in
place; this method mutates this CardArray
.CardArray
(for convenience); the CardArray
is not
copied.public static CardArray intersection(CardArray[] arrays)
CardArray
containing all of the Card
s that are found in all the
argument CardArray
s. The returned CardArray
will contain as many copies of each
Card
as are found in each component CardArray
.arrays
- A CardArray[]
. Must not be null
. Must not be zero-length.CardArray
containing the subset of Card
s which can be found in all of the
argument CardArray
s. May contain duplicates if all
of the CardArray
s
in arrays
also contain duplicates of the same Card
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |