Class TrainCommon
java.lang.Object
jmri.jmrit.operations.trains.trainbuilder.TrainCommon
- Direct Known Subclasses:
HtmlTrainCommon,JsonManifest,PrintShowCarsInTrain,Router,TrainBuilderBase,TrainCsvCommon,TrainManifest,TrainPrintBuildReport,TrainPrintManifest,TrainSwitchLists
Common routines for trains
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected boolean(package private) boolean(package private) boolean(package private) booleanstatic final Stringprotected static final Stringprotected CarManagerprotected static final booleanprotected EngineManagerprotected static final charstatic final String(package private) intprotected static final booleanstatic final booleanstatic final booleanprotected LocationManagerprotected static final Stringprotected static final Dimensionprotected static final booleanstatic final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCarsLocationUnknown(PrintWriter file, boolean isManifest) protected voidaddLine(PrintWriter file, String string) Writes string to file.static voidaddLine(PrintWriter file, String level, String string) Writes a line to the build report fileprotected voidblockCarsByTrack(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Block cars by track, then pick up and set out for each location in a train's route.protected voidblockCarsByTrackNameTwoColumn(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Produces a two column format for car pick ups and set outs.protected voidblockCarsTwoColumn(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Produces a two column format for car pick ups and set outs.protected voidblockLocosTwoColumn(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Used to generate "Two Column" format for engines.voidprotected intconvertStringTime(String time) static DateconvertStringToDate(String date) intcountPickupUtilityCars(List<Car> carList, Car car, boolean isManifest) intcountSetoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest) protected intcountUtilityCars(String[] format, List<Car> carList, Car car, boolean isPickup) Scans the car list for utility cars that have the same attributes as the car provided.static StringcreateTabIfNeeded(int tabSize) Creates a String of spaces to create a tab for text.protected voiddropCar(PrintWriter file, Car car, boolean isManifest) Adds the car's set out string to the output file using the manifest or switch list formatReturns the drop car string.dropEngine(Engine engine) Returns the drop string for a loco.protected voiddropEngines(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Adds a list of locomotive drops for the route location to the output file.static StringformatColorString(String text, Color color) Adds HTML like color text control characters around a string.static StringformatStringToCommaSeparated(String[] array) Produces a string using commas and spaces between the strings provided in the array.static StringgetDate(boolean isModelYear) static StringgetDropCarHeader(boolean isManifest, boolean isTwoColumnTrack) static StringgetISO8601Date(boolean isModelYear) static intgetLineLength(boolean isManifest) Returns the line length for manifest or switch list printout.getLocalMoveHeader(boolean isManifest) static intprotected static DimensiongetPageSize(String orientation) getPickupCarHeader(boolean isManifest, boolean isTwoColumnTrack) static StringgetSwitchListTrainStatus(Train train, RouteLocation rl) static ColorgetTextColor(String string) static StringgetTextColorName(String string) static StringgetTextColorString(String string) Removes the color text control characters around the desired stringstatic StringgetTrainMessage(Train train, RouteLocation rl) static booleanisNextCar(Car car, RouteLocation rl, RouteLocation rld) Used to determine if car is the next to be processed when producing Manifests or Switch Lists.static booleanisNextCar(Car car, RouteLocation rl, RouteLocation rld, boolean isIgnoreTrack) protected booleanisThereWorkAtLocation(List<Car> carList, List<Engine> engList, RouteLocation rl) static booleanisThereWorkAtLocation(Train train, Location location) returns true if the train has work at the locationlocalMoveCar(Car car, boolean isManifest) Returns the move car string.protected voidnewLine(PrintWriter file) Adds a blank line to the file.protected voidnewLine(PrintWriter file, String string, boolean isManifest) Writes a string to a file.static StringpadAndTruncate(String s, int fieldSize) static StringpadAndTruncateIfNeeded(String s, int fieldSize) Pads out a string by adding spaces to the end of the string, and will remove characters from the end of the string if the string exceeds the field size.static StringAdjusts string to be a certain number of characters by adding spaces to the end of the string.Returns the pick up car string.protected voidpickUpCar(PrintWriter file, Car car, boolean isManifest) Adds the car's pick up string to the output file using the manifest or switch list formatprotected voidpickUpCarTruncated(PrintWriter file, Car car, boolean isManifest) Adds the car's pick up string to the output file using the truncated manifest formatpickupEngine(Engine engine) Returns the pick up string for a loco.protected voidpickupEngines(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Adds a list of locomotive pick ups for the route location to the output file.protected voidpickupUtilityCars(PrintWriter file, List<Car> carList, Car car, boolean isTruncate, boolean isManifest) Add a list of utility cars scheduled for pick up from the route location to the output file.pickupUtilityCars(List<Car> carList, Car car, boolean isManifest, boolean isTwoColumnTrack) voidprintCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack) Prints the two column header for cars.voidprintDropCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack) voidprintDropEngineHeader(PrintWriter file, boolean isManifest) voidprintEngineHeader(PrintWriter file, boolean isManifest) Two column header format.voidprintHorizontalLine(PrintWriter file, boolean isManifest) Prints a line across the entire page.voidprintHorizontalLine(PrintWriter file, int start, int end) voidprintHorizontalLine1(PrintWriter file, boolean isManifest) voidprintHorizontalLine2(PrintWriter file, boolean isManifest) voidprintHorizontalLine3(PrintWriter file, boolean isManifest) voidprintLocalCarMoveHeader(PrintWriter file, boolean isManifest) voidprintPickupCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack) voidprintPickupEngineHeader(PrintWriter file, boolean isManifest) protected voidprintTrackComments(PrintWriter file, RouteLocation rl, List<Car> carList, boolean isManifest) protected voidprintTrackNameHeader(PrintWriter file, String trackName, boolean isManifest) protected voidsetCarPickupAndSetoutTimes(Train train, RouteLocation rl, List<Car> carList) protected voidsetoutUtilityCars(PrintWriter file, List<Car> carList, Car car, boolean isTruncate, boolean isManifest) Add a list of utility cars scheduled for drop at the route location to the output file.setoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest) For the Conductor and Yardmaster windows.protected StringsetoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest, boolean isTwoColumnTrack) static StringsplitString(String name) Splits a string (example-number) as long as the second part of the string is an integer or if the first character after the hyphen is a left parenthesis "(".static StringSplits a string if there's a hyphen followed by a left parenthesis "-(".protected static Stringprotected voidtruncatedDropCar(PrintWriter file, Car car, boolean isManifest) Adds the car's set out string to the output file using the truncated manifest format.
-
Field Details
-
TAB
- See Also:
-
NEW_LINE
- See Also:
-
SPACE
- See Also:
-
BLANK_LINE
- See Also:
-
HORIZONTAL_LINE_CHAR
- See Also:
-
BUILD_REPORT_CHAR
- See Also:
-
HYPHEN
- See Also:
-
VERTICAL_LINE_CHAR
- See Also:
-
TEXT_COLOR_START
- See Also:
-
TEXT_COLOR_DONE
- See Also:
-
TEXT_COLOR_END
- See Also:
-
PICKUP
- See Also:
-
IS_MANIFEST
- See Also:
-
LOCAL
- See Also:
-
ENGINE
- See Also:
-
IS_TWO_COLUMN_TRACK
- See Also:
-
carManager
-
engineManager
-
locationManager
-
_pickupCars
-
_dropCars
-
_printPickupHeader
boolean _printPickupHeader -
_printSetoutHeader
boolean _printSetoutHeader -
_printLocalMoveHeader
boolean _printLocalMoveHeader -
doneCars
-
index
int index -
utilityCarTypes
-
PAPER_MARGINS
-
-
Constructor Details
-
TrainCommon
public TrainCommon()
-
-
Method Details
-
blockLocosTwoColumn
protected void blockLocosTwoColumn(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Used to generate "Two Column" format for engines.- Parameters:
file- Manifest or Switch List FileengineList- List of engines for this train.rl- The RouteLocation being printed.isManifest- True if manifest, false if switch list.
-
pickupEngines
protected void pickupEngines(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Adds a list of locomotive pick ups for the route location to the output file. Used to generate "Standard" format.- Parameters:
file- Manifest or Switch List FileengineList- List of engines for this train.rl- The RouteLocation being printed.isManifest- True if manifest, false if switch list
-
dropEngines
protected void dropEngines(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) Adds a list of locomotive drops for the route location to the output file. Used to generate "Standard" format.- Parameters:
file- Manifest or Switch List FileengineList- List of engines for this train.rl- The RouteLocation being printed.isManifest- True if manifest, false if switch list
-
pickupEngine
Returns the pick up string for a loco. Useful for frames like the train conductor and yardmaster.- Parameters:
engine- The Engine.- Returns:
- engine pick up string
-
dropEngine
Returns the drop string for a loco. Useful for frames like the train conductor and yardmaster.- Parameters:
engine- The Engine.- Returns:
- engine drop string
-
blockCarsByTrack
protected void blockCarsByTrack(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Block cars by track, then pick up and set out for each location in a train's route. This routine is used for the "Standard" format.- Parameters:
file- Manifest or switch list Filetrain- The train being printed.carList- List of cars for this trainrl- The RouteLocation being printedprintHeader- True if new location.isManifest- True if manifest, false if switch list.
-
isNextCar
Used to determine if car is the next to be processed when producing Manifests or Switch Lists. Caboose or FRED is placed at end of the train unless they are also passenger cars. Passenger cars are already blocked in the car list. Passenger cars with negative block numbers are placed at the front of the train, positive numbers at the end of the train. Note that a car in train doesn't have a track assignment.- Parameters:
car- the car being testedrl- when in train's route the car is being pulledrld- the destination being tested- Returns:
- true if this car is the next one to be processed
-
isNextCar
public static boolean isNextCar(Car car, RouteLocation rl, RouteLocation rld, boolean isIgnoreTrack) -
blockCarsTwoColumn
protected void blockCarsTwoColumn(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Produces a two column format for car pick ups and set outs. Sorted by track and then by blocking order. This routine is used for the "Two Column" format.- Parameters:
file- Manifest or switch list Filetrain- The traincarList- List of cars for this trainrl- The RouteLocation being printedprintHeader- True if new location.isManifest- True if manifest, false if switch list.
-
blockCarsByTrackNameTwoColumn
protected void blockCarsByTrackNameTwoColumn(PrintWriter file, Train train, List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest) Produces a two column format for car pick ups and set outs. Sorted by track and then by destination. Track name in header format, track name removed from format. This routine is used to generate the "Two Column by Track" format.- Parameters:
file- Manifest or switch list Filetrain- The traincarList- List of cars for this trainrl- The RouteLocation being printedprintHeader- True if new location.isManifest- True if manifest, false if switch list.
-
printTrackComments
protected void printTrackComments(PrintWriter file, RouteLocation rl, List<Car> carList, boolean isManifest) -
setCarPickupAndSetoutTimes
-
getTrainMessage
-
getSwitchListTrainStatus
-
pickUpCarTruncated
Adds the car's pick up string to the output file using the truncated manifest format- Parameters:
file- Manifest or switch list Filecar- The car being printed.isManifest- True if manifest, false if switch list.
-
pickUpCar
Adds the car's pick up string to the output file using the manifest or switch list format- Parameters:
file- Manifest or switch list Filecar- The car being printed.isManifest- True if manifest, false if switch list.
-
pickupCar
Returns the pick up car string. Useful for frames like train conductor and yardmaster.- Parameters:
car- The car being printed.isManifest- when true use manifest format, when false use switch list formatisTwoColumnTrack- True if printing using two column format sorted by track name.- Returns:
- pick up car string
-
truncatedDropCar
Adds the car's set out string to the output file using the truncated manifest format. Does not print out local moves. Local moves are only shown on the switch list for that location.- Parameters:
file- Manifest or switch list Filecar- The car being printed.isManifest- True if manifest, false if switch list.
-
dropCar
Adds the car's set out string to the output file using the manifest or switch list format- Parameters:
file- Manifest or switch list Filecar- The car being printed.isManifest- True if manifest, false if switch list.
-
dropCar
Returns the drop car string. Useful for frames like train conductor and yardmaster.- Parameters:
car- The car being printed.isManifest- when true use manifest format, when false use switch list formatisTwoColumnTrack- True if printing using two column format.- Returns:
- drop car string
-
localMoveCar
Returns the move car string. Useful for frames like train conductor and yardmaster.- Parameters:
car- The car being printed.isManifest- when true use manifest format, when false use switch list format- Returns:
- move car string
-
pickupUtilityCars
protected void pickupUtilityCars(PrintWriter file, List<Car> carList, Car car, boolean isTruncate, boolean isManifest) Add a list of utility cars scheduled for pick up from the route location to the output file. The cars are blocked by destination.- Parameters:
file- Manifest or Switch List File.carList- List of cars for this train.car- The utility car.isTruncate- True if manifest is to be truncatedisManifest- True if manifest, false if switch list.
-
setoutUtilityCars
protected void setoutUtilityCars(PrintWriter file, List<Car> carList, Car car, boolean isTruncate, boolean isManifest) Add a list of utility cars scheduled for drop at the route location to the output file.- Parameters:
file- Manifest or Switch List File.carList- List of cars for this train.car- The utility car.isTruncate- True if manifest is to be truncatedisManifest- True if manifest, false if switch list.
-
pickupUtilityCars
public String pickupUtilityCars(List<Car> carList, Car car, boolean isManifest, boolean isTwoColumnTrack) -
countPickupUtilityCars
-
setoutUtilityCars
For the Conductor and Yardmaster windows.- Parameters:
carList- List of cars for this train.car- The utility car.isLocal- True if local move.isManifest- True if manifest, false if switch list.- Returns:
- A string representing the work of identical utility cars.
-
setoutUtilityCars
protected String setoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest, boolean isTwoColumnTrack) -
countSetoutUtilityCars
-
countUtilityCars
Scans the car list for utility cars that have the same attributes as the car provided. Returns 0 if this car type has already been processed, otherwise the number of cars with the same attribute.- Parameters:
format- Message format.carList- List of cars for this traincar- The utility car.isPickup- True if pick up, false if set out.- Returns:
- 0 if the car type has already been processed
-
clearUtilityCarTypes
-
addLine
Writes a line to the build report file- Parameters:
file- build report filelevel- print levelstring- string to write
-
addLine
Writes string to file. No line length wrap or protection.- Parameters:
file- The File to write to.string- The string to write.
-
newLine
Writes a string to a file. Checks for string length, and will automatically wrap lines.- Parameters:
file- The File to write to.string- The string to write.isManifest- set true for manifest page orientation, false for switch list orientation
-
newLine
Adds a blank line to the file.- Parameters:
file- The File to write to.
-
splitString
Splits a string (example-number) as long as the second part of the string is an integer or if the first character after the hyphen is a left parenthesis "(".- Parameters:
name- The string to split if necessary.- Returns:
- First half of the string.
-
splitStringLeftParenthesis
Splits a string if there's a hyphen followed by a left parenthesis "-(".- Parameters:
name- the string to split- Returns:
- First half of the string.
-
isThereWorkAtLocation
-
isThereWorkAtLocation
returns true if the train has work at the location- Parameters:
train- The Train.location- The Location.- Returns:
- true if the train has work at the location
-
addCarsLocationUnknown
-
printEngineHeader
Two column header format. Left side pick ups, right side set outs- Parameters:
file- Manifest or switch list File.isManifest- True if manifest, false if switch list.
-
printPickupEngineHeader
-
printDropEngineHeader
-
printCarHeader
Prints the two column header for cars. Left side pick ups, right side set outs.- Parameters:
file- Manifest or Switch List FileisManifest- True if manifest, false if switch list.isTwoColumnTrack- True if two column format using track names.
-
printPickupCarHeader
-
printDropCarHeader
-
printLocalCarMoveHeader
-
getPickupEngineHeader
-
getDropEngineHeader
-
getPickupCarHeader
-
getDropCarHeader
-
getLocalMoveHeader
-
printTrackNameHeader
-
printHorizontalLine1
-
printHorizontalLine2
-
printHorizontalLine3
-
printHorizontalLine
Prints a line across the entire page.- Parameters:
file- The File to print to.isManifest- True if manifest, false if switch list.
-
printHorizontalLine
-
getISO8601Date
-
getDate
-
getDate
-
convertStringToDate
-
convertStringTime
-
padAndTruncateIfNeeded
Pads out a string by adding spaces to the end of the string, and will remove characters from the end of the string if the string exceeds the field size.- Parameters:
s- The string to pad.fieldSize- The maximum length of the string.- Returns:
- A String the specified length
-
padAndTruncate
-
padString
Adjusts string to be a certain number of characters by adding spaces to the end of the string.- Parameters:
s- The string to padfieldSize- The fixed length of the string.- Returns:
- A String the specified length
-
createTabIfNeeded
Creates a String of spaces to create a tab for text. Tabs must be enabled. Setup.isTabEnabled()- Parameters:
tabSize- the length of tab- Returns:
- tab
-
tabString
-
getLineLength
Returns the line length for manifest or switch list printout. Always an even number.- Parameters:
isManifest- True if manifest.- Returns:
- line length for manifest or switch list.
-
getManifestHeaderLineLength
-
getPageSize
-
formatStringToCommaSeparated
Produces a string using commas and spaces between the strings provided in the array. Does not check for embedded commas in the string array.- Parameters:
array- The string array to be formated.- Returns:
- formated string using commas and spaces
-
formatColorString
Adds HTML like color text control characters around a string. Note that black is the standard text color, and if black is requested no control characters are added.- Parameters:
text- the text to be modifiedcolor- the color the text is to be printed- Returns:
- formated text with color modifiers
-
getTextColorString
Removes the color text control characters around the desired string- Parameters:
string- the string with control characters- Returns:
- pure text
-
getTextColor
-
getTextColorName
-