taxisrus.implementation
Class Scheduler

java.lang.Object
  |
  +--taxisrus.implementation.Scheduler
All Implemented Interfaces:
SchedulerInterface

public class Scheduler
extends Object
implements SchedulerInterface


Fields inherited from interface taxisrus.publicinterface.SchedulerInterface
ASK_CABS_ONLY_ONCE, DEFAULT_AVERAGE_WAIT, DEFAULT_MIN_ETA
 
Constructor Summary
Scheduler(ModelInterface new_main_model, int new_average_wait, int new_min_ETA)
          Create a Scheduler, with main_model & other user-defined parameters set as passed into constructor.
Scheduler(ModelInterface new_main_model, MapperInterface new_main_mapper)
          Create an empty Scheduler, using default values for local parameters.
 
Method Summary
 Date addCustomerToQueue(Customer to_pickup)
          Add a new customer to queue of customers waiting to be picked up.
 void assignMapper(MapperInterface new_main_mapper)
          Stores a reference to the main mapper.
 void assignModel(ModelInterface new_main_model)
          Stores a reference to the main model.
 void assignNewAverageWait(int new_average_wait)
          Store a new average_wait.
 void assignNewMinETA(int new_min_ETA)
          Store a new min_ETA.
 void callOffCab(Cab to_cancel, Customer customerToCancel)
          Cancel a cab.
 boolean cancelCustomer(Customer to_cancel)
          Cancel given Customer's ride request.
 Customer changeCustomerCopy(Customer curr_cust, Customer new_cust)
          Finds currCust within the scheduler, and replaces non-sorting or pickup critical fields within currCust to match newCust.
 void confirmCab(Cab to_cancel)
          Confirm a cab reservation.
 boolean customerPickup(int cab_id)
          Function to remove customers from the waiting_for_delivery queue when they reach their destination.
 void customerZonesSet(Customer zone_me)
          Set pickup & destination zones for a customer.
 Customer findCustomer(Customer to_find)
          Check if a customer is in a queue.
 int getAverageWait()
          Get current value of average_wait
 ArrayList getCabsInZone(int zone_id)
          Return a list of cabs for a given zone ID
 int getMinETA()
          Get current value of min_ETA
 void manuallySchedule(Customer reschedule)
          Notify dispatcher that automatic scheduling failed - must be manually scheduled.
 boolean openCommChannel(Cab to_talk_to, Customer to_schedule)
          Open up a communication channel with the given cab, and request that the cab pickup the given customer.
 boolean removeLimboCab(Cab to_remove)
          Remove a cab from the limbo_cabs list, if on the list.
 void scheduleAllCustomers()
          Schedule all customers who have been waiting long enough.
 void transferFromCommingToScheduled(Customer to_transfer)
          Change a customer's status from COMING to SCHEDULED, and re-place in CustomerCollection all_customers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scheduler

public Scheduler(ModelInterface new_main_model,
                 MapperInterface new_main_mapper)
          throws BadParamException
Create an empty Scheduler, using default values for local parameters. Throws exception if a parameter is null.
Parameters:
ModelInterface - new_main_model
MapperInterface - new_main_mapper
Throws:
BadParamException -  

Scheduler

public Scheduler(ModelInterface new_main_model,
                 int new_average_wait,
                 int new_min_ETA)
          throws BadParamException
Create a Scheduler, with main_model & other user-defined parameters set as passed into constructor. This will check to ensure valid parameters, and will throw a BadParamException if a parameter is not valid.
Parameters:
ModelInterface - new_main_model
DataStoreInterface - new_data_store
int - new_average_wait
int - new_min_ETA
Throws:
BadParamException -  
Method Detail

scheduleAllCustomers

public void scheduleAllCustomers()
Schedule all customers who have been waiting long enough. THIS IS ONLY USED BY THE SCHEDULER - Do not use otherwise!

customerZonesSet

public void customerZonesSet(Customer zone_me)
Set pickup & destination zones for a customer.
Parameters:
Customer - zone_me

openCommChannel

public boolean openCommChannel(Cab to_talk_to,
                               Customer to_schedule)
Open up a communication channel with the given cab, and request that the cab pickup the given customer.
Parameters:
Cab - - Cab with which we are talking to
Customer - - Customer who is getting the ride
Returns:
boolean - True if placed, false otherwise

removeLimboCab

public boolean removeLimboCab(Cab to_remove)
Remove a cab from the limbo_cabs list, if on the list.
Parameters:
Cab - to_remove - Cab to remove from limbo_cabs list

transferFromCommingToScheduled

