scheduler.db.locationdb
Class LocationDB

java.lang.Object
  extended by java.util.Observable
      extended by scheduler.db.locationdb.LocationDB

public class LocationDB
extends java.util.Observable

The class representing the location database.

Author:
Jan Lorenz Soliman

Nested Class Summary
 class LocationDB.AvailabilityTuple
          Class that holds a building, room, and list of availability.
static class LocationDB.LocationDoesNotExistException
          This exception is raised when a location is queried but does not exist.
static class LocationDB.LocationExistsException
          This exception is raised when a location already exists in the collection.
static class LocationDB.NumberInvalidException
          This exception is raised when the inputted number for converting to time is not correct.
 
Field Summary
protected  java.util.Collection<LocationDB.AvailabilityTuple> availability
          A collection of available days.
protected  java.util.Collection<Location> data
          A collection of locations.
private static int NUMDAYSINWEEK
          Constant for the number of days in a week
private static int ROWS
          Constant for the number of rows in a table
 
Constructor Summary
LocationDB()
          Location database constructor
 
Method Summary
 void addLocation(Location l)
          addLocation Adds a given location to the location database pre: // // "location" must be a valid Location // isValidLocation (location, locationdb); post: // // Only "location" was added to "locationdb" // forall (location' in locationdb') (location' in locationdb') iff ((location' = location) or (location' in locationdb));*
 void changeAvailability(java.util.ArrayList<DayAvail> data, Location location)
          Changes the availability stored in the database.
 void editLocation(Location location)
          editLocation edits a given, already-existing Location in the database.
 java.util.ArrayList<DayAvail> getAvailability(Location location)
          Returns the specified location's availability
 java.util.Collection<Location> getData()
          Returns the collection of the data.
 Time getEndTime(int number)
          Converts the inputted value into a corresponding Time object rounded up to the latest half-hour.
 Location getLocation(java.lang.String location)
          Gets the location based on its string representation
 Time getStartTime(int number)
          Converts the inputted value into a corresponding Time object rounded to the earliest half-hour.
private  java.util.ArrayList<DayAvail> initializeAvailability(java.util.ArrayList<DayAvail> avail)
          Initializes seven DayAvail objects and adds them to a list.
protected  boolean isValidLocationDB(LocationDB[] ldb)
          isValidLocationDB checks if the location database is valid.
 void removeLocation(Location l)
          removeLocation removes a given, already existing location from the location database pre: // // "location" must be in "locationdb" // (location in locationdb); post: // // The new database differs from teh old only in the absence of "location" // forall (location':Location) (location' in locationdb) iff ((location' != location) and (location' in locationdb));
 void setData(java.util.Collection<Location> data)
          Sets the data in the locationDB
 void updateAvailability()
          Updates the availability of the location objects in the local database.
 
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

NUMDAYSINWEEK

private static final int NUMDAYSINWEEK
Constant for the number of days in a week

See Also:
Constant Field Values

ROWS

private static final int ROWS
Constant for the number of rows in a table

See Also:
Constant Field Values

data

protected java.util.Collection<Location> data
A collection of locations.


availability

protected java.util.Collection<LocationDB.AvailabilityTuple> availability
A collection of available days.

Constructor Detail

LocationDB

public LocationDB()
Location database constructor

Method Detail

initializeAvailability

private java.util.ArrayList<DayAvail> initializeAvailability(java.util.ArrayList<DayAvail> avail)
Initializes seven DayAvail objects and adds them to a list.

Parameters:
avail - A list of day availability
Returns:
A list with seven days of availability.

getData

public java.util.Collection<Location> getData()
Returns the collection of the data.

Returns:
the collection of location

setData

public void setData(java.util.Collection<Location> data)
Sets the data in the locationDB
  pre:   //
         // The data field is not null
         //
         (data != null)

  post:
         //
         // The data field now equals the parameter. 
         //
         (this.data == data)
  

Parameters:
data - The data to be set.

addLocation

public void addLocation(Location l)
addLocation Adds a given location to the location database pre: // // "location" must be a valid Location // isValidLocation (location, locationdb); post: // // Only "location" was added to "locationdb" // forall (location' in locationdb') (location' in locationdb') iff ((location' = location) or (location' in locationdb));*


editLocation

public void editLocation(Location location)
editLocation edits a given, already-existing Location in the database. pre: // // "old" and "new" cannot be the same // location != nil; && // // "new" must be a valid location // isValidLocation (location, ldb); post: // // A location 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 (location':data) (location' in locationdb') iff (((location == location') or (location in locationdb)) and (location != location'));


removeLocation

public void removeLocation(Location l)
removeLocation removes a given, already existing location from the location database pre: // // "location" must be in "locationdb" // (location in locationdb); post: // // The new database differs from teh old only in the absence of "location" // forall (location':Location) (location' in locationdb) iff ((location' != location) and (location' in locationdb));


getLocation

public Location getLocation(java.lang.String location)
Gets the location based on its string representation
  pre:   //
         //  location contains the '-' character
         //
         (location.contains('-') )

  post:
         //
         //  the returned location's toString() method is equal to
         //  the parameter.
         //
         ( returnVal.toString().equals(location)  ) 
  


isValidLocationDB

protected boolean isValidLocationDB(LocationDB[] ldb)
isValidLocationDB checks if the location database is valid. pre: // // none // post: // // none //


changeAvailability

public void changeAvailability(java.util.ArrayList<DayAvail> data,
                               Location location)
Changes the availability stored in the database.

Parameters:
data - A list of day availability
location - The method will change the specified location's availability

getAvailability

public java.util.ArrayList<DayAvail> getAvailability(Location location)
Returns the specified location's availability

Parameters:
location - The method will change the specified location's availability
Returns:
A list representing a location's availability

updateAvailability

public void updateAvailability()
Updates the availability of the location objects in the local database.


getStartTime

public Time getStartTime(int number)
Converts the inputted value into a corresponding Time object rounded to the earliest half-hour.
  pre:   //
         //  number is between 0 and 30
         //
         (number >= 0 && number < 30)

  post:
         //
         //  the returned time corresponds to the number
         //
         (time.hour = ((number / 2) + 7) && time.minute = (number % 2) * 30 )
  


getEndTime

public Time getEndTime(int number)
Converts the inputted value into a corresponding Time object rounded up to the latest half-hour.
  pre:   //
         //  number is between 0 and 30
         //
         (number >= 0 && number < 30)

  post:
         //
         //  the returned time corresponds to the number
         //
         (time.hour = ((number / 2) + 7) && time.minute = (number % 2) * 30 )