de.upb.swtpra05.group03.shuttle
Class TaskPlan

java.lang.Object
  extended byde.upb.swtpra05.group03.shuttle.TaskPlan
All Implemented Interfaces:
Module, TaskPlanInterface

public class TaskPlan
extends java.lang.Object
implements Module, TaskPlanInterface

List of tasks the shuttle has to execute.

Version:
$Revision: 1.3 $

Field Summary
(package private) static java.util.logging.Logger log
          Logger for debugging
private  ShuttleDataInterface shuttleData
          The shuttle data
private  java.util.LinkedList tasks
          The tasks
 
Constructor Summary
TaskPlan()
          Constructor
 
Method Summary
 void activateOrder(de.upb.swtpra.kernel.id.OrderID orderId)
          Activates all tasks which belong to the order id
 void addAsFirstTask(java.lang.Object o)
          Adds a feature to the First attribute of the TaskPlan object
 void addAsLastTask(java.lang.Object o)
          Appends the given TaskPlan to the end of this list.
private  void addRepairAtPos(int pos, int stretchAtPos)
          This method will insert a Repair at the given position and if there is always a task, this task and all behind it will be shifted to the end
 void addTask(int index, java.lang.Object o)
          Adds a task or taskplan to this taskplan.
 void addTaskBeforeLastMove(Task taskToAdd)
          This method will add the given task as the last task at the corresponding station if there is any.
 boolean containsOrderId(de.upb.swtpra.kernel.id.OrderID orderId)
          Returns if taskplan contains order.
 boolean containsStationId(int stationId)
          Returns if taskplan contains station.
private  void deleteAllRepairs()
          Deletes all repair tasks in the taskplan.
 java.util.LinkedList getAllConnectionOkTasks()
          Gets the allConnectionOkTasks attribute of the TaskPlan object
 Task getFirstTask()
          Returns the first task.
 int getHighestCapacity(int baseLoaded)
          This method will loop through all of its tasks and calculate the maximum load at any time.
 int getLastStationOnRoute()
           
 int getLastTaskIndexOf(int stationId)
          This method will retrieve the position of the last Task in the TaskPlan which effects the stationId, e.g. at this point in the task, the shuttle will be at this station.
 java.util.SortedMap getOrderHandlingInfos()
          This method calculates the times until the shuttle will unload the orders and the number of connections between loading and unloading, if loading isn't in the taskplan (it's already executed) then the connections from beginning to unloading.
 java.util.Vector getStringVector()
           
 Task getTask(int i)
          Returns the task at index
 TaskPlanInterface getUseableTaskPlan(int currentTime, int timeUseabilityHasToStart)
          Returns a useable taskplan which contains all tasks after useTime.
 int indexOf(Task task)
          Returns the index of the task
 void init(ModuleContainerInterface manager)
          Initializes this module.
 boolean isSuccessorOf(int startId, int successorId)
          Returns if station with successorId is a successor of station with startId.
 java.util.ListIterator listIterator()
          Returns a list iterator if the taskplan.
 void remove(int index)
          Removes the task at index.
 java.lang.Object removeFirstTask()
          Returns the first task and removes it.
 java.util.LinkedList removeOrder(de.upb.swtpra.kernel.id.OrderID orderId)
          Removes all tasks which belong to the order id
 int size()
          Returns the count of tasks in the taskplan.
protected  int substractRepair(int currentStretch)
          Will return the correct stretch if a repair takes place with the stretch given as a parameter
 java.lang.String toString()
          Returns a string representation.
protected  void updateRepairPlan()
          Updates the repair tasks so we do them at the right time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tasks

private java.util.LinkedList tasks
The tasks


shuttleData

private ShuttleDataInterface shuttleData
The shuttle data


log

static final java.util.logging.Logger log
Logger for debugging

Constructor Detail

TaskPlan

public TaskPlan()
Constructor

Method Detail

init

public void init(ModuleContainerInterface manager)
Description copied from interface: Module
Initializes this module. References to other modules should be set here to avoid circle dependencies.