public void transferFromCommingToScheduled(Customer to_transfer)
Change a customer's status from COMING to SCHEDULED, and re-place in CustomerCollection all_customers.
Parameters:
Customer - to_transfer - Customer which will be moved.

callOffCab

public void callOffCab(Cab to_cancel,
                       Customer customerToCancel)
Cancel a cab. Used when a customer is cancelled while in the process of being scheduled.
Parameters:
Cab - - Cab to cancel

confirmCab

public void confirmCab(Cab to_cancel)
Confirm a cab reservation. Used when a customer is scheduled.
Parameters:
Cab - - Cab to reservation

getCabsInZone

public ArrayList getCabsInZone(int zone_id)
Return a list of cabs for a given zone ID
Parameters:
int - - ID of a zone
Returns:
ArrayList - List of cabs available in the zone

manuallySchedule

public void manuallySchedule(Customer reschedule)
Notify dispatcher that automatic scheduling failed - must be manually scheduled. Used when all available cabs refuse customer, and ASK_CABS_ONLY_ONCE is set to true.
Parameters:
Customer - - Customer who could not be scheduled.

getAverageWait

public int getAverageWait()
Get current value of average_wait
Specified by:
getAverageWait in interface SchedulerInterface
Returns:
int average_wait

getMinETA

public int getMinETA()
Get current value of min_ETA
Specified by:
getMinETA in interface SchedulerInterface
Returns:
int min_ETA, in minutes.

assignModel

public void assignModel(ModelInterface new_main_model)
                 throws BadParamException
Stores a reference to the main model. Throws BadParamException if the parameter is null (or otherwise corrupt)
Specified by:
assignModel in interface SchedulerInterface
Parameters:
Model - main_model
Throws:
BadParamException -  

assignMapper

public void assignMapper(MapperInterface new_main_mapper)
                  throws BadParamException
Stores a reference to the main mapper. Throws BadParamException if the parameter is null (or otherwise corrupt)
Specified by:
assignMapper in interface SchedulerInterface
Parameters:
Mapper - main_mapper
Throws:
BadParamException -  

assignNewAverageWait

public void assignNewAverageWait(int new_average_wait)
                          throws BadParamException
Store a new average_wait. Throws BadParamException if new_average_wait < 0.
Specified by:
assignNewAverageWait in interface SchedulerInterface
Parameters:
int - new_average_wait
Throws:
BadParamException -  

assignNewMinETA

public void assignNewMinETA(int new_min_ETA)
                     throws BadParamException
Store a new min_ETA. Throws BadParamException if new_min_ETA < 0.
Specified by:
assignNewMinETA in interface SchedulerInterface
Parameters:
int - new_min_ETA, in minutes.
Throws:
BadParamException -  

addCustomerToQueue

public Date addCustomerToQueue(Customer to_pickup)
Add a new customer to queue of customers waiting to be picked up. Returns an estimated ETA based on queue length, if no cabs are available.
Specified by:
addCustomerToQueue in interface SchedulerInterface
Parameters:
Customer - to_queue - Customer to add to queue
Returns:
Date - Expected time of pickup

findCustomer

public Customer findCustomer(Customer to_find)
Check if a customer is in a queue. Return true if the customer is found.
Specified by:
findCustomer in interface SchedulerInterface
Parameters:
Customer - - Customer to find.
Returns:
Customer - Reference to the customer found. This will have the customer's status.
Will be null if not found.

cancelCustomer

public boolean cancelCustomer(Customer to_cancel)
Cancel given Customer's ride request. Return true if successful. Negative if the customer could not be found, or was not scheduled yet. Will set customers status to RIDE_CANCELLED, and will set customer's cab to null. Will communicate with cab console if neccesary.
Specified by:
cancelCustomer in interface SchedulerInterface
Parameters:
Customer - - Customer to cancel
Returns:
boolean - True if customer was successfully found & cancelled

customerPickup

public boolean customerPickup(int cab_id)
Function to remove customers from the waiting_for_delivery queue when they reach their destination. Should be called by the Model when the CabConsole signals a customer pickup.
Specified by:
customerPickup in interface SchedulerInterface
Parameters:
cab_id - - id of the Cab that just picked up the customer
Returns:
boolean - True if customer was successfully removed.

changeCustomerCopy

public Customer changeCustomerCopy(Customer curr_cust,
                                   Customer new_cust)
Finds currCust within the scheduler, and replaces non-sorting or pickup critical fields within currCust to match newCust. Currently only sets destination address.
Specified by:
changeCustomerCopy in interface SchedulerInterface
Parameters:
Customer - currCust - Old customer as stored in Scheduler
Customer - newCust - New customer to replace currCust in Scheduler


API documentation for build 958