taxisrus.implementation
Class Model

java.lang.Object
  |
  +--taxisrus.implementation.Model
All Implemented Interfaces:
ModelInterface

public class Model
extends Object
implements ModelInterface


Constructor Summary
Model()
          Default Model constructor; activates the Mapper UI automatically.
Model(boolean activateMapperUI)
          Model constructor
PRECONDITION: Mapper has already been fired up
POSTCONDITION: _storage, _mapper, _zoneList, _storage initiallized
Model(int testNumZones, int testPickupZoneID, int testDestZoneID)
          Model constructor for testing.
Model(String dbServerName, String dbUserName, String dbUserPassword, Boolean useNewDB)
          Model constructor, takes database info activates the Mapper UI automatically.
 
Method Summary
 Date addCustomer(Customer customer)
          Adds a customer in system.
PRECONDITION: Customer must have the following information set already:
- call-in time
- pickup address
- pickup time
- destination address
POSTCONDITION: customer's information is set
scheduler now has customer within domain
datastore knows of ride request
 boolean cabIsScheduled(Cab cab)
          Mark cab as scheduled.
 void cabRefusedRide(int cab_id, int zone_id)
          Called when the cab refuses a ride
we must update the cab in the model to be placed in the back
PRECONDITION:
POSTCONDITION:
 void cancelCab(int cab_id, Customer cancelledCustomer)
          Cancels scheduled cab, assumes customer field in cab is set
scheduler calls when cancelled customer not found in waiting customer queue
and msg needs to be relayed to cab console, cab will be placed back into front of zone which cab is found in
assume customer's cab field will be set elsewhere (by scheduler)
PRECONDITION: customer corresponding to cab has been canceled
POSTCONDITION: cab is still in busy cab list, everything but zone is set correctly
 Boolean cancelCustomer(String customerPhone, String customerLastName, String customerFirstName)
          Cancel the customer, returns true for successful cancellation
 Date changeCustomer(Customer oldCustCopy, Customer newCust)
          Changes customer in the system For Dispatcher UI
 Vector getAllBusyCabs()
          Returns the list of busy cabs.
PRECONDITION: none
POSTCONDITION: none
 Vector getArrivingCabs(int zone_id)
          Returns all arriving cabs to specified zone;
to be used when no cabs available in desired zone.
Assumes that the customer field in the cab is set correctly
 Cab getBusyCab(int cab_id)
          Gets (but does NOT remove) the cab with cab_id from the busy list.
-used during actual customer pick-up
PRECONDITION: none
POSTCONDITION: none
 Vector getBusyCabsInZone(int zone_id)
          Returns list of busy cabs in specified zone (destination zone of busy cab)
PRECONDITION: none
POSTCONDITION: none
 Cab getCab(int cab_id)
          Returns referenced Cab object from zone list--does not remove cab
PRECONDITION: cab is waiting in a zone
POSTCONDITION: none
 Customer getCustomer(String customerPhone, String customerLastName, String customerFirstName)
          Returns the Customer identified by the phone number and last name
PRECONDITION: scheduler contains the target customer
POSTCONDITION: none
 ManagerReport getManagerReport(int typeOfReport, int specificity, int timeInterval, Date from, Date to)
          Passes ManagerReport request from ManagerUI to DataStore
 Vector getOpenCabs(int zone_id)
          Returns all open cabs within specified zone.
PRECONDITION: none
POSTCONDITION: none
 Scheduler getScheduler()
          Accessor used in testing
 Zone getZone(int zone_id)
          Returns specified zone.
PRECONDITION: zone_id is a legal zone
POSTCONDITION: none
 boolean isCreditCardAccepted(double chargedAmount, String creditCardNumber)
          "Approve" credit card
-- passes the charge amount and creditCardNumber to bank and sees if the card is approved
PRECONDITION: none
POSTCONDITION: none
 boolean manualDispatchCab(Cab cab, Customer customer)
          Dispatches specified cab to specified customer (NOT YET IMPLEMENTED).
 Boolean registerCabToModel(CabConsoleInterface cabConsole, int cab_id, int driver_id, String gps)
          registers the cab in the model if cab_id and driver_id are valid (in database)
PRECONDITION: both cab and driver identified by cab_id and driver_id registers for the first time.
POSTCONDITION: a cab object corresponding to the cab console has been created and placed in its respective zone in the model
 Cab removeBusyCab(int cab_id)
          Removes the cab with cab_id from the busy list.
PRECONDITION: target cab is currently busy
POSTCONDITION: target cab removed from the busy list
 void rescheduleCustomer(Customer failedScheduling)
          Passes a customer object to a DispatcherUI object for rescheduling.
 boolean rideRequest(Customer iWannaRide, int cab_id)
          For Scheduler
