addressbook
Class AddressBook

java.lang.Object
  extended by java.util.Observable
      extended by addressbook.AddressBook
All Implemented Interfaces:
java.io.Serializable

public class AddressBook
extends java.util.Observable
implements java.io.Serializable

An object of this class maintains the collection of Person objects that constitute an address book

See Also:
Serialized Form

Constructor Summary
AddressBook()
          Constructor - create a new, empty address book
 
Method Summary
 void addPerson(java.lang.String firstName, java.lang.String lastName, java.lang.String address, java.lang.String city, java.lang.String state, java.lang.String zip, java.lang.String phone)
          Add a new Person to the collection
 boolean getChangedSinceSaved()
          Find out whether this address book has been changed since last open / save
 java.io.File getFile()
          Get the File this address book was most recently read from or saved to
 java.lang.String[] getNames()
          Provide a list of the the names of all the persons in the collection
 java.lang.String[] getPersonInformation(java.lang.String name)
          Provide current information about a person
 java.lang.String getTitle()
          Get the title of this address book - based on the most recently used file
 void printMailingLabels(java.io.PrintWriter writer)
          Print the collection of persons in order.
 void removePerson(java.lang.String name)
          Remove a specific person from the collection
 int search(java.lang.String criterion, int startingIndex)
          Search the collection for a person matching given criteria
 void setFile(java.io.File file)
          Set the File this address book was most recently read from or saved to
 void setUnchangedSinceLastSave()
          Record that an open/save operation has taken place, rendering this address book unchanged since the last such operation
 void sortByName()
          Sort the collection by name
 void sortByZip()
          Sort the collection by ZIP
 void updatePerson(java.lang.String name, java.lang.String address, java.lang.String city, java.lang.String state, java.lang.String zip, java.lang.String phone)
          Update stored information about a person
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddressBook

public AddressBook()
Constructor - create a new, empty address book

Method Detail

getNames

public java.lang.String[] getNames()
Provide a list of the the names of all the persons in the collection

Returns:
an array of Strings, each representing the name of one person

addPerson

public void addPerson(java.lang.String firstName,
                      java.lang.String lastName,
                      java.lang.String address,
                      java.lang.String city,
                      java.lang.String state,
                      java.lang.String zip,
                      java.lang.String phone)
Add a new Person to the collection

Parameters:
firstName - the person's first name
lastName - the person's last name
address - the person's address
city - the person's city
state - the person's state
zip - the person's zip
phone - the person's phone

getPersonInformation

public java.lang.String[] getPersonInformation(java.lang.String name)
Provide current information about a person

Parameters:
name - the desired name
Returns:
an array of Strings, each containing one piece of stored information about this person, or null if no such person exists

updatePerson

public void updatePerson(java.lang.String name,
                         java.lang.String address,
                         java.lang.String city,
                         java.lang.String state,
                         java.lang.String zip,
                         java.lang.String phone)
                  throws java.lang.IllegalArgumentException
Update stored information about a person

Parameters:
name - the name of the person (which cannot be updated)
address - the person's new address
city - the person's new city
state - the person's new state
zip - the person's new zip
phone - the person's new phone
Throws:
java.lang.IllegalArgumentException - if the specified person does not exist

removePerson

public void removePerson(java.lang.String name)
                  throws java.lang.IllegalArgumentException
Remove a specific person from the collection

Parameters:
name - the desired name
Throws:
java.lang.IllegalArgumentException - if the specified person does not exist

sortByName

public void sortByName()
Sort the collection by name


sortByZip

public void sortByZip()
Sort the collection by ZIP


search

public int search(java.lang.String criterion,
                  int startingIndex)
Search the collection for a person matching given criteria

Parameters:
criterion - the criterion for the search
startingIndex - the position to start the search from
Returns:
the index of the first person at or after startingIndex which has a field that contains the criterion, or -1 if there is no such person

getFile

public java.io.File getFile()
Get the File this address book was most recently read from or saved to

Returns:
the most recent File - if any - null if none

setFile

public void setFile(java.io.File file)
Set the File this address book was most recently read from or saved to

Parameters:
file - the file just used to read or save this object

getTitle

public java.lang.String getTitle()
Get the title of this address book - based on the most recently used file

Returns:
the title of this address book - "Untitled" if none

printMailingLabels

public void printMailingLabels(java.io.PrintWriter writer)
Print the collection of persons in order.

Parameters:
writer - the writer to print to

getChangedSinceSaved

public boolean getChangedSinceSaved()
Find out whether this address book has been changed since last open / save

Returns:
true if this address book has been changed since the last open / save; false if not

setUnchangedSinceLastSave

public void setUnchangedSinceLastSave()
Record that an open/save operation has taken place, rendering this address book unchanged since the last such operation