edu.jhu.cs.oose.elevel.dataModel
Class Deck

java.lang.Object
  extended by edu.jhu.cs.oose.elevel.dataModel.Deck
All Implemented Interfaces:
Serializable

public class Deck
extends Object
implements Serializable

Deck represents the high-level intuition of a deck of flash cards. The class stores a set of Cards and set of TestStats based on past tests.

Author:
Jesse Yates, Greg Anderson, H. Parker Shelton
See Also:
Serialized Form

Constructor Summary
Deck()
           
Deck(String name)
          Initialize a basic Deck using the name provided
 
Method Summary
 boolean addCard(Card c)
          Add the specified Card to the Deck
 void addCardAtIndex(int i, Card c)
          Add the specified Card to the Deck at position i
 boolean addCards(List<Card> cards)
          Add the list of cards to this deck
 boolean addTestStat(TestStat d)
          Adds a new testing statistic to the current set of statistics for the deck
 void clearCards()
          Removes all Cards from the Deck
 void clearTestStats()
          Clears all of the statistics associated with this Deck
 boolean containsAllCards(Collection<Card> cards)
          Returns true if this Deck contains all specified Cards
 boolean containsCard(Card c)
          Returns true if this Deck contains the specified Card
 boolean equals(Deck other)
           
 Card getCard(int index)
          Returns the Card at the index of this deck
 List<Card> getCards()
          Returns the Collection of Cards in this Deck
 String getDiskLocation()
          Returns a String representing the location of this Deck on disk
 Card getFirstCard()
          Helper method that returns the first card in the deck
 Card getLastCard()
          Helper method that returns the last card in the deck
 String getName()
          Returns a String representing the name of this Deck
 Collection<TestStat> getTestStatistics()
          Returns a Collection of TestStats representing the cumulative statistics of this deck
 boolean hasChanged()
           
 int hashCode()
           
 int indexOf(Card c)
          Returns the index of the specified Card in the specified Deck
 boolean isDeckStatEmpty()
          Returns true if there are no statistics
 int numCards()
          Returns the number of cards in this deck
 int numDeckStatistics()
          Returns the number of test statistics in this deck
static Deck readFromDisk(String filepath)
          Read a Deck from disk given an absolute file name
 boolean removeCard(Card c)
          Removes the specified Card from the Deck, if it is present
 void setDiskLocation(String d)
          Updates the location of this Deck on disk
 void setHasChanged(boolean b)
          Sets the hasChanged flag to the specified boolean
 void setName(String n)
          Updates the name of this Deck to the specified String
 void shuffle()
          Randomizes the ordering of the cards in the card list, "shuffling" them
 Iterator<TestStat> testStatisticsIterator()
          Returns an iterator over this Deck's statistics
 String toString()
          A String representation of the entire deck (including cards).
 void writeToDisk(String filepath)
          Export the contents of this Deck to disk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deck

public Deck()

Deck

public Deck(String name)
Initialize a basic Deck using the name provided

Parameters:
name - A String representing the name of the Deck
Method Detail

readFromDisk

public static Deck readFromDisk(String filepath)
                         throws FileNotFoundException,
                                IOException,
                                ClassNotFoundException
Read a Deck from disk given an absolute file name

Parameters:
filepath - A String representing the absolute path file name of the file
Returns:
a Deck created from the specified file
Throws:
FileNotFoundException
IOException
ClassNotFoundException

addCard

public boolean addCard(Card c)
Add the specified Card to the Deck

Parameters:
c - a Card to be added to the deck

addCardAtIndex

public void addCardAtIndex(int i,
                           Card c)
Add the specified Card to the Deck at position i

Parameters:
i - An int representing the position at which to add the specified card
c - The Card to be added

addCards

public boolean addCards(List<Card> cards)
Add the list of cards to this deck

Parameters:
cards - A List of cards to add to this deck
Returns:
true if all cards were successfully added to the deck, false otherwise

addTestStat

public boolean addTestStat(TestStat d)
Adds a new testing statistic to the current set of statistics for the deck

Parameters:
d - TestStat to be associated with the deck
Returns:
true if the TestStat is inserted, false otherwise

clearCards

public void clearCards()
Removes all Cards from the Deck

See Also:
Collection.clear()

clearTestStats

public void clearTestStats()
Clears all of the statistics associated with this Deck

See Also:
Collection.clear()

containsAllCards

public boolean containsAllCards(Collection<Card> cards)
Returns true if this Deck contains all specified Cards

Parameters:
cards - A Collection to be checked for containment in this collection
See Also:
Collection.containsAll(Collection)

containsCard

public boolean containsCard(Card c)
Returns true if this Deck contains the specified Card

Parameters:
c - the Card whose presence in this Deck is to be tested
See Also:
Collection.contains(Object)

equals

public boolean equals(Deck other)

getCard

public Card getCard(int index)
Returns the Card at the index of this deck

Parameters:
index -
Returns:
The card at the index of this deck

getCards

public List<Card> getCards()
Returns the Collection of Cards in this Deck

Returns:
the Collection of Cards in this Deck

getDiskLocation

public String getDiskLocation()
Returns a String representing the location of this Deck on disk

Returns:
a String representing the location of this Deck on disk

getFirstCard

public Card getFirstCard()
Helper method that returns the first card in the deck

Returns:
First card of the deck

getLastCard

public Card getLastCard()
Helper method that returns the last card in the deck

Returns:
The last card in the deck

getName

public String getName()
Returns a String representing the name of this Deck

Returns:
a String representing the name of this Deck

getTestStatistics

public Collection<TestStat> getTestStatistics()
Returns a Collection of TestStats representing the cumulative statistics of this deck

Returns:
a Collection of TestStats representing the cumulative statistics of this deck

hasChanged

public boolean hasChanged()
Returns:
The value of the hasChanged field.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

indexOf

public int indexOf(Card c)
Returns the index of the specified Card in the specified Deck

Returns:
an int representing the index of the specified Card in the specified Deck, -1 if the Card is not contained in the specified Deck

isDeckStatEmpty

public boolean isDeckStatEmpty()
Returns true if there are no statistics

Returns:
true if there are no statistics
See Also:
Collection.isEmpty()

numCards

public int numCards()
Returns the number of cards in this deck

Returns:
the number of cards in this deck

numDeckStatistics

public int numDeckStatistics()
Returns the number of test statistics in this deck

Returns:
the number of test statistics in this deck
See Also:
Collection.size()

removeCard

public boolean removeCard(Card c)
Removes the specified Card from the Deck, if it is present

Parameters:
c - the Card to be removed from the Deck, if it is present
See Also:
Collection.remove(Object)

setDiskLocation

public void setDiskLocation(String d)
Updates the location of this Deck on disk

Parameters:
d - a String representing the new location of this Deck on disk

setHasChanged

public void setHasChanged(boolean b)
Sets the hasChanged flag to the specified boolean

Parameters:
b - the boolean to update the flag to

setName

public void setName(String n)
Updates the name of this Deck to the specified String

Parameters:
n - a String representing the new name of this Deck

shuffle

public void shuffle()
Randomizes the ordering of the cards in the card list, "shuffling" them


testStatisticsIterator

public Iterator<TestStat> testStatisticsIterator()
Returns an iterator over this Deck's statistics

Returns:
an iterator over the collection of TestStats of this Deck
See Also:
Collection.iterator()

toString

public String toString()
A String representation of the entire deck (including cards).

Overrides:
toString in class Object

writeToDisk

public void writeToDisk(String filepath)
                 throws IOException
Export the contents of this Deck to disk

Parameters:
filepath - A String representing the absolute path file name of the file
Throws:
IOException