scheduler.db.instructordb
Class InstructorDB

java.lang.Object
  extended by java.util.Observable
      extended by scheduler.db.instructordb.InstructorDB

public class InstructorDB
extends java.util.Observable

This class will be the model interface to the MySQL database containing instructor information. This class allows its users to add, modify, and remove instructors from it. One may also retrieve a collection of instructors in the database.

Author:
Jan Lorenz Soliman and Cedric Wienold

Nested Class Summary
static class InstructorDB.DuplicateInstructorException
          Exception class for adding when instructor already exists.
static class InstructorDB.InstructorDoesNotExistException
          This exception is raised when a queried instructor does not exist.
static class InstructorDB.InvalidInstructorException
          Exception class for invalid instructor input.
 class InstructorDB.PreferenceTuple<E>
          Class to house course preference and id.
 class InstructorDB.TimePreferenceTuple
          Class to house time preference and id.
 
Field Summary
protected  java.util.Collection<Instructor> data
          A collection of Instructors
 java.util.ArrayList<InstructorDB.PreferenceTuple> preferences
          A collection of Instructors with course preferences
 java.util.ArrayList<InstructorDB.TimePreferenceTuple> timepreferences
          A collection of Instructors with time preferences
 
Constructor Summary
InstructorDB()
          Here's a constructor that, in fact, does nothing.
InstructorDB(java.util.Collection<Instructor> data)
          This constructor builds an instructordb with predefined data.
 
Method Summary
 void addInstructor(Instructor i)
          Adds a given instructor to the instructor database.
 void changePreferences(java.util.Vector<java.util.Vector> dataTable, Instructor i)
          This method changes the course preferences of a particular instructor.
 void changeTimePreferences(java.util.Vector<java.util.Vector> dataTable, Instructor i)
          This method changes the time preferences of a particular instructor.
 Instructor checkNext()
          Get next and iterator stays the same
 void editInstructor(Instructor i)
          Edits a given instructor which is already in the database.
 void findAndChange(InstructorDB.PreferenceTuple pt)
          Edits an instructor's preference of a certain id and course.
 void findAndChangeTime(InstructorDB.TimePreferenceTuple pt)
          Edits and instructor's preference of a certain id and time.
 java.util.Collection<Instructor> getData()
          Returns the collection of instructors.
 java.util.Collection<Instructor> getDataByGenerosity()
          Returns the instructors sorted by generousity
 Instructor getInstructor(java.lang.String id)
          Returns the instructor from the database matching the inputted string.
 Instructor getInstructorByName(java.lang.String name)
          Returns the instructor from the database matching the name given.
 Instructor getNext()
          Get next and increase iterator
 CoursePreference getPreference(Instructor i, Course c)
          Gets the preference of a particular course for a particular instructor.
 java.util.ArrayList<CoursePreference> getPreferences(Instructor i)
          This method will return all course preferences for a given instructor.
 java.util.Vector<java.util.Vector> getTable()
          Returns a table of instructors and courses in the database.
 java.util.ArrayList<TimePreference> getTimePreferences(Instructor i)
          Returns the time preferences list for this instructor.
 boolean isValidInstructor(Instructor instructor)
          Checks if the Instructor is in the database.
protected  boolean isValidInstructorDB(InstructorDB db)
          Checks if the Instructor Database is valid.
 void removeInstructor(Instructor i)
          Removes a given instructor from the database.
 void reset()
          Reset iterator
 void setData(java.util.Collection<Instructor> data)
          Sets the data in the instructorDB.
 void SetPreferredCourses(Instructor instructor, java.util.Vector<Course> course)
          Adds a vector of preferred courses to the instructor.
 void updatePreferences()
          This function updates the course preferences for this instructor.
 
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
 

Field Detail

data

protected java.util.Collection<Instructor> data
A collection of Instructors


preferences

public java.util.ArrayList<InstructorDB.PreferenceTuple> preferences
A collection of Instructors with course preferences


timepreferences

public java.util.ArrayList<InstructorDB.TimePreferenceTuple> timepreferences
A collection of Instructors with time preferences

Constructor Detail

InstructorDB

public InstructorDB()
Here's a constructor that, in fact, does nothing.


InstructorDB

public InstructorDB(java.util.Collection<Instructor> data)
This constructor builds an instructordb with predefined data.

Parameters:
data - predefined list of instructors.
Method Detail

addInstructor

public void addInstructor(Instructor i)
                   throws InstructorDB.InvalidInstructorException,
                          InstructorDB.DuplicateInstructorException,
                          Instructor.NullUserIDException
Adds a given instructor to the instructor database. pre: // i must be a valid instructor (i != null && i.isValidInstructor()); && // i is not in the database (i not in InstructorDB.data) post: // Only this instructor has been added to the database (forall (Instructor inst) (inst' in InstructorDB'.data) iff ( (inst == i) or (inst in InstructorDB.data)))

