Package jmri.jmrit.timetable
Class TimeTableDataManager
- java.lang.Object
-
- jmri.jmrit.timetable.TimeTableDataManager
-
public class TimeTableDataManager extends java.lang.Object
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 Classes Modifier and Type Class Description class
TimeTableDataManager.SegmentStation
Internal class that provides a combined segment and station view.
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
_lockCalculate
static java.lang.String
CLOCK_LT_1
static java.lang.String
DEFAULT_SPEED_LT_0
static java.lang.String
DISTANCE_LT_0
static java.lang.String
DURATION_LT_0
static java.lang.String
DURATION_RANGE
static java.lang.String
LAYOUT_HAS_CHILDREN
static java.lang.String
NEXT_SPEED_LT_0
static java.lang.String
SCALE_NF
static java.lang.String
SCHEDULE_ADD_FAIL
static java.lang.String
SCHEDULE_HAS_CHILDREN
static java.lang.String
SEGMENT_ADD_FAIL
static java.lang.String
SEGMENT_CHANGE_ERROR
static java.lang.String
SEGMENT_HAS_CHILDREN
static java.lang.String
SIDINGS_LT_0
static java.lang.String
STAGING_IN_USE
static java.lang.String
STAGING_LT_0
static java.lang.String
STAGING_RANGE
static java.lang.String
START_HOUR_RANGE
static java.lang.String
START_TIME_FORMAT
static java.lang.String
START_TIME_RANGE
static java.lang.String
STATION_ADD_FAIL
static java.lang.String
STATION_HAS_REFERENCE
static java.lang.String
STOP_ADD_FAIL
static java.lang.String
STOP_DURATION_LT_0
static java.lang.String
THROTTLE_RANGE
static java.lang.String
THROTTLES_IN_USE
static java.lang.String
THROTTLES_LT_0
static java.lang.String
TIME_OUT_OF_RANGE
static java.lang.String
TRAIN_ADD_FAIL
static java.lang.String
TRAIN_HAS_CHILDREN
static java.lang.String
TYPE_ADD_FAIL
static java.lang.String
TYPE_HAS_REFERENCE
-
Constructor Summary
Constructors Constructor Description TimeTableDataManager(boolean loadData)
Create a TimeTableDataManager instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLayout(int id, Layout newLayout)
void
addSchedule(int id, Schedule newSchedule)
void
addSegment(int id, Segment newSegment)
void
addStation(int id, Station newStation)
Add a new station.void
addStop(int id, Stop newStop)
void
addTrain(int id, Train newTrain)
void
addTrainType(int id, TrainType newTrainType)
(package private) void
calculateLayoutTrains(int layoutId, boolean updateStops)
Update the stops for all of the trains for this layout.(package private) void
calculateScheduleTrains(int scheduleId, boolean updateStops)
Update the stop times for all of the trains that use this schedule.void
calculateTrain(int trainId, boolean updateStops)
Calculate the arrival and departure times for all of the stops.void
deleteLayout(int id)
Delete the layout if there are no train types, segments or schedules.void
deleteSchedule(int id)
Delete the schedule if it has no trains.void
deleteSegment(int id)
Delete the segment if it has no stations.void
deleteStation(int id)
Delete the station if there are no stop references.void
deleteStop(int id)
Delete the stop and update train schedule.void
deleteTrain(int id)
Delete the train if it has no stops.void
deleteTrainType(int id)
Delete the train type if there are no train references.static TimeTableDataManager
getDataManager()
Use the InstanceManager to only allow a single data manager instance.Layout
getLayout(int id)
Layout
getLayoutForStop(int stopId)
java.util.List<Layout>
getLayouts(boolean sort)
Create a list of layoutsint
getNextId(java.lang.String type)
Get the last key from the map and add 1.Schedule
getSchedule(int id)
java.util.List<Schedule>
getSchedules(int fKeyLayout, boolean sort)
Create a list of schedulesSegment
getSegment(int id)
java.util.List<Segment>
getSegments(int fKeyLayout, boolean sort)
Create a list of segmentsjava.util.List<TimeTableDataManager.SegmentStation>
getSegmentStations(int layoutId)
Station
getStation(int id)
java.util.List<Station>
getStations(int fKeySegment, boolean sort)
Create a list of stationsStop
getStop(int id)
java.util.List<Stop>
getStops(int fKeyTrain, int fKeyStation, boolean sort)
Create a list of stopsTrain
getTrain(int id)
java.util.List<Train>
getTrains(int fKeySchedule, int fKeyType, boolean sort)
Create a list of trainsTrainType
getTrainType(int id)
java.util.List<TrainType>
getTrainTypes(int fKeyLayout, boolean sort)
Create a list of train typesvoid
setLockCalculate(boolean lock)
boolean
validateTime(int checkStart, int checkDuration, int checkTime)
Check to see if the supplied time is within the time range for the supplied schedule.
-
-
-
Field Detail
-
CLOCK_LT_1
public static final java.lang.String CLOCK_LT_1
- See Also:
- Constant Field Values
-
DURATION_LT_0
public static final java.lang.String DURATION_LT_0
- See Also:
- Constant Field Values
-
THROTTLES_LT_0
public static final java.lang.String THROTTLES_LT_0
- See Also:
- Constant Field Values
-
THROTTLES_IN_USE
public static final java.lang.String THROTTLES_IN_USE
- See Also:
- Constant Field Values
-
SCALE_NF
public static final java.lang.String SCALE_NF
- See Also:
- Constant Field Values
-
TIME_OUT_OF_RANGE
public static final java.lang.String TIME_OUT_OF_RANGE
- See Also:
- Constant Field Values
-
SEGMENT_CHANGE_ERROR
public static final java.lang.String SEGMENT_CHANGE_ERROR
- See Also:
- Constant Field Values
-
DISTANCE_LT_0
public static final java.lang.String DISTANCE_LT_0
- See Also:
- Constant Field Values
-
SIDINGS_LT_0
public static final java.lang.String SIDINGS_LT_0
- See Also:
- Constant Field Values
-
STAGING_LT_0
public static final java.lang.String STAGING_LT_0
- See Also:
- Constant Field Values
-
STAGING_IN_USE
public static final java.lang.String STAGING_IN_USE
- See Also:
- Constant Field Values
-
START_HOUR_RANGE
public static final java.lang.String START_HOUR_RANGE
- See Also:
- Constant Field Values
-
DURATION_RANGE
public static final java.lang.String DURATION_RANGE
- See Also:
- Constant Field Values
-
DEFAULT_SPEED_LT_0
public static final java.lang.String DEFAULT_SPEED_LT_0
- See Also:
- Constant Field Values
-
START_TIME_FORMAT
public static final java.lang.String START_TIME_FORMAT
- See Also:
- Constant Field Values
-
START_TIME_RANGE
public static final java.lang.String START_TIME_RANGE
- See Also:
- Constant Field Values
-
THROTTLE_RANGE
public static final java.lang.String THROTTLE_RANGE
- See Also:
- Constant Field Values
-
STAGING_RANGE
public static final java.lang.String STAGING_RANGE
- See Also:
- Constant Field Values
-
STOP_DURATION_LT_0
public static final java.lang.String STOP_DURATION_LT_0
- See Also:
- Constant Field Values
-
NEXT_SPEED_LT_0
public static final java.lang.String NEXT_SPEED_LT_0
- See Also:
- Constant Field Values
-
LAYOUT_HAS_CHILDREN
public static final java.lang.String LAYOUT_HAS_CHILDREN
- See Also:
- Constant Field Values
-
TYPE_HAS_REFERENCE
public static final java.lang.String TYPE_HAS_REFERENCE
- See Also:
- Constant Field Values
-
SEGMENT_HAS_CHILDREN
public static final java.lang.String SEGMENT_HAS_CHILDREN
- See Also:
- Constant Field Values
-
STATION_HAS_REFERENCE
public static final java.lang.String STATION_HAS_REFERENCE
- See Also:
- Constant Field Values
-
SCHEDULE_HAS_CHILDREN
public static final java.lang.String SCHEDULE_HAS_CHILDREN
- See Also:
- Constant Field Values
-
TRAIN_HAS_CHILDREN
public static final java.lang.String TRAIN_HAS_CHILDREN
- See Also:
- Constant Field Values
-
TYPE_ADD_FAIL
public static final java.lang.String TYPE_ADD_FAIL
- See Also:
- Constant Field Values
-
SEGMENT_ADD_FAIL
public static final java.lang.String SEGMENT_ADD_FAIL
- See Also:
- Constant Field Values
-
STATION_ADD_FAIL
public static final java.lang.String STATION_ADD_FAIL
- See Also:
- Constant Field Values
-
SCHEDULE_ADD_FAIL
public static final java.lang.String SCHEDULE_ADD_FAIL
- See Also:
- Constant Field Values
-
TRAIN_ADD_FAIL
public static final java.lang.String TRAIN_ADD_FAIL
- See Also:
- Constant Field Values
-
STOP_ADD_FAIL
public static final java.lang.String STOP_ADD_FAIL
- See Also:
- Constant Field Values
-
_lockCalculate
boolean _lockCalculate
-
-
Constructor Detail
-
TimeTableDataManager
public TimeTableDataManager(boolean loadData)
Create a TimeTableDataManager instance.- Parameters:
loadData
- False to create an empty instance, otherwise load the data
-
-
Method Detail
-
getDataManager
public static TimeTableDataManager getDataManager()
Use the InstanceManager to only allow a single data manager instance.- Returns:
- the current or new data manager.
-
setLockCalculate
public void setLockCalculate(boolean lock)
-
addTrainType
public void addTrainType(int id, TrainType newTrainType)
-
addSegment
public void addSegment(int id, Segment newSegment)
-
addStation
public void addStation(int id, Station newStation)
Add a new station. Create a SegmentStation instance. Add it to the SegmentStation list.- Parameters:
id
- map id.newStation
- the new station.
-
addSchedule
public void addSchedule(int id, Schedule newSchedule)
-
deleteLayout
public void deleteLayout(int id)
Delete the layout if there are no train types, segments or schedules.- Parameters:
id
- The layout id.- Throws:
java.lang.IllegalArgumentException
- LAYOUT_HAS_CHILDREN
-
deleteTrainType
public void deleteTrainType(int id)
Delete the train type if there are no train references.- Parameters:
id
- The train type id.- Throws:
java.lang.IllegalArgumentException
- TYPE_HAS_REFERENCE
-
deleteSegment
public void deleteSegment(int id)
Delete the segment if it has no stations.- Parameters:
id
- The segment id.- Throws:
java.lang.IllegalArgumentException
- SEGMENT_HAS_CHILDREN
-
deleteStation
public void deleteStation(int id)
Delete the station if there are no stop references.- Parameters:
id
- The station id.- Throws:
java.lang.IllegalArgumentException
- STATION_HAS_REFERENCE
-
deleteSchedule
public void deleteSchedule(int id)
Delete the schedule if it has no trains.- Parameters:
id
- The schedule id.- Throws:
java.lang.IllegalArgumentException
- SCHEDULE_HAS_CHILDREN
-
deleteTrain
public void deleteTrain(int id)
Delete the train if it has no stops.- Parameters:
id
- The train id.- Throws:
java.lang.IllegalArgumentException
- TRAIN_HAS_CHILDREN
-
deleteStop
public void deleteStop(int id)
Delete the stop and update train schedule.- Parameters:
id
- The stop id.
-
getTrainType
public TrainType getTrainType(int id)
-
getSegment
public Segment getSegment(int id)
-
getStation
public Station getStation(int id)
-
getSchedule
public Schedule getSchedule(int id)
-
getNextId
public int getNextId(java.lang.String type)
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
public java.util.List<Layout> getLayouts(boolean sort)
Create a list of layouts- Parameters:
sort
- If true, sort the resulting list- Returns:
- a list of layouts
-
getTrainTypes
public java.util.List<TrainType> getTrainTypes(int fKeyLayout, boolean sort)
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
public java.util.List<Segment> getSegments(int fKeyLayout, boolean sort)
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
public java.util.List<Station> getStations(int fKeySegment, boolean sort)
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
public java.util.List<Schedule> getSchedules(int fKeyLayout, boolean sort)
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
public java.util.List<Train> getTrains(int fKeySchedule, int fKeyType, boolean sort)
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
public java.util.List<Stop> getStops(int fKeyTrain, int fKeyStation, boolean sort)
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
public Layout getLayoutForStop(int stopId)
-
getSegmentStations
public java.util.List<TimeTableDataManager.SegmentStation> getSegmentStations(int layoutId)
-
calculateLayoutTrains
void calculateLayoutTrains(int layoutId, boolean updateStops)
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
void calculateScheduleTrains(int scheduleId, boolean updateStops)
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
public void calculateTrain(int trainId, boolean updateStops)
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:
java.lang.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
public boolean validateTime(int checkStart, int checkDuration, int checkTime)
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.
-
-