org.norvelle.textcite.model
Class BookCollection

java.lang.Object
  extended by org.norvelle.textcite.model.BookCollection
All Implemented Interfaces:
ListModelAdaptee

public class BookCollection
extends java.lang.Object
implements ListModelAdaptee

The BookCollection object maintains a sorted list of all the Books currently in the Citebook.


Nested Class Summary
static class BookCollection.BookCollectionConverter
          BookCollectionConverter is an inner class used for serializing BookCollection objects via XStream.
 
Field Summary
 java.util.HashMap<java.lang.Integer,Book> books
          We use a HashMap here to maintain a reference to all Books by their IDs
 
Constructor Summary
BookCollection()
          The constructor.
 
Method Summary
 void addAdapter(ListModelChangeListener adapter)
           
 void checkBookIntegrity()
          Make sure that all Books in the collection are connected to Authors which know about the books.
 void clear()
           
 Book getBookByName(java.lang.String name)
           
 java.lang.Object getElementAt(int pos)
          Returns the Book at the given position in the sorted list.
 int getObjectCount()
           
 int getPosInList(java.lang.Object item)
           
 int getSize()
           
 boolean isBookInList(java.lang.String name)
          If the book already exists in the list (with the same author) return tru
 void recreateAdapterCollection()
          After loading a new file, the AdapterCollection (which is marked as transient) will not be recreated during the deserialization process.
 void registerBook(Book book)
          Add a Book object to the list.
 void removeAdapter(ListModelChangeListener adapter)
           
 void restoreCitationReferences()
          After deserializing the Books, each Book object needs to rebuild its HashMap of references to the Citations registered for the author.
 void unregisterBook(Book book)
          Eliminate the given Book object from the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

books

public java.util.HashMap<java.lang.Integer,Book> books
We use a HashMap here to maintain a reference to all Books by their IDs

Constructor Detail

BookCollection

public BookCollection()
The constructor. Sets up the Map objects used to store the Books

Method Detail

registerBook

public void registerBook(Book book)
                  throws DuplicateRecordException
Add a Book object to the list. Fires notifications to all listeners interested in the state of the list.

Parameters:
book - The Book object to be added
Throws:
DuplicateRecordException

unregisterBook

public void unregisterBook(Book book)
Eliminate the given Book object from the list.

Parameters:
book - The Book object to be removed from the list.

getElementAt

public java.lang.Object getElementAt(int pos)
Returns the Book at the given position in the sorted list.

Specified by:
getElementAt in interface ListModelAdaptee
See Also:
ListModel.getElementAt(int)

getSize

public int getSize()
Specified by:
getSize in interface ListModelAdaptee

getObjectCount

public int getObjectCount()
Returns:
Returns the total number of objects contained in the BookCollection.

clear

public void clear()

isBookInList

public boolean isBookInList(java.lang.String name)
If the book already exists in the list (with the same author) return tru

Parameters:
name - The name of the book to search for

getBookByName

public Book getBookByName(java.lang.String name)

getPosInList

public int getPosInList(java.lang.Object item)
Specified by:
getPosInList in interface ListModelAdaptee

addAdapter

public void addAdapter(ListModelChangeListener adapter)
Specified by:
addAdapter in interface ListModelAdaptee

removeAdapter

public void removeAdapter(ListModelChangeListener adapter)
Specified by:
removeAdapter in interface ListModelAdaptee

recreateAdapterCollection

public void recreateAdapterCollection()
After loading a new file, the AdapterCollection (which is marked as transient) will not be recreated during the deserialization process. This procedure needs to be called to recreate an emtpy AdapterCollection.

Specified by:
recreateAdapterCollection in interface ListModelAdaptee

restoreCitationReferences

public void restoreCitationReferences()
After deserializing the Books, each Book object needs to rebuild its HashMap of references to the Citations registered for the author.


checkBookIntegrity

public void checkBookIntegrity()
Make sure that all Books in the collection are connected to Authors which know about the books. If there are any orphan Books in the collection, eliminate them.