Relays ride request from scheduler to cab console
Responsible only for relaying messages
PRECONDITION: valid cab id
cab currently in the model
POSTCONDITION: none
 CabConsoleImplementation unitTest_getCabConsole(int cab_id)
           
 boolean unitTest_moveCabFromBusyToZone(int cab_id, int zone_id, boolean front)
          unit test only
 boolean unitTest_moveCabFromZoneToBusy(int cab_id, int zone_id, int destZoneID)
          unit test only
 void unitTest_pretendBusyCabs()
          Unit test helper method setup an instance in time in which there are busy cabs in the "world."
This function will create an instance in which:
cab1 has picked up cust1 cab2 has picked up cust2 cust0 and cust3 are waiting PRECONDITIONS: test_setupInitialWorld was just called.
 void unitTest_pretendCustomersAreWaitingAndScheduled()
          Unit test helper method to setup an instance in time in which there are customers waiting.
This function will create an instance in which:
cust2 has been scheduled.
 Cab unitTest_removeCabFromZone(int cab_id, int zone_id)
          unit test only
 void unitTest_setCabConsoleAccepts(boolean cabAccepts)
           
 boolean updateModelCabInfo(String cab_info)
          For Cab Console:
Called after console updates referenced cab object, this method triggers necessary
model updates
Case 0: customer dropped off
Case 2: customer has been picked up
Case 3: customer has canceled and cab has been canceled
PRECONDITION: cab console has changed its status and needs to be updated in the model
case 0: cab is busy
case 2: none
case 3: cab has been emptied of its customer and is in the busy cab list
POSTCONDITION: case 0: cab is waiting in its appropriate zone
case 2: pickup time for customer in database has been updated
case 3: cab waiting at front of zone's cab list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model()
Default Model constructor; activates the Mapper UI automatically.

Model

public Model(String dbServerName,
             String dbUserName,
             String dbUserPassword,
             Boolean useNewDB)
Model constructor, takes database info activates the Mapper UI automatically.

Model

public Model(boolean activateMapperUI)
Model constructor
PRECONDITION: Mapper has already been fired up
POSTCONDITION: _storage, _mapper, _zoneList, _storage initiallized
Parameters:
activateMapperUI - if true then mapperUI is activated; false, otherwise.

Model

public Model(int testNumZones,
             int testPickupZoneID,
             int testDestZoneID)
Model constructor for testing.
Parameters:
testNumZones - the number of zones to create
testPickupZone - the default ID of pickup zone of customers
testDestZone - the default ID of destination zone of customers
Method Detail

addCustomer

public Date addCustomer(Customer customer)
Adds a customer in system.
PRECONDITION: Customer must have the following information set already:
- call-in time
- pickup address
- pickup time
- destination address
POSTCONDITION: customer's information is set
scheduler now has customer within domain
datastore knows of ride request
Specified by:
addCustomer in interface ModelInterface
Parameters:
customer - customer object to be added
Returns:
ETA the estimated pickup time

getCustomer

public Customer getCustomer(String customerPhone,
                            String customerLastName,
                            String customerFirstName)
Returns the Customer identified by the phone number and last name
PRECONDITION: scheduler contains the target customer
POSTCONDITION: none
Specified by:
getCustomer in interface ModelInterface
Parameters:
customerPhone -  
customerLastName -  
Returns:
customer that matches the phone and name

getCab

public Cab getCab(int cab_id)
Returns referenced Cab object from zone list--does not remove cab
PRECONDITION: cab is waiting in a zone
POSTCONDITION: none
Specified by:
getCab in interface ModelInterface
Returns:
if cab is in the model and currently available, return the cab, else return null

getBusyCabsInZone

public Vector getBusyCabsInZone(int zone_id)
Returns list of busy cabs in specified zone (destination zone of busy cab)
PRECONDITION: none
POSTCONDITION: none
Specified by:
getBusyCabsInZone in interface ModelInterface
Returns:
Vector list of cabs in the zone

removeBusyCab

public Cab removeBusyCab(int cab_id)
Removes the cab with cab_id from the busy list.
PRECONDITION: target cab is currently busy
POSTCONDITION: target cab removed from the busy list
Returns:
the cab with cab_id removed from the busy list. If the cab with cab_id is not in the busy list, returns null.

getBusyCab

public Cab getBusyCab(int cab_id)
Gets (but does NOT remove) the cab with cab_id from the busy list.
-used during actual customer pick-up
PRECONDITION: none
POSTCONDITION: none
Specified by:
getBusyCab in interface ModelInterface
Returns:
the cab with cab_id taken from the busy list. If the cab with cab_id is not in the busy list, returns null.

