inonit.domain.game.card
Class Card

java.lang.Object
  |
  +--inonit.domain.game.card.Card
All Implemented Interfaces:
java.io.Serializable

public class Card
extends java.lang.Object
implements java.io.Serializable

A playing card, with a Rank and a Suit. Cards are conceptually values; thus, a Card with a given Rank and Suit is interchangeable with another Card with the same Rank and Suit. Cards are immutable.

Constant Card instances representing the cards in a normal deck are declared as public static final in this class and are not individually documented.

Collections of Cards can be manipulated via the CardArray class.

See Also:
Serialized Form

Inner Class Summary
static class Card.Order
          A logical ordering of a set of Cards.
 
Field Summary
static Card ACE_CLUBS
           
static Card ACE_DIAMONDS
           
static Card ACE_HEARTS
           
static Card ACE_SPADES
           
static Card EIGHT_CLUBS
           
static Card EIGHT_DIAMONDS
           
static Card EIGHT_HEARTS
           
static Card EIGHT_SPADES
           
static Card FIVE_CLUBS
           
static Card FIVE_DIAMONDS
           
static Card FIVE_HEARTS
           
static Card FIVE_SPADES
           
static Card FOUR_CLUBS
           
static Card FOUR_DIAMONDS
           
static Card FOUR_HEARTS
           
static Card FOUR_SPADES
           
static Card JACK_CLUBS
           
static Card JACK_DIAMONDS
           
static Card JACK_HEARTS
           
static Card JACK_SPADES
           
static Card KING_CLUBS
           
static Card KING_DIAMONDS
           
static Card KING_HEARTS
           
static Card KING_SPADES
           
static Card NINE_CLUBS
           
static Card NINE_DIAMONDS
           
static Card NINE_HEARTS
           
static Card NINE_SPADES
           
static Card QUEEN_CLUBS
           
static Card QUEEN_DIAMONDS
           
static Card QUEEN_HEARTS
           
static Card QUEEN_SPADES
           
static Card SEVEN_CLUBS
           
static Card SEVEN_DIAMONDS
           
static Card SEVEN_HEARTS
           
static Card SEVEN_SPADES
           
static Card SIX_CLUBS
           
static Card SIX_DIAMONDS
           
static Card SIX_HEARTS
           
static Card SIX_SPADES
           
static Card TEN_CLUBS
           
static Card TEN_DIAMONDS
           
static Card TEN_HEARTS
           
static Card TEN_SPADES
           
static Card THREE_CLUBS
           
static Card THREE_DIAMONDS
           
static Card THREE_HEARTS
           
static Card THREE_SPADES
           
static Card TWO_CLUBS
           
static Card TWO_DIAMONDS
           
static Card TWO_HEARTS
           
static Card TWO_SPADES
           
 
Method Summary
 boolean equals(java.lang.Object o)
          Returns whether this object equals the given Object.
static Card get(Rank rank, Suit suit)
          Returns a Card object of the given Rank and Suit.
 java.lang.String getAbbreviation()
          Returns an abbreviated string representation of this card.
 Rank getRank()
          Returns the Rank of this Card.
 Suit getSuit()
          Returns the Suit of this Card.
 int hashCode()
          Returns a hash code for this object.
 boolean isSameRankAs(Card card)
          Returns whether the given Card and this Card have the same Rank.
 boolean isSameSuitAs(Card card)
          Returns whether the given Card and this Card have the same Suit.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TWO_CLUBS

public static final Card TWO_CLUBS

THREE_CLUBS

public static final Card THREE_CLUBS

FOUR_CLUBS

public static final Card FOUR_CLUBS

FIVE_CLUBS

public static final Card FIVE_CLUBS

SIX_CLUBS

public static final Card SIX_CLUBS

SEVEN_CLUBS

public static final Card SEVEN_CLUBS

EIGHT_CLUBS

public static final Card EIGHT_CLUBS

NINE_CLUBS

public static final Card NINE_CLUBS

TEN_CLUBS

public static final Card TEN_CLUBS

JACK_CLUBS

public static final Card JACK_CLUBS

QUEEN_CLUBS

public static final Card QUEEN_CLUBS

KING_CLUBS

public static final Card KING_CLUBS

ACE_CLUBS

public static final Card ACE_CLUBS

TWO_DIAMONDS

public static final Card TWO_DIAMONDS

THREE_DIAMONDS

public static final Card THREE_DIAMONDS

