jskat.share
Class CardVector

java.lang.Object
  extended by java.util.Observable
      extended by jskat.share.CardVector
Direct Known Subclasses:
CardDeck

public class CardVector
extends java.util.Observable

Author:
Jan Schäfer

Constructor Summary
CardVector()
          Creates a new instance of CardVector
CardVector(java.util.HashSet<Card> cardSet)
          Creates a new instance of CardVector from a HashSet of Cards
 
Method Summary
 void add(Card card)
          Adds a Card to the CardVector
 void addNew(Card card)
          Adds a Card to the CardVector by creating a new Card object instead of using the reference
 void clear()
          Clears the CardVector
 boolean contains(Card card)
          Searches in the Vector for the given card
 boolean contains(int suit, int value)
          Searches in the Vector for the given card
 Card getCard(int index)
          Returns a reference to a Card in the CardVector without removing it
 int getFirstIndexOfSuit(int suit)
          Gets the index of a card in the Vector
 int getFirstIndexOfSuit(int gameType, int suit)
          Gets the index of a card in the Vector
 int getIndexOf(Card c)
          Gets the index of a card in the Vector
 int getIndexOf(int suit, int value)
          Gets the index of a card in the Vector
 int getLastIndexOfSuit(int suit)
          Gets the index of a card in the Vector
 int getLastIndexOfSuit(int gameType, int suit)
          Gets the index of a card in the Vector
 int getMostFrequentSuitColor()
           
 int getSuitColorCount(int suit)
          Deprecated.  
 int getSuitColorCount(int gameType, int suit)
          Returns the numer of cards with a given suit dependent on a game type
 boolean hasSuit(int suit)
          Deprecated.  
 boolean hasSuit(int gameType, int suit)
          Tests whether a card with a suit is in the CardVector or not
 boolean hasTrump(int trump)
          Deprecated.  
 boolean hasTrump(int gameType, int trump)
          Tests whether a trump card is in the CardVector or not
 java.util.Iterator iterator()
           
 Card remove(Card card)
          Returns a reference to a Card in the CardVector and removes this card from the CardVector
 Card remove(int index)
          Returns a reference to a Card in the CardVector and removes this card from the CardVector
 Card remove(int suit, int value)
          Returns a reference to a Card in the CardVector and removes this card from the CardVector
 int size()
          Returns the size of the CardVector
 void sort(int sortType)
           
 void sort(int gameType, int trump)
          Sorts the cards in the Vector according the sort type SkatConstants
 java.lang.String toString()
          Generates a String of all cards in the CardVector
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CardVector

public CardVector()
Creates a new instance of CardVector


CardVector

public CardVector(java.util.HashSet<Card> cardSet)
Creates a new instance of CardVector from a HashSet of Cards

See Also:
SkatGameData.getDealtCards()
Method Detail

addNew

public void addNew(Card card)
Adds a Card to the CardVector by creating a new Card object instead of using the reference

Parameters:
card - The Card to be added

add

public void add(Card card)
Adds a Card to the CardVector

Parameters:
card - The Card to be added

getCard

public Card getCard(int index)
Returns a reference to a Card in the CardVector without removing it

Parameters:
index - The Index of the Card to be returned

remove

public Card remove(int index)
Returns a reference to a Card in the CardVector and removes this card from the CardVector

Parameters:
index - The index of the Card to remove
Returns:
The Card

remove

public Card remove(Card card)
Returns a reference to a Card in the CardVector and removes this card from the CardVector

Parameters:
card - The Card to remove
Returns:
The Card

remove

public Card remove(int suit,
                   int value)
Returns a reference to a Card in the CardVector and removes this card from the CardVector

Parameters:
suit - The suit of the card to remove
value - The value of the card to remove
Returns:
The Card

contains

public boolean contains(int suit,
                        int value)
Searches in the Vector for the given card

Parameters:
suit - The suit of the card
value - The value of the card
Returns:
TRUE if the card is in the CardVector

contains

public boolean contains(Card card)
Searches in the Vector for the given card

Parameters:
card - The Card
Returns:
TRUE if the card is in the CardVector

hasSuit

public boolean hasSuit(int suit)
Deprecated. 

Searches in the Vector for the given card Returns true if the card is in the Vector This method doesn't take the game type into account

Parameters:
suit - Suit to be tested
Returns:
TRUE, when the suit is on the hand

hasSuit

public boolean hasSuit(int gameType,
                       int suit)
Tests whether a card with a suit is in the CardVector or not

Parameters:
gameType - Game type of the game played
suit - Suit color
Returns:
TRUE, when a card with the suit is found

hasTrump

public boolean hasTrump(int trump)
Deprecated. 

Searches in the Vector for any trump cards. Returns true if at least one trump card is in the Vector This is only valid for suit games

Parameters:
trump - Current trump color
Returns:
TRUE, when a trump card is found

hasTrump

public boolean hasTrump(int gameType,
                        int trump)
Tests whether a trump card is in the CardVector or not

Parameters:
gameType - Game type of the game played
trump - Trump color
Returns:
TRUE, when a trump card was found in the CardVector

getIndexOf

public int getIndexOf(Card c)
Gets the index of a card in the Vector


getIndexOf

public int getIndexOf(int suit,
                      int value)
Gets the index of a card in the Vector


getFirstIndexOfSuit

public int getFirstIndexOfSuit(int suit)
Gets the index of a card in the Vector


getFirstIndexOfSuit

public int getFirstIndexOfSuit(int gameType,
                               int suit)
Gets the index of a card in the Vector


getLastIndexOfSuit

public int getLastIndexOfSuit(int suit)
Gets the index of a card in the Vector


getLastIndexOfSuit

public int getLastIndexOfSuit(int gameType,
                              int suit)
Gets the index of a card in the Vector


getMostFrequentSuitColor

public int getMostFrequentSuitColor()

getSuitColorCount

public int getSuitColorCount(int suit)
Deprecated. 

Returns number of cards with a given suit This is only valid for suit games

Parameters:
suit - The suit to search for
Returns:
Number of cards with this suit

getSuitColorCount

public int getSuitColorCount(int gameType,
                             int suit)
Returns the numer of cards with a given suit dependent on a game type

Parameters:
gameType - The game type
suit - The suit to search for
Returns:
Number of cards with this suit

sort

public void sort(int sortType)

sort

public void sort(int gameType,
                 int trump)
Sorts the cards in the Vector according the sort type SkatConstants


size

public int size()
Returns the size of the CardVector


toString

public java.lang.String toString()
Generates a String of all cards in the CardVector

Overrides:
toString in class java.lang.Object
Returns:
All cards

iterator

public java.util.Iterator iterator()

clear

public void clear()
Clears the CardVector