getAllBusyCabs

public Vector getAllBusyCabs()
Returns the list of busy cabs.
PRECONDITION: none
POSTCONDITION: none
Specified by:
getAllBusyCabs in interface ModelInterface
Returns:
Vector list of busy cabs

getZone

public Zone getZone(int zone_id)
Returns specified zone.
PRECONDITION: zone_id is a legal zone
POSTCONDITION: none
Specified by:
getZone in interface ModelInterface
Parameters:
zone_id - ID of requested zone
Returns:
the requested zone object

manualDispatchCab

public boolean manualDispatchCab(Cab cab,
                                 Customer customer)
Dispatches specified cab to specified customer (NOT YET IMPLEMENTED).
Specified by:
manualDispatchCab in interface ModelInterface
Parameters:
cab - the cab to be dispatched
customer - the customer that will be picked up
Returns:
True if the cab is dispatched to customer; false, otherwise.

getOpenCabs

public Vector getOpenCabs(int zone_id)
Returns all open cabs within specified zone.
PRECONDITION: none
POSTCONDITION: none
Specified by:
getOpenCabs in interface ModelInterface
Parameters:
zone_id - zone to get cabs from
Returns:
Vector list containing all available cabs within zone

getArrivingCabs

public Vector getArrivingCabs(int zone_id)
Returns all arriving cabs to specified zone;
to be used when no cabs available in desired zone.
Assumes that the customer field in the cab is set correctly
Specified by:
getArrivingCabs in interface ModelInterface
Parameters:
zone_id - the ID of the zone from which to get arriving cabs
Returns:
all arriving cabs to specified zone

rideRequest

public boolean rideRequest(Customer iWannaRide,
                           int cab_id)
For Scheduler
Relays ride request from scheduler to cab console
Responsible only for relaying messages
PRECONDITION: valid cab id
cab currently in the model
POSTCONDITION: none
Specified by:
rideRequest in interface ModelInterface
Parameters:
Customer - who requests ride
cab_id - of cab to request
Returns:
true if cab console confirms request

cancelCab

public void cancelCab(int cab_id,
                      Customer cancelledCustomer)
Cancels scheduled cab, assumes customer field in cab is set
scheduler calls when cancelled customer not found in waiting customer queue
and msg needs to be relayed to cab console, cab will be placed back into front of zone which cab is found in
assume customer's cab field will be set elsewhere (by scheduler)
PRECONDITION: customer corresponding to cab has been canceled
POSTCONDITION: cab is still in busy cab list, everything but zone is set correctly
Specified by:
cancelCab in interface ModelInterface
Parameters:
cab_id - of cab to cancel

cabIsScheduled

public boolean cabIsScheduled(Cab cab)
Mark cab as scheduled. It is assumed that a customer has been matched with a cab, that is, its member variable for a customer is set.
PRECONDITION: cab has been assigned a customer
POSTCONDITION: scheduler has knowledge of cab/customer assignment
Specified by:
cabIsScheduled in interface ModelInterface
Parameters:
cab - is the busy cab (reservation)
Returns:
true if successful update in model

cabRefusedRide

public void cabRefusedRide(int cab_id,
                           int zone_id)
Called when the cab refuses a ride
we must update the cab in the model to be placed in the back
PRECONDITION:
POSTCONDITION:
Specified by:
cabRefusedRide in interface ModelInterface
Parameters:
cab_id - ID of cab that refused
zone_id - ID of zone where cab is located

cancelCustomer

public Boolean cancelCustomer(String customerPhone,
                              String customerLastName,
                              String customerFirstName)
Cancel the customer, returns true for successful cancellation
Specified by:
cancelCustomer in interface ModelInterface
Parameters:
customer_id -  
customerLastName -  
Returns:
Boolean object (NOT PRIMITIVE!)

changeCustomer

public Date changeCustomer(Customer oldCustCopy,
                           Customer newCust)
Changes customer in the system For Dispatcher UI
Specified by:
changeCustomer in interface ModelInterface
Parameters:
old - customer - copy
new - customer
Returns:
ETA of changed customer, if null, customer was not found anymore or customer did not/could not be changed --- Design Decisions --- A change customer request essentially falls in two catagories: Changes that require a customer reschedule, and Changes that require only a update of customer fields in various places in system ( in our case, destination address change only ) A change customer request can find the custmer in two states inside the scheduler: before or after cab assignment. If one of 3 fields in customer changed: pickup addr, pickup time, #riders then reschedule customer, otherwise just update in appropriate places In case of reschedule, call to cancel customer will percolate to scheduler, db, and cab console if necessary.

