scheduler.db.coursedb
Class CourseDB

java.lang.Object
  extended by java.util.Observable
      extended by scheduler.db.coursedb.CourseDB

public class CourseDB
extends java.util.Observable

The class representing the course database.

Author:
Jan Lorenz Soliman

Nested Class Summary
static class CourseDB.CourseDoesNotExistException
          Course already exists exception thrown in the set methods.
static class CourseDB.CourseExistsException
          Course already exists exception thrown in the set methods.
static class CourseDB.SectionsTuple
          A tuple representing the number of sectons for the courses.
 
Field Summary
static java.lang.String courseFields
          A constant representing the course fields for a courses SQL database.
protected  java.util.Collection<Course> data
          A collection of courses.
protected  java.util.Collection<CourseDB.SectionsTuple> sectionsPerCourse
          A collection of the sections per course.
 
Constructor Summary
CourseDB()
          Construct the database and grab the information from the SQL database.
 
Method Summary
 void addCourse(Course c)
          Adds a given course to the course database.
 void addCourseTest(Course c)
          Same as addCourse, but used for testing purposes.
 void changeSections(java.lang.String id, int sections)
          Changes the number of sections per course
 void changeSections(java.util.Vector<java.util.Vector> dataTable)
           
 void editCourse(Course c)
          Edits a given course which is already in the course database.
 void editCourseTest(Course c)
          The same as editCourse but for testing purposes.
 Course getCourse(int number, java.lang.String courseType)
          Gets the course by courseNum
 java.util.Collection<Course> getData()
          Returns the collection of courses
 java.util.Vector<java.lang.String> getLabNames()
          A method to get all of the lab course names in the Course Database.
 java.util.Vector<Course> getLabs()
          A method to get all of the lab courses in the Course Database.
 int getTotalSections()
          Returns the total number of sections
 void removeCourse(Course c)
          Removes a given, already-exiting course from the course database
 void removeCourseTest(Course c)
          The same as removeCourse() but for testing purposes.
 void setData(java.util.Collection<Course> data)
          Sets the data in the courseDB
 boolean validId(int id)
          Checks if the id is three digits long
 
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

courseFields

public static final java.lang.String courseFields
A constant representing the course fields for a courses SQL database.

See Also:
Constant Field Values

data

protected java.util.Collection<Course> data
A collection of courses.


sectionsPerCourse

protected java.util.Collection<CourseDB.SectionsTuple> sectionsPerCourse
A collection of the sections per course.

Constructor Detail

CourseDB

public CourseDB()
Construct the database and grab the information from the SQL database.

Method Detail

changeSections

public void changeSections(java.util.Vector<java.util.Vector> dataTable)

changeSections

public void changeSections(java.lang.String id,
                           int sections)
Changes the number of sections per course

Parameters:
id - The id of the course. The id will have a L if it is a lab.
sections - The number of sections for the course

getData

public java.util.Collection<Course> getData()
Returns the collection of courses


setData

public void setData(java.util.Collection<Course> data)
Sets the data in the courseDB

Parameters:
data - The data to be set.

getCourse

public Course getCourse(int number,
                        java.lang.String courseType)
Gets the course by courseNum
  pre: 
         //
         // The course number is three digits long
         // 
         (this.validId(number)  )
           &&


         //
         // The string is either "Lab" or "Lecture" 
         //
         (courseType == "Lab" or courseType == "Lecture")

  post:
         //
         // The returned course has the id of number and
         // course type of courseType
         //
         (course.id == number and course.courseType == courseType)
  

Parameters:
number - The course number.
courseType - A string representing the course type
Returns:
the Course corresponding to the number and type.

validId

public boolean validId(int id)
Checks if the id is three digits long
  pre: 
         //
         // The id is a number from 100 to 999 
         // 
         (id < 1000 && id > 99 )


  post:

  

Parameters:
id - The id of the course

addCourseTest

public void addCourseTest(Course c)
                   throws CourseDB.CourseExistsException
Same as addCourse, but used for testing purposes. This connects to a test database.
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )

           &&


         //
         // The course is not in the database
         //
         (c not in courseDB.data)

  post:
         //
         // Only c is added to the database
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course == c) or 
                 (course in courseDB.data)))
  

Parameters:
c - The Course to be added.
Throws:
CourseDB.CourseExistsException

addCourse

public void addCourse(Course c)
               throws CourseDB.CourseExistsException
Adds a given course to the course database.
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )

           &&


         //
         // The course is not in the database
         //
         (c not in courseDB.data)

  post:
         //
         // Only c is added to the database
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course == c) or 
                 (course in courseDB.data)))
  

Parameters:
c - The Course to be added.
Throws:
CourseDB.CourseExistsException

getLabs

public java.util.Vector<Course> getLabs()
A method to get all of the lab courses in the Course Database.

Returns:
A Vector of labs in the course database.
  pre: 


  post:
         //
         // The return value contains only labs. 
         //
         (forall (Courses course in returnValue)
             (course.type == "lab")
  

getLabNames

public java.util.Vector<java.lang.String> getLabNames()
A method to get all of the lab course names in the Course Database.

Returns:
A Vector of lab names in the course database.
  pre: 


  post:
         //
         // The return value contains only labs. 
         //
         (forall (Course c)
            if (course.type == "lab") {
               c.name in returnVal
            }
  

getTotalSections

public int getTotalSections()
Returns the total number of sections


editCourseTest

public void editCourseTest(Course c)
The same as editCourse but for testing purposes.
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )


           &&

         //
         // The course c is already in the database
         //
         (c in courseDB.data )


  post:
         //
         // No courses are added to the database 
         //
         (courseDB.data.size() == courseDB.data.size() )

            &&

         //
         // The database is the same as the earlier version except 
         // for the edited course.
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course == c) or 
                 (course in courseDB.data && course.id != c.id )))

  

Parameters:
c - The Course to be edited.

editCourse

public void editCourse(Course c)
Edits a given course which is already in the course database.
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )


           &&

         //
         // The course c is already in the database
         //
         (c in courseDB.data )


  post:
         //
         // No courses are added to the database 
         //
         (courseDB.data.size() == courseDB.data.size() )

            &&

         //
         // The database is the same as the earlier version except 
         // for the edited course.
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course == c) or 
                 (course in courseDB.data && course.id != c.id )))

  

Parameters:
c - The Course to be edited.

removeCourseTest

public void removeCourseTest(Course c)
                      throws CourseDB.CourseDoesNotExistException
The same as removeCourse() but for testing purposes.
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )


           &&

         //
         // The course c is already in the database
         //
         (c in courseDB.data )

  post:
         //
         // The database size is one smaller 
         //
         (courseDB.data.size() == courseDB`.data.size() - 1 )

            &&

         //
         // The database is the same as the earlier version except 
         // for the removed course.
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course != c)))

  

Parameters:
c - The Course to be edited.
Throws:
CourseDB.CourseDoesNotExistException

removeCourse

public void removeCourse(Course c)
                  throws CourseDB.CourseDoesNotExistException
Removes a given, already-exiting course from the course database
  pre: 
         //
         // The course c is valid course
         // 
         (c != null && c.isValidCourse()  )


           &&

         //
         // The course c is already in the database
         //
         (c in courseDB.data )

  post:
         //
         // The database size is one smaller 
         //
         (courseDB.data.size() == courseDB`.data.size() - 1 )

            &&

         //
         // The database is the same as the earlier version except 
         // for the removed course.
         //
         (forall (Courses course)
             (course in courseDB'.data) iff
                ( (course != c)))

  

Parameters:
c - The Course to be edited.
Throws:
CourseDB.CourseDoesNotExistException