Package jmri.jmrit.timetable
Class TimeTableDataManager
java.lang.Object
jmri.jmrit.timetable.TimeTableDataManager
Provide data base management services.
The data structure was migrated from a MySQL database. As such, it contains tables implemented as TreeMaps and records implemented as Classes. The logical relationships are handled using foreign keys.
Data Structure:
Layout -- Global data.
TrainTypes -- Assigned to trains for diagram colors.
Segments -- Used for division / sub-division arrangements.
Stations -- Any place a train can stop.
Schedules -- Basic information about a schedule.
Trains -- Train characteristics.
Stops -- A junction between a train and a station that contains arrival and departure times.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassInternal class that provides a combined segment and station view. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionTimeTableDataManager(boolean loadData) Create a TimeTableDataManager instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddSchedule(int id, Schedule newSchedule) voidaddSegment(int id, Segment newSegment) voidaddStation(int id, Station newStation) Add a new station.voidvoidvoidaddTrainType(int id, TrainType newTrainType) (package private) voidcalculateLayoutTrains(int layoutId, boolean updateStops) Update the stops for all of the trains for this layout.(package private) voidcalculateScheduleTrains(int scheduleId, boolean updateStops) Update the stop times for all of the trains that use this schedule.voidcalculateTrain(int trainId, boolean updateStops) Calculate the arrival and departure times for all of the stops.voiddeleteLayout(int id) Delete the layout if there are no train types, segments or schedules.voiddeleteSchedule(int id) Delete the schedule if it has no trains.voiddeleteSegment(int id) Delete the segment if it has no stations.voiddeleteStation(int id) Delete the station if there are no stop references.voiddeleteStop(int id) Delete the stop and update train schedule.voiddeleteTrain(int id) Delete the train if it has no stops.voiddeleteTrainType(int id) Delete the train type if there are no train references.static TimeTableDataManagerUse the InstanceManager to only allow a single data manager instance.getLayout(int id) getLayoutForStop(int stopId) getLayouts(boolean sort) Create a list of layoutsintGet the last key from the map and add 1.getSchedule(int id) getSchedules(int fKeyLayout, boolean sort) Create a list of schedulesgetSegment(int id) getSegments(int fKeyLayout, boolean sort) Create a list of segmentsgetSegmentStations(int layoutId) getStation(int id) getStations(int fKeySegment, boolean sort) Create a list of stationsgetStop(int id) getStops(int fKeyTrain, int fKeyStation, boolean sort) Create a list of stopsgetTrain(int id) getTrains(int fKeySchedule, int fKeyType, boolean sort) Create a list of trainsgetTrainType(int id) getTrainTypes(int fKeyLayout, boolean sort) Create a list of train typesvoidsetLockCalculate(boolean lock) booleanvalidateTime(int checkStart, int checkDuration, int checkTime) Check to see if the supplied time is within the time range for the supplied schedule.
-
Field Details
-
CLOCK_LT_1
- See Also:
-
DURATION_LT_0
- See Also:
-
THROTTLES_LT_0
- See Also:
-
THROTTLES_IN_USE
- See Also:
-
SCALE_NF
- See Also:
-
TIME_OUT_OF_RANGE
- See Also:
-
SEGMENT_CHANGE_ERROR
- See Also:
-
DISTANCE_LT_0
- See Also:
-
SIDINGS_LT_0
- See Also:
-
STAGING_LT_0
- See Also:
-
STAGING_IN_USE
- See Also:
-
START_HOUR_RANGE
- See Also:
-
DURATION_RANGE
- See Also:
-
DEFAULT_SPEED_LT_0
- See Also:
-
START_TIME_FORMAT
- See Also:
-
START_TIME_RANGE
- See Also:
-
THROTTLE_RANGE
- See Also:
-
STAGING_RANGE
- See Also:
-
STOP_DURATION_LT_0
- See Also:
-
NEXT_SPEED_LT_0
- See Also:
-
LAYOUT_HAS_CHILDREN
- See Also:
-
TYPE_HAS_REFERENCE
- See Also:
-
SEGMENT_HAS_CHILDREN
- See Also:
-
STATION_HAS_REFERENCE
- See Also:
-
SCHEDULE_HAS_CHILDREN
- See Also:
-
TRAIN_HAS_CHILDREN
- See Also:
-
TYPE_ADD_FAIL
- See Also:
-
SEGMENT_ADD_FAIL
- See Also:
-
STATION_ADD_FAIL
- See Also:
-
SCHEDULE_ADD_FAIL
- See Also:
-
TRAIN_ADD_FAIL
- See Also:
-
STOP_ADD_FAIL
- See Also:
-
_lockCalculate
boolean _lockCalculate
-
-
Constructor Details
-
TimeTableDataManager
Create a TimeTableDataManager instance.- Parameters:
loadData- False to create an empty instance, otherwise load the data
-
-
Method Details
-
getDataManager
Use the InstanceManager to only allow a single data manager instance.- Returns:
- the current or new data manager.
-
setLockCalculate
-
addLayout
-
addTrainType
-
addSegment
-
addStation
Add a new station. Create a SegmentStation instance. Add it to the SegmentStation list.- Parameters:
id- map id.newStation- the new station.
-
addSchedule
-
addTrain
-
addStop
-
deleteLayout
Delete the layout if there are no train types, segments or schedules.- Parameters:
id- The layout id.- Throws:
IllegalArgumentException- LAYOUT_HAS_CHILDREN
-
deleteTrainType
Delete the train type if there are no train references.- Parameters:
id- The train type id.- Throws:
IllegalArgumentException- TYPE_HAS_REFERENCE
-
deleteSegment
Delete the segment if it has no stations.- Parameters:
id- The segment id.- Throws:
IllegalArgumentException- SEGMENT_HAS_CHILDREN
-
deleteStation
Delete the station if there are no stop references.- Parameters:
id- The station id.- Throws:
IllegalArgumentException- STATION_HAS_REFERENCE
-
deleteSchedule
Delete the schedule if it has no trains.- Parameters:
id- The schedule id.- Throws:
IllegalArgumentException- SCHEDULE_HAS_CHILDREN
-
deleteTrain
Delete the train if it has no stops.- Parameters:
id- The train id.- Throws:
IllegalArgumentException- TRAIN_HAS_CHILDREN
-
deleteStop
Delete the stop and update train schedule.- Parameters:
id- The stop id.
-
getLayout
-
getTrainType
-
getSegment
-
getStation
-
getSchedule
-
getTrain
-
getStop
-
getNextId
Get the last key from the map and add 1.- Parameters:
type- The record type which is used to select the appropriate map.- Returns:
- the next id, or 0 if there is an error.
-
getLayouts
Create a list of layouts- Parameters:
sort- If true, sort the resulting list- Returns:
- a list of layouts
-
getTrainTypes
Create a list of train types- Parameters:
fKeyLayout- If non-zero, select the types that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of train types
-
getSegments
Create a list of segments- Parameters:
fKeyLayout- If non-zero, select the segments that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of segments
-
getStations
Create a list of stations- Parameters:
fKeySegment- If non-zero, select the stations that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of stations
-
getSchedules
Create a list of schedules- Parameters:
fKeyLayout- If non-zero, select the schedules that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of schedules
-
getTrains
Create a list of trains- Parameters:
fKeySchedule- If non-zero, select the trains that have the specified foreign keyfKeyType- If non-zero, select the trains that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of trains
-
getStops
Create a list of stops- Parameters:
fKeyTrain- If non-zero, select the stops that have the specified foreign keyfKeyStation- If non-zero, select the stops that have the specified foreign keysort- If true, sort the resulting list- Returns:
- a list of stops
-
getLayoutForStop
-
getSegmentStations
-
calculateLayoutTrains
Update the stops for all of the trains for this layout. Invoked by updates to fast clock speed, metric, scale and station distances.- Parameters:
layoutId- The id for the layout that has been updated.updateStops- True for update
-
calculateScheduleTrains
Update the stop times for all of the trains that use this schedule.- Parameters:
scheduleId- The id for the schedule that has been updated.updateStops- True for update
-
calculateTrain
Calculate the arrival and departure times for all of the stops.- Parameters:
trainId- The id of the train to be updated.updateStops- When true, update the arrive and depart times.- Throws:
IllegalArgumentException- when stop times are outside of the schedule times or a segment change failed. The TIME_OUT_OF_RANGE exception message includes the stop id and train name. The SEGMENT_CHANGE_ERROR message includes the segment name and the station name. The tilde character is used as the string separator.
-
validateTime
Check to see if the supplied time is within the time range for the supplied schedule. If the duration is 24 hours, then all times are valid. Otherwise, we need to calculate the valid range, which can span midnight.- Parameters:
checkStart- The schedule start hour.checkDuration- The schedule duration.checkTime- The time value to be check.- Returns:
- true if the time is valid.
-