com.threerings.parlor.card.data
Class Card

java.lang.Object
  extended by com.threerings.parlor.card.data.Card
All Implemented Interfaces:
Streamable, CardCodes, InvocationCodes, DSet.Entry, Comparable<Card>

public class Card
extends Object
implements DSet.Entry, Comparable<Card>, CardCodes

Instances of this class represent individual playing cards.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected  Byte _key
          The comparison key.
protected  byte _value
          The number of the card.
 
Fields inherited from interface com.threerings.parlor.card.data.CardCodes
ACE, BLACK_JOKER, CLUBS, DIAMONDS, HEARTS, JACK, KING, QUEEN, RED_JOKER, SPADES
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Constructor Summary
Card()
          No-arg constructor for deserialization.
Card(int number, int suit)
          Creates a new card.
 
Method Summary
 int compareTo(Card other)
          Compares this card to another.
 boolean equals(Object other)
           
 Comparable<?> getKey()
           
 int getNumber()
          Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER.
 int getSuit()
          Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS.
 int hashCode()
           
 boolean isAce()
          Checks whether the card is an ace.
 boolean isFace()
          Checks whether the card is a face card (KING, QUEEN, or JACK).
 boolean isJoker()
          Checks whether the card is a joker.
 boolean isNumber()
          Checks whether the card is a number card (2 to 10).
 boolean isValid()
          Checks whether or not this card is valid.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_value

protected byte _value
The number of the card.


_key

protected transient Byte _key
The comparison key.

Constructor Detail

Card

public Card()
No-arg constructor for deserialization.


Card

public Card(int number,
            int suit)
Creates a new card.

Parameters:
number - the number of the card
suit - the suit of the card
Method Detail

getNumber

public int getNumber()
Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER.

Returns:
the value of the card

getSuit

public int getSuit()
Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS. If the card is the joker, the suit is undefined.

Returns:
the suit of the card

isNumber

public boolean isNumber()
Checks whether the card is a number card (2 to 10).

Returns:
true if the card is a number card, false otherwise

isFace

public boolean isFace()
Checks whether the card is a face card (KING, QUEEN, or JACK).

Returns:
true if the card is a face card, false otherwise

isAce

public boolean isAce()
Checks whether the card is an ace.

Returns:
true if the card is an ace, false otherwise

isJoker

public boolean isJoker()
Checks whether the card is a joker.

Returns:
true if the card is a joker, false otherwise

isValid

public boolean isValid()
Checks whether or not this card is valid. The no-arg public constructor for deserialization creates an invalid card.

Returns:
true if this card is valid, false if not

getKey

public Comparable<?> getKey()
Specified by:
getKey in interface DSet.Entry

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

compareTo

public int compareTo(Card other)
Compares this card to another. The card order is the same as the initial deck ordering: two through ten, jack, queen, king, ace for spades, hearts, clubs, and diamonds, then the red joker and the black joker.

Specified by:
compareTo in interface Comparable<Card>
Parameters:
other - the other card to compare this to
Returns:
-1, 0, or +1, depending on whether this card is less than, equal to, or greater than the other card

toString

public String toString()
Overrides:
toString in class Object