updateModelCabInfo

public boolean updateModelCabInfo(String cab_info)
For Cab Console:
Called after console updates referenced cab object, this method triggers necessary
model updates
Case 0: customer dropped off
Case 2: customer has been picked up
Case 3: customer has canceled and cab has been canceled
PRECONDITION: cab console has changed its status and needs to be updated in the model
case 0: cab is busy
case 2: none
case 3: cab has been emptied of its customer and is in the busy cab list
POSTCONDITION: case 0: cab is waiting in its appropriate zone
case 2: pickup time for customer in database has been updated
case 3: cab waiting at front of zone's cab list
Specified by:
updateModelCabInfo in interface ModelInterface
Parameters:
must - be in this format:
"cab_id \n status \n gps \n meter \n mileage \n pickuptime", or
"cab_id \n status \n date"
where status = 0 dropped off customer, 1 accepted fare, 2 picked up customer
where date = Date.toString()
assumes: cab_id is int,
gps is "(,)",
meter is double, status is true or false,
ride mileage is float

registerCabToModel

public Boolean registerCabToModel(CabConsoleInterface cabConsole,
                                  int cab_id,
                                  int driver_id,
                                  String gps)
registers the cab in the model if cab_id and driver_id are valid (in database)
PRECONDITION: both cab and driver identified by cab_id and driver_id registers for the first time.
POSTCONDITION: a cab object corresponding to the cab console has been created and placed in its respective zone in the model
Specified by:
registerCabToModel in interface ModelInterface
Returns:
true if both id's are valid, false otherwise

isCreditCardAccepted

public boolean isCreditCardAccepted(double chargedAmount,
                                    String creditCardNumber)
Description copied from interface: ModelInterface
"Approve" credit card
-- passes the charge amount and creditCardNumber to bank and sees if the card is approved
PRECONDITION: none
POSTCONDITION: none
Specified by:
isCreditCardAccepted in interface ModelInterface
Following copied from interface: taxisrus.publicinterface.ModelInterface
Parameters:
chargedAmount - amount to charge
creditCardNumber - credit card number
Returns:
whether the card was accepted

getManagerReport

public ManagerReport getManagerReport(int typeOfReport,
                                      int specificity,
                                      int timeInterval,
                                      Date from,
                                      Date to)
Passes ManagerReport request from ManagerUI to DataStore
Specified by:
getManagerReport in interface ModelInterface
Parameters:
typeOfReport - - type of report
specificity -  
timeInterval -  
from - - starting date for query
to - - ending date for query
Returns:
the manager report

rescheduleCustomer

public void rescheduleCustomer(Customer failedScheduling)
Passes a customer object to a DispatcherUI object for rescheduling. Used if automatic scheduling fails and SchedulerInterface.ASK_CABS_ONLY_ONCE is set to true.
Specified by:
rescheduleCustomer in interface ModelInterface
Parameters:
Customer - - Customer who needs to be manually scheduled.

getScheduler

public Scheduler getScheduler()
Accessor used in testing
Returns:
Scheduler - The scheduler stored in the Model

unitTest_pretendBusyCabs

public void unitTest_pretendBusyCabs()
Unit test helper method setup an instance in time in which there are busy cabs in the "world."
This function will create an instance in which:
  • cab1 has picked up cust1
  • cab2 has picked up cust2
  • cust0 and cust3 are waiting PRECONDITIONS: test_setupInitialWorld was just called.

  • unitTest_pretendCustomersAreWaitingAndScheduled

    public void unitTest_pretendCustomersAreWaitingAndScheduled()
    Unit test helper method to setup an instance in time in which there are customers waiting.
    This function will create an instance in which:
  • cust2 has been scheduled.
  • cab3 has picked up cust3. PRECONDITIONS: test_setupInitialWorld was just called.

  • unitTest_getCabConsole

    public CabConsoleImplementation unitTest_getCabConsole(int cab_id)

    unitTest_setCabConsoleAccepts

    public void unitTest_setCabConsoleAccepts(boolean cabAccepts)

    unitTest_moveCabFromZoneToBusy

    public boolean unitTest_moveCabFromZoneToBusy(int cab_id,
                                                  int zone_id,
                                                  int destZoneID)
    unit test only

    unitTest_moveCabFromBusyToZone

    public boolean unitTest_moveCabFromBusyToZone(int cab_id,
                                                  int zone_id,
                                                  boolean front)
    unit test only

    unitTest_removeCabFromZone

    public Cab unitTest_removeCabFromZone(int cab_id,
                                          int zone_id)
    unit test only


    API documentation for build 958