Specified by:
init in interface Module
Parameters:
manager - The module manager which contain all modules

addTask

public void addTask(int index,
                    java.lang.Object o)
Description copied from interface: TaskPlanInterface
Adds a task or taskplan to this taskplan.

Specified by:
addTask in interface TaskPlanInterface
Parameters:
index - index to add at
o - task or taskplan

remove

public void remove(int index)
Description copied from interface: TaskPlanInterface
Removes the task at index.

Specified by:
remove in interface TaskPlanInterface
Parameters:
index - index of task to remove

getHighestCapacity

public int getHighestCapacity(int baseLoaded)
Description copied from interface: TaskPlanInterface
This method will loop through all of its tasks and calculate the maximum load at any time. That means, if the current load is 4 and the next task is a LoadShuttleTask to load 3 passengers up the return value will be 7. If the 4 passengers got unloaded before loading the 3 people the answer will be 4.

Specified by:
getHighestCapacity in interface TaskPlanInterface
Parameters:
baseLoaded - The current load
Returns:
the highest load over all tasks

getAllConnectionOkTasks

public java.util.LinkedList getAllConnectionOkTasks()
Description copied from interface: TaskPlanInterface
Gets the allConnectionOkTasks attribute of the TaskPlan object

Specified by:
getAllConnectionOkTasks in interface TaskPlanInterface
Returns:
The allConnectionOkTasks value

addTaskBeforeLastMove

public void addTaskBeforeLastMove(Task taskToAdd)
Description copied from interface: TaskPlanInterface
This method will add the given task as the last task at the corresponding station if there is any. If there is not already a task for this station, the task will be added at the end of the taskplan

Specified by:
addTaskBeforeLastMove in interface TaskPlanInterface
Parameters:
taskToAdd - The new Task to add to the taskplan

getLastTaskIndexOf

public int getLastTaskIndexOf(int stationId)
Description copied from interface: TaskPlanInterface
This method will retrieve the position of the last Task in the TaskPlan which effects the stationId, e.g. at this point in the task, the shuttle will be at this station.

Specified by:
getLastTaskIndexOf in interface TaskPlanInterface
Parameters:
stationId - the id of the station whose last task will be returned
Returns:
the position of the last found task in the taskplan

isSuccessorOf

public boolean isSuccessorOf(int startId,
                             int successorId)
Description copied from interface: TaskPlanInterface
Returns if station with successorId is a successor of station with startId.

Specified by:
isSuccessorOf in interface TaskPlanInterface
Parameters:
startId - Description of the Parameter
successorId - Description of the Parameter
Returns:
if successor is realy a successor of start

getLastStationOnRoute

public int getLastStationOnRoute()
Specified by:
getLastStationOnRoute in interface TaskPlanInterface
Returns:
The lastRouteMember value

substractRepair

protected int substractRepair(int currentStretch)
Will return the correct stretch if a repair takes place with the stretch given as a parameter

Parameters:
currentStretch - the stretch before the repair
Returns:
the stretch after a repair has taken place

addRepairAtPos

private void addRepairAtPos(int pos,
                            int stretchAtPos)
This method will insert a Repair at the given position and if there is always a task, this task and all behind it will be shifted to the end

Parameters:
pos - The position where the Repair will be inserted
stretchAtPos - the stretch at this position, needed to calculate the costs correctly

updateRepairPlan

protected void updateRepairPlan()
Updates the repair tasks so we do them at the right time. First removes all but the first if already executed and then iterates through the tasks and inserts repairs where needed.


deleteAllRepairs

private void deleteAllRepairs()
Deletes all repair tasks in the taskplan.


toString

public java.lang.String toString()
Description copied from interface: TaskPlanInterface
Returns a string representation.

Specified by:
toString in interface TaskPlanInterface

addAsFirstTask

public void addAsFirstTask(java.lang.Object o)
Description copied from interface: TaskPlanInterface
Adds a feature to the First attribute of the TaskPlan object

