com.biotools.meerkat
Class Hand

java.lang.Object
  extended by com.biotools.meerkat.Hand
All Implemented Interfaces:
java.io.Serializable

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

Stores a Hand of Cards (up to a maximum of 7) Hands are indexed from 1, not 0. This is done for special speed optimization reasons.

See Also:
Serialized Form

Field Summary
static int MAX_CARDS
           
 
Constructor Summary
Hand()
          Create a new empty hand.
Hand(Hand h)
          Duplicate an existing hand.
Hand(java.lang.String cs)
          Create a hand from a string representation
 
Method Summary
 boolean addCard(Card c)
          Add a card to the hand.
 boolean addCard(int i)
          Add a card to the hand.
 void addHand(Hand h)
          Add the cards from a hand to this hand
 void clear()
          Make empty
 void clearBadCards()
          Remove any invalid cards from this hand
 boolean contains(Card c)
          See if the hand contains a card
 boolean equals(Hand h)
          Returns true if the hands are identical
 java.lang.String flashingString()
          Get a string representation of this Hand for flashing purposes.
 Card getCard(int pos)
          Get the specified card in the hand
 int[] getCardArray()
          Obtain the array of card indexes for this hand.
 int getCardIndex(int pos)
          Get the specified card id
static java.lang.String getCardString(Card c1, Card c2)
          Get a string to represent this starting hand (AA, AKs, QJo, ??, etc...)
 Card getFirstCard()
          Accessor for hole card simplicity.
 Card getLastCard()
           
 int getLastCardIndex()
          Get the last card id
 Card getSecondCard()
          Accessor for hole card simplicity.
 void makeEmpty()
          Remove the all cards from the hand.
 void removeCard()
          Remove the last card in the hand.
 void removeCard(int i)
          Remove the ith card in the hand.
 void setCard(int pos, Card c)
          Set the card at pos to the given card
 void setCard(int pos, int cInd)
          Set the card at pos to the given card
 int size()
          Get the size of the hand.
 void sort()
          Bubble Sort the hand to have cards in descending order, but card index.
 java.lang.String toString()
          Get a string representation of this Hand.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_CARDS

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

Hand

public Hand()
Create a new empty hand.


Hand

public Hand(java.lang.String cs)
Create a hand from a string representation

Parameters:
cs - A string representing a Hand of cards

Hand

public Hand(Hand h)
Duplicate an existing hand.

Parameters:
h - the hand to clone.
Method Detail

clear

public void clear()
Make empty


size

public final int size()
Get the size of the hand.

Returns:
the number of cards in the hand

removeCard

public void removeCard()
Remove the last card in the hand.


makeEmpty

public void makeEmpty()
Remove the all cards from the hand.


addCard

public boolean addCard(Card c)
Add a card to the hand. (if there is room). Ignore it if it null.

Parameters:
c - the card to add, or null (ignored)
Returns:
true if the card was added, false otherwise

addCard

public boolean addCard(int i)
Add a card to the hand. (if there is room)

Parameters:
i - the index value of the card to add
Returns:
true if the card was added, false otherwise

getCard

public Card getCard(int pos)
Get the specified card in the hand

Parameters:
pos - the position (1..n) of the card in the hand
Returns:
the card at position pos

getCardIndex

public int getCardIndex(int pos)
Get the specified card id

Parameters:
pos - the position (1..n) of the card in the hand
Returns:
the card at position pos

getLastCardIndex

public int getLastCardIndex()
Get the last card id

Returns:
the last card id

setCard

public void setCard(int pos,
                    Card c)
Set the card at pos to the given card

Parameters:
pos - the position of the card to add
c - the card to add

setCard

public void setCard(int pos,
                    int cInd)
Set the card at pos to the given card

Parameters:
pos - the position of the card card to set
cInd - the index value of the card to add

getCardArray

public int[] getCardArray()
Obtain the array of card indexes for this hand. First element contains the size of the hand.

Returns:
array of card indexs (size = MAX_CARDS+1)

sort

public void sort()
Bubble Sort the hand to have cards in descending order, but card index. Used for database indexing.


equals

public boolean equals(Hand h)
Returns true if the hands are identical

Parameters:
h - a hand to compare to

toString

public java.lang.String toString()
Get a string representation of this Hand.

Overrides:
toString in class java.lang.Object

flashingString

public java.lang.String flashingString()
Get a string representation of this Hand for flashing purposes.


contains

public boolean contains(Card c)
See if the hand contains a card

Parameters:
c - a card to check for
Returns:
true if the hand contains the card

addHand

public void addHand(Hand h)
Add the cards from a hand to this hand

Parameters:
h - a hand to add

clearBadCards

public void clearBadCards()
Remove any invalid cards from this hand


removeCard

public void removeCard(int i)
Remove the ith card in the hand.


getCardString

public static java.lang.String getCardString(Card c1,
                                             Card c2)
Get a string to represent this starting hand (AA, AKs, QJo, ??, etc...)

Parameters:
c1 - first hole card
c2 - second hole card
Returns:
a string representing the pre-flop hand category

getLastCard

public final Card getLastCard()
Returns:
the last card in the hand

getFirstCard

public Card getFirstCard()
Accessor for hole card simplicity.


getSecondCard

public Card getSecondCard()
Accessor for hole card simplicity.