public class TrackModel extends java.lang.Object implements TrackModelInterface
TrackModel.init();
To initalize with some test data loaded:
TrackModel.initWithTestData();
Modifier and Type | Field and Description |
---|---|
protected static double |
ACCUMULATION_RATE |
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> |
blockAuthority |
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> |
blockOccupancy |
protected java.util.HashMap<java.lang.Integer,java.lang.Double> |
blockSpeed |
protected java.sql.Connection |
conn |
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> |
crossingState |
protected static int |
FREEZING |
protected int |
last_updated |
protected java.util.Random |
random |
protected java.util.HashMap<java.lang.Integer,StaticBlock> |
staticBlockCache |
protected java.util.HashMap<java.lang.Integer,StaticSwitch> |
staticSwitchCache |
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> |
switchState |
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<StaticBlock>> |
trainOccupancy |
protected java.util.HashMap<java.lang.Integer,java.lang.Double> |
waitingPassengers |
Modifier | Constructor and Description |
---|---|
protected |
TrackModel()
Constructs the Track Model (privately).
|
Modifier and Type | Method and Description |
---|---|
protected void |
accumulateWaitingPassengers(double accumulationRate,
int timeUnits)
Accumulate passengers at all stations over time.
|
protected void |
clearDB()
Truncates all tables in database
|
boolean |
exportTrack(java.io.File file)
Exports a model of the track to a file.
|
boolean |
getAuthority(int blockId)
Gets the authority of a block.
|
java.util.ArrayList<java.lang.Integer> |
getBlockIds()
Gets the block ids
|
boolean |
getCrossingState(int blockId)
Gets the crossing state.
|
double |
getGrade(int trainId)
Gets the grade of the block a train is on.
|
boolean |
getSignal(int blockId)
Gets the signal of a block.
|
StaticBlock |
getStaticBlock(int blockId)
Gets the static block info for a given id.
|
protected StaticBlock |
getStaticBlock(int blockId,
StaticSwitch staticSwitch)
Gets the static block.
|
StaticSwitch |
getStaticSwitch(int switchId)
Gets the static switch.
|
StaticTrack |
getStaticTrack()
Generates and returns a static track.
|
protected BlockStatus |
getStatus(int blockId)
Gets the status of a block.
|
boolean |
getSwitch(int blockId)
Gets the switch state.
|
java.util.ArrayList<java.lang.Integer> |
getSwitchIds()
Gets the switch ids
|
static TrackModel |
getTrackModel()
Initialize/get the track model.
|
boolean |
getTrainAuthority(int trainId)
Gets the train's commanded authority.
|
int |
getTrainBeacon(int trainId)
Returns beacon information if train in within range of a beacon.
|
protected int |
getTrainBlock(int trainId)
Gets the train's current block (internal use only)
|
boolean |
getTrainBlockChange(int trainId)
Gets the train block change.
|
java.util.ArrayList<java.lang.Integer> |
getTrainIds()
Gets the train ids
|
protected boolean |
getTrainLoadedPassenger(int trainId)
Gets the train's loaded passenger flag
|
protected Train |
getTrainModelFromTrainTracker(int trainId) |
int |
getTrainPassengers(int trainId)
Gets the number of passengers disembarked on a train.
|
protected double |
getTrainPosition(int trainId)
Gets the train's current position (internal use only)
|
protected boolean |
getTrainReportedBlockChange(int trainId)
Gets the train's reported block change flag
|
protected boolean |
getTrainReportedPassenger(int trainId)
Gets the train's reported passenger flag
|
double |
getTrainSpeed(int trainId)
Gets the train's suggested speed.
|
boolean |
importTrack(java.io.File file)
Imports a model of the track from a file.
|
static TrackModel |
init()
Initializes the Track Mdel
|
boolean |
initializeTrain(int trainId,
int starting_blockId)
Initialize a new train
|
static TrackModel |
initWithTestData()
Initialize the track model.
|
boolean |
isIcyTrack(int trainId)
Determines if track is icy.
|
boolean |
isOccupied(int blockId)
Determines if a block occupied.
|
TrackModel |
loadTestData()
load test data.
|
protected StaticBlock |
nextBlock(StaticBlock curr_block,
boolean direction)
{ function_description }
|
protected boolean |
nextDirection(StaticBlock curr_block,
StaticBlock next_block)
determines a new direction based on current and next block
|
boolean |
setAuthority(int blockId,
boolean authority)
Sets the authority.
|
protected boolean |
setBidirectional(int blockId,
boolean bidirectional)
Sets whether the block is bidirectional.
|
protected boolean |
setCrossing(int blockId,
boolean rr_crossing)
Sets whether the block has a rr_crossing.
|
boolean |
setCrossingState(int blockId,
boolean active)
Sets the crossing state.
|
protected boolean |
setElevation(int blockId,
double elevation)
Sets the elevation of a block.
|
protected boolean |
setGrade(int blockId,
double grade)
Sets the grade of a block.
|
protected boolean |
setHeater(int blockId,
boolean heater)
Sets whether the block has a heater.
|
protected boolean |
setLength(int blockId,
double length)
Sets the length of a block.
|
protected java.lang.String |
setLine(int blockId,
java.lang.String line)
Sets the block's line.
|
protected boolean |
setOccupied(int blockId,
boolean occupied)
Sets whether or not a block is occupied.
|
boolean |
setOperational(int blockId) |
protected void |
setRandom(java.util.Random r)
This is useful for forcing random during testing
|
protected boolean |
setRegion(int blockId,
java.lang.String region)
Sets the region of a block.
|
boolean |
setRepair(int blockId) |
boolean |
setSignal(int blockId,
boolean active)
Sets the signal on a block.
|
double |
setSpeed(int blockId,
double speed)
Sets the suggested speed.
|
protected boolean |
setSpeedLimit(int blockId,
double speed_limit)
Sets the speed_limit of a block.
|
void |
setStaticBlockUpdate(int blockId) |
protected java.lang.String |
setStation(int blockId,
java.lang.String station)
Sets the block's station.
|
protected BlockStatus |
setStatus(int blockId,
BlockStatus status)
Sets the status of a block.
|
boolean |
setSwitch(int blockId,
boolean active)
Sets the switch.
|
protected int |
setTrainBlock(int trainId,
int block)
Sets the train's current block (internal use only)
|
protected boolean |
setTrainDirection(int trainId,
boolean direction)
Gets the train's current direction (internal use only)
|
protected boolean |
setTrainLoadedPassenger(int trainId,
boolean loaded_passengers)
Sets the train's loaded passenger flag (internal use only)
|
protected boolean |
setTrainReportedBlockChange(int trainId,
boolean reported_change)
Sets the train's reported block change flag (internal use only)
|
protected boolean |
setTrainReportedPassenger(int trainId,
boolean reported_passengers)
Sets the train's reported passenger flag (internal use only)
|
protected boolean |
setUnderground(int blockId,
boolean underground)
Sets whether the block is underground.
|
protected void |
update()
update the state of the track model.
|
protected void |
updateOccupancies()
update the occupancy status of each block on the track
|
protected void |
updateTrain(int trainId)
updates the location of a train on the track
|
protected static final int FREEZING
protected static final double ACCUMULATION_RATE
protected java.sql.Connection conn
protected int last_updated
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<StaticBlock>> trainOccupancy
protected java.util.HashMap<java.lang.Integer,StaticBlock> staticBlockCache
protected java.util.HashMap<java.lang.Integer,StaticSwitch> staticSwitchCache
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> blockOccupancy
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> blockAuthority
protected java.util.HashMap<java.lang.Integer,java.lang.Double> blockSpeed
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> switchState
protected java.util.HashMap<java.lang.Integer,java.lang.Boolean> crossingState
protected java.util.HashMap<java.lang.Integer,java.lang.Double> waitingPassengers
protected java.util.Random random
protected TrackModel()
public static TrackModel getTrackModel()
public static TrackModel init()
public static TrackModel initWithTestData()
public TrackModel loadTestData()
protected void setRandom(java.util.Random r)
r
- the new random object to setpublic boolean importTrack(java.io.File file)
file
- The file to importpublic boolean exportTrack(java.io.File file)
file
- The file to export toprotected void clearDB()
public boolean isOccupied(int blockId)
isOccupied
in interface TrackModelInterface
blockId
- The block identifierprotected boolean setOccupied(int blockId, boolean occupied)
blockId
- The block identifieroccupied
- The occupiedpublic java.util.ArrayList<java.lang.Integer> getBlockIds()
public java.util.ArrayList<java.lang.Integer> getSwitchIds()
public java.util.ArrayList<java.lang.Integer> getTrainIds()
public StaticBlock getStaticBlock(int blockId)
getStaticBlock
in interface TrackModelInterface
blockId
- The block identifierprotected StaticBlock getStaticBlock(int blockId, StaticSwitch staticSwitch)
blockId
- The block identifierstaticSwitch
- The static switchpublic StaticSwitch getStaticSwitch(int switchId)
getStaticSwitch
in interface TrackModelInterface
switchId
- The switch identifierprotected boolean setRegion(int blockId, java.lang.String region)
blockId
- The block identifierregion
- The regionprotected boolean setLength(int blockId, double length)
blockId
- The block identifierlength
- The lengthprotected boolean setSpeedLimit(int blockId, double speed_limit)
blockId
- The block identifierspeed_limit
- The speed_limitprotected boolean setElevation(int blockId, double elevation)
blockId
- The block identifierelevation
- The elevationprotected boolean setGrade(int blockId, double grade)
blockId
- The block identifiergrade
- The gradepublic boolean setSwitch(int blockId, boolean active)
setSwitch
in interface TrackModelInterface
blockId
- The block identifieractive
- The activepublic boolean getSwitch(int blockId)
getSwitch
in interface TrackModelInterface
blockId
- The block identifierpublic boolean setAuthority(int blockId, boolean authority)
setAuthority
in interface TrackModelInterface
blockId
- The block identifierauthority
- The authoritypublic boolean getAuthority(int blockId)
blockId
- The block identifierpublic double setSpeed(int blockId, double speed)
setSpeed
in interface TrackModelInterface
blockId
- The block identifierspeed
- The speedpublic boolean getCrossingState(int blockId)
getCrossingState
in interface TrackModelInterface
blockId
- The block identifierpublic boolean setCrossingState(int blockId, boolean active)
setCrossingState
in interface TrackModelInterface
blockId
- The block identifieractive
- The activepublic boolean setSignal(int blockId, boolean active)
setSignal
in interface TrackModelInterface
blockId
- The block identifieractive
- The valuepublic boolean getSignal(int blockId)
getSignal
in interface TrackModelInterface
blockId
- The block identifierpublic boolean initializeTrain(int trainId, int starting_blockId)
trainId
- The train identifierstarting_blockId
- The starting block idpublic boolean getTrainAuthority(int trainId)
getTrainAuthority
in interface TrackModelInterface
trainId
- The train identifierpublic double getTrainSpeed(int trainId)
getTrainSpeed
in interface TrackModelInterface
trainId
- The train identifierpublic int getTrainBeacon(int trainId)
getTrainBeacon
in interface TrackModelInterface
trainId
- The train identifierpublic boolean isIcyTrack(int trainId)
isIcyTrack
in interface TrackModelInterface
trainId
- The train identifierpublic double getGrade(int trainId)
getGrade
in interface TrackModelInterface
trainId
- The train identifierprotected BlockStatus getStatus(int blockId)
blockId
- The block identifierprotected BlockStatus setStatus(int blockId, BlockStatus status)
blockId
- The block identifierstatus
- The statuspublic StaticTrack getStaticTrack()
protected void update()
protected void updateTrain(int trainId)
trainId
- The train identifierprotected double getTrainPosition(int trainId)
trainId
- The train identifierprotected boolean setTrainDirection(int trainId, boolean direction)
trainId
- The train identifierdirection
- The directionprotected int getTrainBlock(int trainId)
trainId
- The train identifierprotected int setTrainBlock(int trainId, int block)
trainId
- The train identifierblock
- The new blockprotected StaticBlock nextBlock(StaticBlock curr_block, boolean direction)
curr_block
- The curr blockdirection
- The directionprotected boolean nextDirection(StaticBlock curr_block, StaticBlock next_block)
curr_block
- The curr blocknext_block
- The next blockprotected void updateOccupancies()
protected boolean getTrainReportedBlockChange(int trainId)
trainId
- The train identifierprotected boolean setTrainReportedBlockChange(int trainId, boolean reported_change)
trainId
- The train identifierreported_change
- whether the change has been reportedpublic boolean getTrainBlockChange(int trainId)
trainId
- The train identifierprotected boolean getTrainReportedPassenger(int trainId)
trainId
- The train identifierprotected boolean setTrainReportedPassenger(int trainId, boolean reported_passengers)
trainId
- The train identifierreported_passengers
- whether the change has been reportedprotected boolean getTrainLoadedPassenger(int trainId)
trainId
- The train identifierprotected boolean setTrainLoadedPassenger(int trainId, boolean loaded_passengers)
trainId
- The train identifierloaded_passengers
- whether the change has been loadedpublic int getTrainPassengers(int trainId)
getTrainPassengers
in interface TrackModelInterface
trainId
- The train identifierprotected boolean setUnderground(int blockId, boolean underground)
blockId
- The block identifierunderground
- whether block is undergroundprotected boolean setHeater(int blockId, boolean heater)
blockId
- The block identifierheater
- whether block has a heaterprotected boolean setCrossing(int blockId, boolean rr_crossing)
blockId
- The block identifierrr_crossing
- whether block has a rr_crossingprotected boolean setBidirectional(int blockId, boolean bidirectional)
blockId
- The block identifierbidirectional
- whether block is bidirectionalprotected java.lang.String setStation(int blockId, java.lang.String station)
blockId
- The block identifierstation
- name of the stationprotected java.lang.String setLine(int blockId, java.lang.String line)
blockId
- The block identifierline
- name of the lineprotected Train getTrainModelFromTrainTracker(int trainId)
public boolean setRepair(int blockId)
setRepair
in interface TrackModelInterface
public boolean setOperational(int blockId)
setOperational
in interface TrackModelInterface
public void setStaticBlockUpdate(int blockId)
protected void accumulateWaitingPassengers(double accumulationRate, int timeUnits)
accumulationRate
- The accumulation rate in # people/time unittimeUnits
- The time units since last update