Specified by:
addAsFirstTask in interface TaskPlanInterface
Parameters:
o - The feature to be added to the First attribute

activateOrder

public void activateOrder(de.upb.swtpra.kernel.id.OrderID orderId)
Description copied from interface: TaskPlanInterface
Activates all tasks which belong to the order id

Specified by:
activateOrder in interface TaskPlanInterface
Parameters:
orderId - The order id to activate tasks for

removeOrder

public java.util.LinkedList removeOrder(de.upb.swtpra.kernel.id.OrderID orderId)
Description copied from interface: TaskPlanInterface
Removes all tasks which belong to the order id

Specified by:
removeOrder in interface TaskPlanInterface
Parameters:
orderId - The order if to remove task for
Returns:
Description of the Return Value

getUseableTaskPlan

public TaskPlanInterface getUseableTaskPlan(int currentTime,
                                            int timeUseabilityHasToStart)
Description copied from interface: TaskPlanInterface
Returns a useable taskplan which contains all tasks after useTime.

Specified by:
getUseableTaskPlan in interface TaskPlanInterface
Parameters:
currentTime - current time
timeUseabilityHasToStart - useable time, time from which get all tasks
Returns:
useable taskplan

addAsLastTask

public void addAsLastTask(java.lang.Object o)
Description copied from interface: TaskPlanInterface
Appends the given TaskPlan to the end of this list.

Specified by:
addAsLastTask in interface TaskPlanInterface
Parameters:
o - The feature to be added to the Last attribute

size

public int size()
Description copied from interface: TaskPlanInterface
Returns the count of tasks in the taskplan.

Specified by:
size in interface TaskPlanInterface
Returns:
the count of tasks in the taskplan.

getFirstTask

public Task getFirstTask()
Description copied from interface: TaskPlanInterface
Returns the first task.

Specified by:
getFirstTask in interface TaskPlanInterface
Returns:
the first task

removeFirstTask

public java.lang.Object removeFirstTask()
Description copied from interface: TaskPlanInterface
Returns the first task and removes it.

Specified by:
removeFirstTask in interface TaskPlanInterface
Returns:
the first task

getOrderHandlingInfos

public java.util.SortedMap getOrderHandlingInfos()
Description copied from interface: TaskPlanInterface
This method calculates the times until the shuttle will unload the orders and the number of connections between loading and unloading, if loading isn't in the taskplan (it's already executed) then the connections from beginning to unloading.

Specified by:
getOrderHandlingInfos in interface TaskPlanInterface
Returns:
a sorted map of OrderIDs with their OrderHandlingInfo

getTask

public Task getTask(int i)
Description copied from interface: TaskPlanInterface
Returns the task at index

Specified by:
getTask in interface TaskPlanInterface
Parameters:
i - index of the task to return
Returns:
task at index i

indexOf

public int indexOf(Task task)
Description copied from interface: TaskPlanInterface
Returns the index of the task

Specified by:
indexOf in interface TaskPlanInterface
Parameters:
task - task which index to return
Returns:
index of the task

listIterator

public java.util.ListIterator listIterator()
Description copied from interface: TaskPlanInterface
Returns a list iterator if the taskplan.

Specified by:
listIterator in interface TaskPlanInterface
Returns:
a list iterator if the taskplan

getStringVector

public java.util.Vector getStringVector()
Specified by:
getStringVector in interface TaskPlanInterface
Returns:
The stringVector value

containsStationId

public boolean containsStationId(int stationId)
Description copied from interface: TaskPlanInterface
Returns if taskplan contains station.

Specified by:
containsStationId in interface TaskPlanInterface
Parameters:
stationId - station id
Returns:
if taskplan contains station

containsOrderId

public boolean containsOrderId(de.upb.swtpra.kernel.id.OrderID orderId)
Description copied from interface: TaskPlanInterface
Returns if taskplan contains order.

Specified by:
containsOrderId in interface TaskPlanInterface
Parameters:
orderId - order id
Returns:
if taskplan contains order