FOUR_DIAMONDS

public static final Card FOUR_DIAMONDS

FIVE_DIAMONDS

public static final Card FIVE_DIAMONDS

SIX_DIAMONDS

public static final Card SIX_DIAMONDS

SEVEN_DIAMONDS

public static final Card SEVEN_DIAMONDS

EIGHT_DIAMONDS

public static final Card EIGHT_DIAMONDS

NINE_DIAMONDS

public static final Card NINE_DIAMONDS

TEN_DIAMONDS

public static final Card TEN_DIAMONDS

JACK_DIAMONDS

public static final Card JACK_DIAMONDS

QUEEN_DIAMONDS

public static final Card QUEEN_DIAMONDS

KING_DIAMONDS

public static final Card KING_DIAMONDS

ACE_DIAMONDS

public static final Card ACE_DIAMONDS

TWO_SPADES

public static final Card TWO_SPADES

THREE_SPADES

public static final Card THREE_SPADES

FOUR_SPADES

public static final Card FOUR_SPADES

FIVE_SPADES

public static final Card FIVE_SPADES

SIX_SPADES

public static final Card SIX_SPADES

SEVEN_SPADES

public static final Card SEVEN_SPADES

EIGHT_SPADES

public static final Card EIGHT_SPADES

NINE_SPADES

public static final Card NINE_SPADES

TEN_SPADES

public static final Card TEN_SPADES

JACK_SPADES

public static final Card JACK_SPADES

QUEEN_SPADES

public static final Card QUEEN_SPADES

KING_SPADES

public static final Card KING_SPADES

ACE_SPADES

public static final Card ACE_SPADES

TWO_HEARTS

public static final Card TWO_HEARTS

THREE_HEARTS

public static final Card THREE_HEARTS

FOUR_HEARTS

public static final Card FOUR_HEARTS

FIVE_HEARTS

public static final Card FIVE_HEARTS

SIX_HEARTS

public static final Card SIX_HEARTS

SEVEN_HEARTS

public static final Card SEVEN_HEARTS

EIGHT_HEARTS

public static final Card EIGHT_HEARTS

NINE_HEARTS

public static final Card NINE_HEARTS

TEN_HEARTS

public static final Card TEN_HEARTS

JACK_HEARTS

public static final Card JACK_HEARTS

QUEEN_HEARTS

public static final Card QUEEN_HEARTS

KING_HEARTS

public static final Card KING_HEARTS

ACE_HEARTS

public static final Card ACE_HEARTS
Method Detail

get

public static Card get(Rank rank,
                       Suit suit)
Returns a Card object of the given Rank and Suit.
Parameters:
rank - A Rank. Must not be null.
suit - A Suit. Must not be null.
Returns:
A Card object which has the given Rank and Suit.

toString

public java.lang.String toString()
Returns a string representation of this object.
Overrides:
toString in class java.lang.Object
Returns:
A string representation of this card, e.g., Card: 2 Clubs for Card.TWO_CLUBS, which may be useful for debugging.

equals

public boolean equals(java.lang.Object o)
Returns whether this object equals the given Object. A Card is equal to another Card if it is of the same Rank and Suit.
Overrides:
equals in class java.lang.Object
Parameters:
o - the object to which to compare this one.
Returns:
true if o is a Card and has the same Rank and Suit as this Card; false otherwise.

hashCode

public int hashCode()
Returns a hash code for this object.
Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for this Card consistent with the implementation of equals.

getRank

public Rank getRank()
Returns the Rank of this Card.
Returns:
The Rank of this Card, e.g., Rank.TWO for TWO_CLUBS.

isSameRankAs

public boolean isSameRankAs(Card card)
Returns whether the given Card and this Card have the same Rank.
Parameters:
card - Another Card. Must not be null.
Returns:
true if the given Card has the same Rank as this Card; false otherwise.

getSuit

public Suit getSuit()
Returns the Suit of this Card.
Returns:
The Suit of this Card, e.g., Suit.CLUBS for TWO_CLUBS.

isSameSuitAs

public boolean isSameSuitAs(Card card)
Returns whether the given Card and this Card have the same Suit.
Parameters:
card - Another Card. Must not be null.
Returns:
true if the given Card is of the same Suit as this Card; false otherwise.

getAbbreviation

public java.lang.String getAbbreviation()
Returns an abbreviated string representation of this card.
Returns:
A two-character abbreviation for this card, e.g., 2C for Card.TWO_CLUBS.