net.sourceforge.pavlov.library
Class Book

java.lang.Object
  extended by net.sourceforge.pavlov.library.LibraryDocument
      extended by net.sourceforge.pavlov.library.Book
All Implemented Interfaces:
Serializable, Comparable, AbstractBook

public final class Book
extends LibraryDocument
implements AbstractBook, Serializable, Comparable

Describes a Book, which is a collection of Chapters.

See Also:
Library, Chapter, Question, Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.pavlov.library.LibraryDocument
author, description, name
 
Constructor Summary
Book()
          Create an unnamed, empty book.
Book(String name)
           
 
Method Summary
 void addChapter(Chapter chapter)
          Adds the named chapter, keyed on Chapter.getName().
 int compareTo(Object obj)
           
 Book deepCopy()
          Uses a neat trick from "Design Patterns in Java" to make a completely independent copy of this book.
 void deleteChapter(String cpName)
          Deletes the named chapter
 boolean equals(Object obj)
          Returns true if this book equals the given book.
protected  String getBaseFileName()
          Creates a cannonical filename for this book, lowercasing it and URLEncoding it.
 Chapter getChapter(String cpName)
          Returns the named chapter, or null if it doesn't exist
 TreeMap<String,AbstractChapter> getChapters()
          Returns a hashtable of all my chapters.
 Collection<AbstractChapter> getChaptersReadOnly()
          Returns the book's chapters as a read-only collection.
 String getCover()
          Returns filename of a descriptive image of this book.
 int getNumberOfChapters()
          Returns the number of chapters I have.
 int getNumberOfQuestions()
          Sums the number of questions of all my chapters and returns the total.
 String getTitle()
          Deprecated. use getName() instead.
 Collection<AbstractChapter> getValues()
          Returns the book's chapters as a collection.
static Book loadFrom(File bookFile)
           
static Book loadFrom(String filename)
           
static Book makeBlankBook()
          Creates an unnamed book with one unnamed chapter, which has one blank question.
 void populateTree(DefaultMutableTreeNode bk)
          Displays chapters as a tree.
 void save(File directory)
          Saves the book in the given directory, using the book's cannonical filename.
 void saveAs(File file)
          Saves the book to the given file.
 void setCover(String n)
          Sets filename of a descriptive image of this book.
 String toString()
          Returns the book's name
 void toXML(Writer writer)
          Dumps the Book in XML format to the given writer.
 
Methods inherited from class net.sourceforge.pavlov.library.LibraryDocument
getAuthor, getDescription, getName, setAuthor, setDescription, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.pavlov.library.AbstractBook
getAuthor, getDescription, getName
 

Constructor Detail

Book

public Book()
Create an unnamed, empty book.


Book

public Book(String name)
Method Detail

compareTo

public int compareTo(Object obj)
Specified by:
compareTo in interface Comparable

makeBlankBook

public static Book makeBlankBook()
Creates an unnamed book with one unnamed chapter, which has one blank question.

Returns:
a Book value

setCover

public void setCover(String n)
Sets filename of a descriptive image of this book.

Parameters:
n - a String value

getCover

public String getCover()
Returns filename of a descriptive image of this book.

Specified by:
getCover in interface AbstractBook
Returns:
a String value

getTitle

@Deprecated
public String getTitle()
Deprecated. use getName() instead.

Describe getTitle method here.

Specified by:
getTitle in interface AbstractBook
Returns:
a String value

addChapter

public void addChapter(Chapter chapter)
Adds the named chapter, keyed on Chapter.getName().

Parameters:
b - a Chapter value

deleteChapter

public void deleteChapter(String cpName)
Deletes the named chapter

Parameters:
cpName - a String value

getChapter

public Chapter getChapter(String cpName)
Returns the named chapter, or null if it doesn't exist

Specified by:
getChapter in interface AbstractBook
Parameters:
cpName - a String value
Returns:
a Chapter value

getNumberOfQuestions

public int getNumberOfQuestions()
Sums the number of questions of all my chapters and returns the total.

Specified by:
getNumberOfQuestions in interface AbstractBook
Returns:
an int value

toXML

public void toXML(Writer writer)
           throws IOException
Dumps the Book in XML format to the given writer. Loops throught chapters, questions.

Specified by:
toXML in interface AbstractBook
Parameters:
writer - a java.io.Writer value
Throws:
IOException - if an error occurs

save

public void save(File directory)
          throws IOException
Saves the book in the given directory, using the book's cannonical filename.

Specified by:
save in interface AbstractBook
Parameters:
directory - a File value
Throws:
IOException

saveAs

public void saveAs(File file)
            throws IOException
Saves the book to the given file.

Parameters:
file - a File value
Throws:
IOException

loadFrom

public static Book loadFrom(String filename)

loadFrom

public static Book loadFrom(File bookFile)

getBaseFileName

protected String getBaseFileName()
Creates a cannonical filename for this book, lowercasing it and URLEncoding it.

Returns:
a String value

populateTree

public void populateTree(DefaultMutableTreeNode bk)
Displays chapters as a tree.

Specified by:
populateTree in interface AbstractBook
Parameters:
bk - a DefaultMutableTreeNode value

getChapters

public TreeMap<String,AbstractChapter> getChapters()
Returns a hashtable of all my chapters.

Returns:
a Hashtable value

getNumberOfChapters

public int getNumberOfChapters()
Returns the number of chapters I have.

Returns:
an int value

toString

public String toString()
Returns the book's name

Specified by:
toString in interface AbstractBook
Overrides:
toString in class Object
Returns:
a String value

getValues

public Collection<AbstractChapter> getValues()
Returns the book's chapters as a collection.

Specified by:
getValues in interface AbstractBook
Returns:
a Collection value

getChaptersReadOnly

public Collection<AbstractChapter> getChaptersReadOnly()
Returns the book's chapters as a read-only collection.

Specified by:
getChaptersReadOnly in interface AbstractBook
Returns:
a Collection value

equals

public boolean equals(Object obj)
Returns true if this book equals the given book.

Overrides:
equals in class Object
Parameters:
obj - an Object value
Returns:
a boolean value

deepCopy

public Book deepCopy()
Uses a neat trick from "Design Patterns in Java" to make a completely independent copy of this book. Normal copying methods are unsuitable for book editing.

Returns:
a Book value