Class Card
Each card consists of a Rank and a Suit, and maintains
an internal integer value for efficient poker hand evaluation. The internal
value uses a specific bit layout for fast comparison and evaluation operations.
Cards can be created from their rank and suit components, or parsed from a two-character string representation (e.g., "Ks" for King of Spades).
String format examples:
- "As" - Ace of Spades
- "Kc" - King of Clubs
- "Th" - Ten of Hearts
- "2d" - Two of Diamonds
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Card
Creates a new card with the specified rank and suit.The constructor computes an internal bit-packed value for efficient poker hand evaluation operations.
- Parameters:
rank- the rank of the cardsuit- the suit of the card- Throws:
NullPointerException- if rank or suit is null
-
-
Method Details
-
fromString
Creates a new Card instance from its string representation.The string must be exactly two characters: the first character represents the rank, and the second character represents the suit.
Rank characters: "2", "3", "4", "5", "6", "7", "8", "9", "T" (Ten), "J" (Jack), "Q" (Queen), "K" (King), "A" (Ace)
Suit characters: "s" (Spades), "h" (Hearts), "d" (Diamonds), "c" (Clubs)
- Parameters:
string- the two-character string representation (e.g., "Ks", "2h")- Returns:
- a new Card instance corresponding to the given string
- Throws:
IllegalArgumentException- if string is null, not exactly 2 characters, or contains invalid rank/suit characters
-
getRank
Returns the rank of this card.- Returns:
- the rank of this card
- See Also:
-
getSuit
Returns the suit of this card.- Returns:
- the suit of this card
- See Also:
-
toString
Returns the string representation of this card.The format is a two-character string where the first character represents the rank and the second represents the suit.
Examples: "Ks" (King of Spades), "Jh" (Jack of Hearts), "2c" (Two of Clubs)
-