net.sourceforge.pavlov.library
Class Chapter

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

public final class Chapter
extends LibraryDocument
implements AbstractChapter, Serializable, Comparable

Describes a chapter, which contains questions.

See Also:
Question, Book, Library, Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.pavlov.library.LibraryDocument
author, description, name
 
Constructor Summary
Chapter()
          Creates an untitled chapter.
Chapter(String newName)
          Creates a new Chapter instance.
 
Method Summary
 void addQuestion(Question b)
          Adds a question using it's ID as the key
 int compareTo(Object obj)
           
 Chapter deepCopy()
          Uses a nifty trick from "Design Patterns in Java" to make a completely independent copy of this chapter.
 boolean equals(Object obj)
          Returns true if the given object is a chapter and all its elements are equal to mine.
 String getCover()
          Returns the filename for a descriptive image.
 int getNumberOfQuestions()
          Number of questions this chapter contains.
 Question getQuestion(String id)
          Gets the question with the specified ID or null if it doesn't exist.
 TreeMap<String,Question> getQuestions()
          Describe getQuestions method here.
 Collection<Question> getQuestionsCollection()
          Deprecated.  
 Collection<Question> getQuestionsReadOnly()
          Returns the chapter's questions as a read-only collection.
 String getTitle()
          Deprecated. Use getName()
static Chapter makeBlankChapter()
          Describe makeBlankChapter method here.
 void setCover(String n)
          Sets the filename for a descriptive image.
 void setQuestions(Collection<Question> list)
          Describe setQuestions method here.
 void setTitle(String n)
          Deprecated. Use setTitle()
 String toString()
          Returns the chapter's title
 void toXML(Writer writer)
          Dumps the chapter 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.AbstractChapter
getAuthor, getDescription
 

Constructor Detail

Chapter

public Chapter()
Creates an untitled chapter.


Chapter

public Chapter(String newName)
Creates a new Chapter instance.

Parameters:
newName - a String value
Method Detail

getQuestion

public Question getQuestion(String id)
Gets the question with the specified ID or null if it doesn't exist.

Specified by:
getQuestion in interface AbstractChapter
Parameters:
id - a String value
Returns:
a Question value

compareTo

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

setQuestions

public void setQuestions(Collection<Question> list)
Describe setQuestions method here.


getNumberOfQuestions

public int getNumberOfQuestions()
Number of questions this chapter contains.

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

getTitle

@Deprecated
public String getTitle()
Deprecated. Use getName()

Returns the title of this chapter.

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

setTitle

@Deprecated
public void setTitle(String n)
Deprecated. Use setTitle()

Sets the title of this chapter.

Parameters:
n - a String value

getCover

public String getCover()
Returns the filename for a descriptive image.

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

setCover

public void setCover(String n)
Sets the filename for a descriptive image.

Parameters:
n - a String value

addQuestion

public void addQuestion(Question b)
Adds a question using it's ID as the key

Parameters:
b - a Question value

toXML

public void toXML(Writer writer)
           throws IOException
Dumps the chapter in XML format to the given writer. Dumps all questions too.

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

getQuestionsCollection

@Deprecated
public Collection<Question> getQuestionsCollection()
Deprecated. 

Returns all questions as a Collection

Specified by:
getQuestionsCollection in interface AbstractChapter
Returns:
a Collection value

getQuestionsReadOnly

public Collection<Question> getQuestionsReadOnly()
Returns the chapter's questions as a read-only collection.

Specified by:
getQuestionsReadOnly in interface AbstractChapter
Returns:
a Collection value

getQuestions

public TreeMap<String,Question> getQuestions()
Describe getQuestions method here.

Returns:
a Hashtable value

toString

public String toString()
Returns the chapter's title

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

makeBlankChapter

public static Chapter makeBlankChapter()
Describe makeBlankChapter method here.

Returns:
a Chapter value

equals

public boolean equals(Object obj)
Returns true if the given object is a chapter and all its elements are equal to mine.

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

deepCopy

public Chapter deepCopy()
Uses a nifty trick from "Design Patterns in Java" to make a completely independent copy of this chapter. Useful in chapter editors.

Returns:
a Chapter value