jfreerails.world.train
Class MutableSchedule

java.lang.Object
  extended by jfreerails.world.train.MutableSchedule
All Implemented Interfaces:
Schedule

public class MutableSchedule
extends java.lang.Object
implements Schedule

This class represents a train's schedule. That is, which stations that the train should visit and what wagons the engine should pull.

Author:
lindsal

Field Summary
private  boolean hasPriorityOrders
          Whether the train should ignore the stationToGoto and goto the first station in the list.
private  int nextScheduledOrder
           
private  java.util.Vector<TrainOrdersModel> orders
          Vector of TrainOrdersModel.
 
Fields inherited from interface jfreerails.world.train.Schedule
MAXIMUM_NUMBER_OF_ORDER, PRIORITY_ORDERS
 
Constructor Summary
MutableSchedule()
           
MutableSchedule(ImmutableSchedule s)
           
 
Method Summary
 void addOrder(int orderNumber, TrainOrdersModel order)
          Inserts an order at the specified position.
 int addOrder(TrainOrdersModel order)
           
 boolean autoConsist()
          Returns the value for the autoconsist flag at the next scheduled stop.
 boolean canAddOrder()
           
 boolean canPullUp(int orderNumber)
           
 boolean canPushDown(int orderNumber)
           
 boolean canSetGotoStation(int orderNumber)
           
private  int firstScheduleStop()
           
 int getNextScheduledOrder()
           
 int getNumOrders()
          Returns number of non priority orders + number of priority orders.
 TrainOrdersModel getOrder(int i)
           
 int getOrderToGoto()
          Returns the number of the order the train is currently carry out.
 int getStationToGoto()
          Returns the station number of the next station the train is scheduled to stop at.
 ImInts getWagonsToAdd()
          Returns the wagons to add at the next scheduled stop.
 void gotoNextStaton()
          If there are no priority orders, sets the station to goto to the next station in the list of orders or if there are no more stations, the first station in the list.
 boolean hasPriorityOrders()
           
private  int numberOfScheduledStops()
           
 void pullUp(int orderNumber)
           
 void pushDown(int orderNumber)
           
 void removeAllStopsAtStation(int stationNumber)
           
 void removeOrder(int orderNumber)
          Removes the order at the specified position.
 void setOrder(int orderNumber, TrainOrdersModel order)
           
 void setOrderToGoto(int i)
           
 void setPriorityOrders(TrainOrdersModel order)
           
 ImmutableSchedule toImmutableSchedule()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

orders

private final java.util.Vector<TrainOrdersModel> orders
Vector of TrainOrdersModel.


nextScheduledOrder

private int nextScheduledOrder

hasPriorityOrders

private boolean hasPriorityOrders
Whether the train should ignore the stationToGoto and goto the first station in the list.

Constructor Detail

MutableSchedule

public MutableSchedule()

MutableSchedule

public MutableSchedule(ImmutableSchedule s)
Method Detail

toImmutableSchedule

public ImmutableSchedule toImmutableSchedule()

setPriorityOrders

public void setPriorityOrders(TrainOrdersModel order)

removeOrder

public void removeOrder(int orderNumber)
Removes the order at the specified position.


firstScheduleStop

private int firstScheduleStop()

numberOfScheduledStops

private int numberOfScheduledStops()

addOrder

public void addOrder(int orderNumber,
                     TrainOrdersModel order)
Inserts an order at the specified position. Note you must call setPriorityOrders() to set the priority orders.


addOrder

public int addOrder(TrainOrdersModel order)

setOrder

public void setOrder(int orderNumber,
                     TrainOrdersModel order)

getOrder

public TrainOrdersModel getOrder(int i)
Specified by:
getOrder in interface Schedule

getOrderToGoto

public int getOrderToGoto()
Returns the number of the order the train is currently carry out.

Specified by:
getOrderToGoto in interface Schedule

setOrderToGoto

public void setOrderToGoto(int i)

getStationToGoto

public int getStationToGoto()
Returns the station number of the next station the train is scheduled to stop at.

Specified by:
getStationToGoto in interface Schedule

getWagonsToAdd

public ImInts getWagonsToAdd()
Returns the wagons to add at the next scheduled stop.

Specified by:
getWagonsToAdd in interface Schedule

gotoNextStaton

public void gotoNextStaton()
If there are no priority orders, sets the station to goto to the next station in the list of orders or if there are no more stations, the first station in the list. If priority orders are set, the priority orders orders are removed from the schedule and the goto station is not changed.


hasPriorityOrders

public boolean hasPriorityOrders()
Specified by:
hasPriorityOrders in interface Schedule

getNumOrders

public int getNumOrders()
Returns number of non priority orders + number of priority orders.

Specified by:
getNumOrders in interface Schedule
Returns:
Number of orders.

canPullUp

public boolean canPullUp(int orderNumber)

canPushDown

public boolean canPushDown(int orderNumber)

pullUp

public void pullUp(int orderNumber)

pushDown

public void pushDown(int orderNumber)

canAddOrder

public boolean canAddOrder()

canSetGotoStation

public boolean canSetGotoStation(int orderNumber)

getNextScheduledOrder

public int getNextScheduledOrder()
Specified by:
getNextScheduledOrder in interface Schedule

removeAllStopsAtStation

public void removeAllStopsAtStation(int stationNumber)

autoConsist

public boolean autoConsist()
Description copied from interface: Schedule
Returns the value for the autoconsist flag at the next scheduled stop.

Specified by:
autoConsist in interface Schedule