Class TrainCommon

java.lang.Object
jmri.jmrit.operations.trains.trainbuilder.TrainCommon
Direct Known Subclasses:
HtmlTrainCommon, JsonManifest, PrintShowCarsInTrain, Router, TrainBuilderBase, TrainCsvCommon, TrainManifest, TrainPrintBuildReport, TrainPrintManifest, TrainSwitchLists

public class TrainCommon extends Object
Common routines for trains
  • Field Details

  • Constructor Details

  • 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 File
      engineList - 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 File
      engineList - 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 File
      engineList - List of engines for this train.
      rl - The RouteLocation being printed.
      isManifest - True if manifest, false if switch list
    • pickupEngine

      public String pickupEngine(Engine engine)
      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

      public String dropEngine(Engine engine)
      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 File
      train - The train being printed.
      carList - List of cars for this train
      rl - The RouteLocation being printed
      printHeader - True if new location.
      isManifest - True if manifest, false if switch list.
    • isNextCar

      public static boolean isNextCar(Car car, RouteLocation rl, RouteLocation rld)
      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 tested
      rl - when in train's route the car is being pulled
      rld - 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 File
      train - The train
      carList - List of cars for this train
      rl - The RouteLocation being printed
      printHeader - 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 File
      train - The train
      carList - List of cars for this train
      rl - The RouteLocation being printed
      printHeader - 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

      protected void setCarPickupAndSetoutTimes(Train train, RouteLocation rl, List<Car> carList)
    • getTrainMessage

      public static String getTrainMessage(Train train, RouteLocation rl)
    • getSwitchListTrainStatus

      public static String getSwitchListTrainStatus(Train train, RouteLocation rl)
    • pickUpCarTruncated

      protected void pickUpCarTruncated(PrintWriter file, Car car, boolean isManifest)
      Adds the car's pick up string to the output file using the truncated manifest format
      Parameters:
      file - Manifest or switch list File
      car - The car being printed.
      isManifest - True if manifest, false if switch list.
    • pickUpCar

      protected void pickUpCar(PrintWriter file, Car car, boolean isManifest)
      Adds the car's pick up string to the output file using the manifest or switch list format
      Parameters:
      file - Manifest or switch list File
      car - The car being printed.
      isManifest - True if manifest, false if switch list.
    • pickupCar

      public String pickupCar(Car car, boolean isManifest, boolean isTwoColumnTrack)
      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 format
      isTwoColumnTrack - True if printing using two column format sorted by track name.
      Returns:
      pick up car string
    • truncatedDropCar

      protected void truncatedDropCar(PrintWriter file, Car car, boolean isManifest)
      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 File
      car - The car being printed.
      isManifest - True if manifest, false if switch list.
    • dropCar

      protected void dropCar(PrintWriter file, Car car, boolean isManifest)
      Adds the car's set out string to the output file using the manifest or switch list format
      Parameters:
      file - Manifest or switch list File
      car - The car being printed.
      isManifest - True if manifest, false if switch list.
    • dropCar

      public String dropCar(Car car, boolean isManifest, boolean isTwoColumnTrack)
      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 format
      isTwoColumnTrack - True if printing using two column format.
      Returns:
      drop car string
    • localMoveCar

      public String localMoveCar(Car car, boolean isManifest)
      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 truncated
      isManifest - 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 truncated
      isManifest - True if manifest, false if switch list.
    • pickupUtilityCars

      public String pickupUtilityCars(List<Car> carList, Car car, boolean isManifest, boolean isTwoColumnTrack)
    • countPickupUtilityCars

      public int countPickupUtilityCars(List<Car> carList, Car car, boolean isManifest)
    • setoutUtilityCars

      public String setoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest)
      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

      public int countSetoutUtilityCars(List<Car> carList, Car car, boolean isLocal, boolean isManifest)
    • countUtilityCars

      protected int countUtilityCars(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. 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 train
      car - The utility car.
      isPickup - True if pick up, false if set out.
      Returns:
      0 if the car type has already been processed
    • clearUtilityCarTypes

      public void clearUtilityCarTypes()
    • addLine

      public static void addLine(PrintWriter file, String level, String string)
      Writes a line to the build report file
      Parameters:
      file - build report file
      level - print level
      string - string to write
    • addLine

      protected void addLine(PrintWriter file, String string)
      Writes string to file. No line length wrap or protection.
      Parameters:
      file - The File to write to.
      string - The string to write.
    • newLine

      protected void newLine(PrintWriter file, String string, boolean isManifest)
      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

      protected void newLine(PrintWriter file)
      Adds a blank line to the file.
      Parameters:
      file - The File to write to.
    • splitString

      public static String splitString(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 "(".
      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

      protected boolean isThereWorkAtLocation(List<Car> carList, List<Engine> engList, RouteLocation rl)
    • isThereWorkAtLocation

      public static boolean isThereWorkAtLocation(Train train, Location location)
      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

      protected void addCarsLocationUnknown(PrintWriter file, boolean isManifest)
    • printEngineHeader

      public void printEngineHeader(PrintWriter file, boolean isManifest)
      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

      public void printPickupEngineHeader(PrintWriter file, boolean isManifest)
    • printDropEngineHeader

      public void printDropEngineHeader(PrintWriter file, boolean isManifest)
    • printCarHeader

      public void printCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)
      Prints the two column header for cars. Left side pick ups, right side set outs.
      Parameters:
      file - Manifest or Switch List File
      isManifest - True if manifest, false if switch list.
      isTwoColumnTrack - True if two column format using track names.
    • printPickupCarHeader

      public void printPickupCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)
    • printDropCarHeader

      public void printDropCarHeader(PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)
    • printLocalCarMoveHeader

      public void printLocalCarMoveHeader(PrintWriter file, boolean isManifest)
    • getPickupEngineHeader

    • getDropEngineHeader

    • getPickupCarHeader

      public String getPickupCarHeader(boolean isManifest, boolean isTwoColumnTrack)
    • getDropCarHeader

      public String getDropCarHeader(boolean isManifest, boolean isTwoColumnTrack)
    • getLocalMoveHeader

      public String getLocalMoveHeader(boolean isManifest)
    • printTrackNameHeader

      protected void printTrackNameHeader(PrintWriter file, String trackName, boolean isManifest)
    • printHorizontalLine1

      public void printHorizontalLine1(PrintWriter file, boolean isManifest)
    • printHorizontalLine2

      public void printHorizontalLine2(PrintWriter file, boolean isManifest)
    • printHorizontalLine3

      public void printHorizontalLine3(PrintWriter file, boolean isManifest)
    • printHorizontalLine

      public void printHorizontalLine(PrintWriter file, boolean isManifest)
      Prints a line across the entire page.
      Parameters:
      file - The File to print to.
      isManifest - True if manifest, false if switch list.
    • printHorizontalLine

      public void printHorizontalLine(PrintWriter file, int start, int end)
    • getISO8601Date

      public static String getISO8601Date(boolean isModelYear)
    • getDate

      public static String getDate(Date date)
    • getDate

      public static String getDate(boolean isModelYear)
    • convertStringToDate

      public static Date convertStringToDate(String date)
    • convertStringTime

      protected int convertStringTime(String time)
    • padAndTruncateIfNeeded

      public static String padAndTruncateIfNeeded(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.
      Parameters:
      s - The string to pad.
      fieldSize - The maximum length of the string.
      Returns:
      A String the specified length
    • padAndTruncate

      public static String padAndTruncate(String s, int fieldSize)
    • padString

      public static String padString(String s, int fieldSize)
      Adjusts string to be a certain number of characters by adding spaces to the end of the string.
      Parameters:
      s - The string to pad
      fieldSize - The fixed length of the string.
      Returns:
      A String the specified length
    • createTabIfNeeded

      public static String createTabIfNeeded(int tabSize)
      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

      protected static String tabString(String s, int tabSize)
    • getLineLength

      public static int getLineLength(boolean isManifest)
      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

      public static int getManifestHeaderLineLength()
    • getPageSize

      protected static Dimension getPageSize(String orientation)
    • formatStringToCommaSeparated

      public static String formatStringToCommaSeparated(String[] array)
      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

      public static String formatColorString(String text, Color color)
      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 modified
      color - the color the text is to be printed
      Returns:
      formated text with color modifiers
    • getTextColorString

      public static String getTextColorString(String string)
      Removes the color text control characters around the desired string
      Parameters:
      string - the string with control characters
      Returns:
      pure text
    • getTextColor

      public static Color getTextColor(String string)
    • getTextColorName

      public static String getTextColorName(String string)