edu.harvard.deas.hyperenc
Class DBContactList

java.lang.Object
  extended by edu.harvard.deas.hyperenc.ContactList
      extended by edu.harvard.deas.hyperenc.DBContactList
All Implemented Interfaces:
Iterable<Contact>

public class DBContactList
extends ContactList

A contact list backed by a database on disk. This class uses PersistentMap to store the Contacts to disk. Because PersistentMap provides an unsorted view of the data, this class also stores all Contacts in the list in a sorted collection in memory; all changes to this list are made in the in-memory copy and also written through to disk via the PersistentMap.

DBContactList attempts to read in any existing contact list from disk that has the same owner. If none is found, a new, empty DBContactList is created. Because entries are stored in the on-disk database in an inherently unsorted manner, the order of Contacts in a DBContactList may not be consistent across multiple sessions—the order is subject to change every time the data is read in from disk.

See Also:
PersistentMap

Constructor Summary
DBContactList(Contact owner)
          Equivalent to DBContactList(owner, null).
DBContactList(Contact owner, File envPath)
          Creates a new DBContactList.
 
Method Summary
 void addContact(Contact c)
          Appends c to the list.
 Contact get(int index)
          Returns the contact at index index in the list.
 Contact getContact(Address a)
          Returns the Contact in this list with e-mail address a.
 boolean isEmpty()
          Returns whether this list is empty.
 Iterator<Contact> iterator()
          Returns an Iterator over the Contacts in this list.
 void removeContact(Contact c)
          Removes c from the list.
 int size()
          Returns the number of contacts in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBContactList

public DBContactList(Contact owner,
                     File envPath)
Creates a new DBContactList. Attempts to read in any existing contact list from disk that has the same owner. If none is found, a new, empty DBContactList is created. Because entries are stored in the on-disk database in an inherently unsorted manner, the order of Contacts in a DBContactList may not be consistent across multiple sessions—the order of the Contacts in the created list may be different from the order in which they were written by a previous instance of DBContactList.

Parameters:
owner - the owner of this list (usually the Contact corresponding to the user of the hyper-encryption application)
envPath - The path on disk of the database backing this map. Must be readable and writable. If it doesn't exist, it will be created. If null, the default environment specified by PersistentMap.DEFAULT_HOME is used.
See Also:
PersistentMap

DBContactList

public DBContactList(Contact owner)
Equivalent to DBContactList(owner, null).

Parameters:
owner - the owner of this list (usually the Contact corresponding to the user of the hyper-encryption application)
Method Detail

iterator

public Iterator<Contact> iterator()
Description copied from class: ContactList
Returns an Iterator over the Contacts in this list. The Iterator returns Contacts in the order in which they appear in this list, that is, starting from index 0 and going in increasing order.

Specified by:
iterator in interface Iterable<Contact>
Specified by:
iterator in class ContactList

addContact

public void addContact(Contact c)
Description copied from class: ContactList
Appends c to the list.

Specified by:
addContact in class ContactList
Parameters:
c - the contact to be added

removeContact

public void removeContact(Contact c)
Description copied from class: ContactList
Removes c from the list.

Specified by:
removeContact in class ContactList
Parameters:
c - the contact to be removed

get

public Contact get(int index)
Description copied from class: ContactList
Returns the contact at index index in the list.

Specified by:
get in class ContactList
Parameters:
index - an integer index between 0 and this.size() - 1
Returns:
the contact at the specified index

size

public int size()
Description copied from class: ContactList
Returns the number of contacts in the list.

Specified by:
size in class ContactList
Returns:
the size of this list

isEmpty

public boolean isEmpty()
Description copied from class: ContactList
Returns whether this list is empty.

Overrides:
isEmpty in class ContactList
Returns:
true iff the size of this list is 0

getContact

public Contact getContact(Address a)
Returns the Contact in this list with e-mail address a.

Specified by:
getContact in class ContactList
Parameters:
a - e-mail address
Returns:
the Contact with the given e-mail address