Parameters:
i - the new instructor to add to the database
Throws:
InstructorDB.InvalidInstructorException
InstructorDB.DuplicateInstructorException
Instructor.NullUserIDException

changePreferences

public void changePreferences(java.util.Vector<java.util.Vector> dataTable,
                              Instructor i)
This method changes the course preferences of a particular instructor.

Parameters:
dataTable - table of course preferences.
i - instructor whose course preference you wish to change.

changeTimePreferences

public void changeTimePreferences(java.util.Vector<java.util.Vector> dataTable,
                                  Instructor i)
This method changes the time preferences of a particular instructor.

Parameters:
dataTable - table of time preferences.
i - instructor whose time preference you wish to change.

checkNext

public Instructor checkNext()
Get next and iterator stays the same


editInstructor

public void editInstructor(Instructor i)
Edits a given instructor which is already in the database. pre: // // "old" and "new" cannot be the same // instructor != nil; && // // "new" must be a valid instructor // isValidInstructor (instructor, ldb); post: // // A instructor is in the output database iff it was already there // to begin with, iff it was the new user added, and iff it is // not the old instructor that was changed // forall (instructor':data) (instructor' in instructordb') iff (((instructor == instructor') or (instructor in instructordb)) and (instructor != instructor'));

Parameters:
instructor - the instructor to edit

findAndChange

public void findAndChange(InstructorDB.PreferenceTuple pt)
Edits an instructor's preference of a certain id and course.

Parameters:
pt - the preference tuple to change.

findAndChangeTime

public void findAndChangeTime(InstructorDB.TimePreferenceTuple pt)
Edits and instructor's preference of a certain id and time.

Parameters:
pt - time preference tuple to change.

getData

public java.util.Collection<Instructor> getData()
Returns the collection of instructors.

Returns:
a collection of instructors in the database

getDataByGenerosity

public java.util.Collection<Instructor> getDataByGenerosity()
Returns the instructors sorted by generousity

Returns:
a collection of instructors in the database based on the generousity

getInstructor

public Instructor getInstructor(java.lang.String id)
Returns the instructor from the database matching the inputted string.

Parameters:
id - user id of the instructor to get.
Returns:
the instructor matching the id, or null.

getInstructorByName

public Instructor getInstructorByName(java.lang.String name)
Returns the instructor from the database matching the name given.

Parameters:
name - Name of instructor, given in [last],[first] format.
Returns:
the instructor going by the given name.

getNext

public Instructor getNext()
Get next and increase iterator


getPreference

public CoursePreference getPreference(Instructor i,
                                      Course c)
Gets the preference of a particular course for a particular instructor.

Parameters:
i - instructor whose preference to get.
c - course to use to get the preference for this instructor.
Returns:
the course preference for this instructor and course.

getPreferences

public java.util.ArrayList<CoursePreference> getPreferences(Instructor i)
This method will return all course preferences for a given instructor.

Parameters:
i - the instructor for whom to get course preferences.
Returns:
the course preference list for this instructor.

getTable

public java.util.Vector<java.util.Vector> getTable()
Returns a table of instructors and courses in the database.

Returns:
a table of instructors and courses in the database.

getTimePreferences

public java.util.ArrayList<TimePreference> getTimePreferences(Instructor i)
Returns the time preferences list for this instructor.

Parameters:
i - the instructor for whom to get time preferences.
Returns:
the list of time preferences.

isValidInstructor

public boolean isValidInstructor(Instructor instructor)
Checks if the Instructor is in the database.

Parameters:
instructor - instructor to check for in the database
db - the database in which to check for the instructor pre: // none post; // none
Returns:
whether the given instructor is in the given database

isValidInstructorDB

protected boolean isValidInstructorDB(InstructorDB db)
Checks if the Instructor Database is valid. pre: // none post: // none

Parameters:
db - the database to check validity for
Returns:
whether the given database is valid

removeInstructor

public void removeInstructor(Instructor i)
Removes a given instructor from the database. This does not deal with removal. This is handled elsewhere. pre: // // "instructor" must be in "instructordb" // (instructor in instructordb); post: // // The new database differs from the old only in the absence of // "instructor" // forall (instructor':Instructor) (instructor' in instructordb) iff ((instructor' != instructor) and (instructor' in instructordb));

Parameters:
instructor - the instructor to remove from the database

reset

public void reset()
Reset iterator


setData

public void setData(java.util.Collection<Instructor> data)
Sets the data in the instructorDB.

Parameters:
data - The data to be set.

SetPreferredCourses

public void SetPreferredCourses(Instructor instructor,
                                java.util.Vector<Course> course)
Adds a vector of preferred courses to the instructor.

Parameters:
instructor - the instructor for whom to set preferred courses
course - a vector of courses representing the preference

updatePreferences

public void updatePreferences()
This function updates the course preferences for this instructor.