com.asdf.plugins.pokergames
Class Card

java.lang.Object
  extended by com.asdf.plugins.pokergames.Card

public class Card
extends java.lang.Object

A class to efficiently represent a traditional playing card from a 52 card deck.


Field Summary
 int card
           
static int[] primes
           
 
Constructor Summary
Card()
          Default constructor.
Card(int card_)
          Constructs a card with the given integer representation.
Card(int rank, int suit)
          Constructs a card with given rank and suit.
 
Method Summary
 int compareTo(Card a)
          Compares this card to another card.
 int getInt()
          Getter for integer representation of the card.
 boolean isValid()
          Checks if the card is a valid card
 boolean lessThan(Card anotherCard)
          Comparator function.
 int rank()
          Getter function for card rank.
 int suit()
          Getter function for card suit.
 void swap(Card a)
          Swaps the contents of two cards
 java.lang.String toString()
          Creates a string representation of the card.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

card

public int card

primes

public static int[] primes
Constructor Detail

Card

public Card()
Default constructor. Initializes the card to improper card.


Card

public Card(int card_)
Constructs a card with the given integer representation.

Parameters:
card_ - integer representation of the card.

Card

public Card(int rank,
            int suit)
Constructs a card with given rank and suit.

Parameters:
rank - Rank is a value from [0-12] and describes the rank of the card.
suit - Suit is an integer from [0-3].
Method Detail

compareTo

public int compareTo(Card a)
Compares this card to another card.

Parameters:
a - Another card.
Returns:
2 if rank of current card is greater than of the other card. -2 if rank is less than that of the other card. 1 if ranks are equal but suit is greater. -1 if ranks are equal but suit is less. 0 if has the same rank and same suit.

lessThan

public boolean lessThan(Card anotherCard)
Comparator function. Compares two cards and says which one is bigger.

Parameters:
anotherCard - A card to which we will compare this card.
Returns:
Returns true if this card is of greater rank than the other card. Otherwise false.

isValid

public boolean isValid()
Checks if the card is a valid card

Returns:
False if card value is zero, true otherwise.

rank

public int rank()
Getter function for card rank.

Returns:
Rank of the card

suit

public int suit()
Getter function for card suit.

Returns:
Integer representation of the suit from the range [0-3].

swap

public void swap(Card a)
Swaps the contents of two cards

Parameters:
a - Another card with which the contents of this card will be swapped.

getInt

public int getInt()
Getter for integer representation of the card.

Returns:
Integer representation of the card.

toString

public java.lang.String toString()
Creates a string representation of the card.

Overrides:
toString in class java.lang.Object