poker
Class Card

java.lang.Object
  extended by poker.Card
All Implemented Interfaces:
java.io.Serializable

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

Represents a playing card from a set of cards {0..51} which map to cards having a suit {0..3} <==> {SPADES,HEARTS,DIAMONDS,CLUBS} and a face value {0..12} <==> {2..ACE}

Version:
1.2.2
Author:
Aaron Davidson
See Also:
Serialized Form

Field Summary
static int ACE
           
static int BAD_CARD
           
static int CLUBS
           
static int DIAMONDS
           
static int EIGHT
           
static int FIVE
           
static int FOUR
           
static int HEARTS
           
static int JACK
           
static int KING
           
static int NINE
           
static int NUM_CARDS
           
static int NUM_RANKS
           
static int NUM_SUITS
           
static int QUEEN
           
static int SEVEN
           
static int SIX
           
static int SPADES
           
static int TEN
           
static int THREE
           
static int TWO
           
 
Constructor Summary
Card()
          Constructor -- makes an empty card.
Card(char rank, char suit)
          Constructor.
Card(int index)
          Constructor.
Card(int rank, int suit)
          Constructor.
Card(java.lang.String s)
           
 
Method Summary
 boolean equals(Card c)
           
 int getIndex()
          Return the integer index for this card.
 int getRank()
          Obtain the rank of this card
static int getRank(int i)
          Obtain the rank of this card
static char getRankChar(int r)
           
static int getRankFromChar(char rank)
           
 int getSuit()
          Obtain the suit of this card
static int getSuit(int i)
          Obtain the suit of this card
static char getSuitChar(int s)
          Given an integer suit value {0...3}, returns a character representation of it {h,d,c,s}
static int getSuitFromChar(char suit)
          Converts a suit character into its integer representation.
 void setCard(int rank, int suit)
          Change this card to another.
 void setIndex(int index)
          Change the index of the card.
static int toIndex(int rank, int suit)
          convert a rank and a suit to an index
 java.lang.String toString()
          Obtain a String representation of this Card
 boolean valid()
          Test if the card is valid.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPADES

public static final int SPADES
See Also:
Constant Field Values

HEARTS

public static final int HEARTS
See Also:
Constant Field Values

DIAMONDS

public static final int DIAMONDS
See Also:
Constant Field Values

CLUBS

public static final int CLUBS
See Also:
Constant Field Values

BAD_CARD

public static final int BAD_CARD
See Also:
Constant Field Values

TWO

public static final int TWO
See Also:
Constant Field Values

THREE

public static final int THREE
See Also:
Constant Field Values

FOUR

public static final int FOUR
See Also:
Constant Field Values

FIVE

public static final int FIVE
See Also:
Constant Field Values

SIX

public static final int SIX
See Also:
Constant Field Values

SEVEN

public static final int SEVEN
See Also:
Constant Field Values

EIGHT

public static final int EIGHT
See Also:
Constant Field Values

NINE

public static final int NINE
See Also:
Constant Field Values

TEN

public static final int TEN
See Also:
Constant Field Values

JACK

public static final int JACK
See Also:
Constant Field Values

QUEEN

public static final int QUEEN
See Also:
Constant Field Values

KING

public static final int KING
See Also:
Constant Field Values

ACE

public static final int ACE
See Also:
Constant Field Values

NUM_SUITS

public static final int NUM_SUITS
See Also:
Constant Field Values

NUM_RANKS

public static final int NUM_RANKS
See Also:
Constant Field Values

NUM_CARDS

public static final int NUM_CARDS
See Also:
Constant Field Values
Constructor Detail

Card

public Card()
Constructor -- makes an empty card.


Card

public Card(int rank,
            int suit)
Constructor.

Parameters:
rank - face value of the card
suit - suit of the card

Card

public Card(int index)
Constructor. Creates a Card from an integer index {0..51}

Parameters:
index - integer index of card between 0 and 51

Card

public Card(java.lang.String s)

Card

public Card(char rank,
            char suit)
Constructor. Creates a card from its character based representation.

Parameters:
rank - the character representing the card's rank
suit - the character representing the card's suit
Method Detail

equals

public boolean equals(Card c)

getIndex

public final int getIndex()
Return the integer index for this card.

Returns:
the card's index value

setIndex

public void setIndex(int index)
Change the index of the card.

Parameters:
index - the new index of the card

toIndex

public static final int toIndex(int rank,
                                int suit)
convert a rank and a suit to an index

Parameters:
rank - the rank to convert
suit - the suit to convert
Returns:
the index calculated from the rank and suit

setCard

public void setCard(int rank,
                    int suit)
Change this card to another. This is more practical than creating a new object for optimization reasons.

Parameters:
rank - face value of the card
suit - suit of the card

getRank

public final int getRank()
Obtain the rank of this card

Returns:
rank

getRank

public static final int getRank(int i)
Obtain the rank of this card

Returns:
rank

getSuit

public static final int getSuit(int i)
Obtain the suit of this card

Returns:
suit

getSuit

public final int getSuit()
Obtain the suit of this card

Returns:
suit

toString

public java.lang.String toString()
Obtain a String representation of this Card

Overrides:
toString in class java.lang.Object
Returns:
A string for this card

getRankFromChar

public static int getRankFromChar(char rank)

getSuitFromChar

public static int getSuitFromChar(char suit)
Converts a suit character into its integer representation.

Parameters:
suit - the suit character to convert
Returns:
the integer representation of the suit. Returns -1 for bad suit input.

getRankChar

public static char getRankChar(int r)

getSuitChar

public static char getSuitChar(int s)
Given an integer suit value {0...3}, returns a character representation of it {h,d,c,s}

Returns:
character representing the integer suit value

valid

public boolean valid()
Test if the card is valid.

Returns:
true if the card is a valid card