Class TrainCommon

    • Constructor Summary

      Constructors 
      Constructor Description
      TrainCommon()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addCarsLocationUnknown​(java.io.PrintWriter file, boolean isManifest)  
      protected void addLine​(java.io.PrintWriter file, java.lang.String string)
      Writes string to file.
      protected static void addLine​(java.io.PrintWriter file, java.lang.String level, java.lang.String string)
      Writes a line to the build report file
      protected void blockCarsByTrack​(java.io.PrintWriter file, Train train, java.util.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 void blockCarsByTrackNameTwoColumn​(java.io.PrintWriter file, Train train, java.util.List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest)
      Produces a two column format for car pick ups and set outs.
      protected void blockCarsTwoColumn​(java.io.PrintWriter file, Train train, java.util.List<Car> carList, RouteLocation rl, boolean printHeader, boolean isManifest)
      Produces a two column format for car pick ups and set outs.
      protected void blockLocosTwoColumn​(java.io.PrintWriter file, java.util.List<Engine> engineList, RouteLocation rl, boolean isManifest)
      Used to generate "Two Column" format for engines.
      void clearUtilityCarTypes()  
      int countPickupUtilityCars​(java.util.List<Car> carList, Car car, boolean isManifest)  
      int countSetoutUtilityCars​(java.util.List<Car> carList, Car car, boolean isLocal, boolean isManifest)  
      protected int countUtilityCars​(java.lang.String[] format, java.util.List<Car> carList, Car car, boolean isPickup)
      Scans the car list for utility cars that have the same attributes as the car provided.
      static java.lang.String createTabIfNeeded​(int tabSize)
      Creates a String of spaces to create a tab for text.
      protected void dropCar​(java.io.PrintWriter file, Car car, boolean isManifest)
      Adds the car's set out string to the output file using the manifest or switch list format
      java.lang.String dropCar​(Car car, boolean isManifest, boolean isTwoColumnTrack)
      Returns the drop car string.
      java.lang.String dropEngine​(Engine engine)
      Returns the drop string for a loco.
      protected void dropEngines​(java.io.PrintWriter file, java.util.List<Engine> engineList, RouteLocation rl, boolean isManifest)
      Adds a list of locomotive drops for the route location to the output file.
      static java.lang.String formatColorString​(java.lang.String text, java.awt.Color color)
      Adds HTML like color text control characters around a string.
      static java.lang.String formatStringToCommaSeparated​(java.lang.String[] array)
      Produces a string using commas and spaces between the strings provided in the array.
      static java.lang.String getDate​(boolean isModelYear)  
      static java.lang.String getDate​(java.util.Date date)  
      java.lang.String getDropCarHeader​(boolean isManifest, boolean isTwoColumnTrack)  
      java.lang.String getDropEngineHeader()  
      static java.lang.String getISO8601Date​(boolean isModelYear)  
      static int getLineLength​(boolean isManifest)
      Returns the line length for manifest or switch list printout.
      java.lang.String getLocalMoveHeader​(boolean isManifest)  
      static int getManifestHeaderLineLength()  
      protected static java.awt.Dimension getPageSize​(java.lang.String orientation)  
      java.lang.String getPickupCarHeader​(boolean isManifest, boolean isTwoColumnTrack)  
      java.lang.String getPickupEngineHeader()  
      static java.awt.Color getTextColor​(java.lang.String string)  
      static java.lang.String getTextColorString​(java.lang.String string)
      Removes the color text control characters around the desired string
      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.
      protected boolean isThereWorkAtLocation​(java.util.List<Car> carList, java.util.List<Engine> engList, RouteLocation rl)  
      static boolean isThereWorkAtLocation​(Train train, Location location)
      returns true if the train has work at the location
      java.lang.String localMoveCar​(Car car, boolean isManifest)
      Returns the move car string.
      protected void newLine​(java.io.PrintWriter file)
      Adds a blank line to the file.
      protected void newLine​(java.io.PrintWriter file, java.lang.String string, boolean isManifest)
      Writes a string to a file.
      static java.lang.String padAndTruncate​(java.lang.String s, int fieldSize)  
      static java.lang.String padAndTruncateIfNeeded​(java.lang.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 java.lang.String padString​(java.lang.String s, int fieldSize)
      Adjusts string to be a certain number of characters by adding spaces to the end of the string.
      java.lang.String pickupCar​(Car car, boolean isManifest, boolean isTwoColumnTrack)
      Returns the pick up car string.
      protected void pickUpCar​(java.io.PrintWriter file, Car car, boolean isManifest)
      Adds the car's pick up string to the output file using the manifest or switch list format
      protected void pickUpCarTruncated​(java.io.PrintWriter file, Car car, boolean isManifest)
      Adds the car's pick up string to the output file using the truncated manifest format
      java.lang.String pickupEngine​(Engine engine)
      Returns the pick up string for a loco.
      protected void pickupEngines​(java.io.PrintWriter file, java.util.List<Engine> engineList, RouteLocation rl, boolean isManifest)
      Adds a list of locomotive pick ups for the route location to the output file.
      protected void pickupUtilityCars​(java.io.PrintWriter file, java.util.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.
      java.lang.String pickupUtilityCars​(java.util.List<Car> carList, Car car, boolean isManifest, boolean isTwoColumnTrack)  
      void printCarHeader​(java.io.PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)
      Prints the two column header for cars.
      void printDropCarHeader​(java.io.PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)  
      void printDropEngineHeader​(java.io.PrintWriter file, boolean isManifest)  
      void printEngineHeader​(java.io.PrintWriter file, boolean isManifest)
      Two column header format.
      void printHorizontalLine​(java.io.PrintWriter file, boolean isManifest)
      Prints a line across the entire page.
      void printHorizontalLine​(java.io.PrintWriter file, int start, int end)  
      void printLocalCarMoveHeader​(java.io.PrintWriter file, boolean isManifest)  
      void printPickupCarHeader​(java.io.PrintWriter file, boolean isManifest, boolean isTwoColumnTrack)  
      void printPickupEngineHeader​(java.io.PrintWriter file, boolean isManifest)  
      protected void printTrackComments​(java.io.PrintWriter file, RouteLocation rl, java.util.List<Car> carList, boolean isManifest)  
      protected void printTrackNameHeader​(java.io.PrintWriter file, java.lang.String trackName, boolean isManifest)  
      protected void setoutUtilityCars​(java.io.PrintWriter file, java.util.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.
      java.lang.String setoutUtilityCars​(java.util.List<Car> carList, Car car, boolean isLocal, boolean isManifest)
      For the Conductor and Yardmaster windows.
      protected java.lang.String setoutUtilityCars​(java.util.List<Car> carList, Car car, boolean isLocal, boolean isManifest, boolean isTwoColumnTrack)  
      static java.lang.String splitString​(java.lang.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 "(".
      protected static java.lang.String tabString​(java.lang.String s, int tabSize)  
      protected void truncatedDropCar​(java.io.PrintWriter file, Car car, boolean isManifest)
      Adds the car's set out string to the output file using the truncated manifest format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • blockLocosTwoColumn

        protected void blockLocosTwoColumn​(java.io.PrintWriter file,
                                           java.util.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​(java.io.PrintWriter file,
                                     java.util.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​(java.io.PrintWriter file,
                                   java.util.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 java.lang.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 java.lang.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​(java.io.PrintWriter file,
                                        Train train,
                                        java.util.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. 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
      • blockCarsTwoColumn

        protected void blockCarsTwoColumn​(java.io.PrintWriter file,
                                          Train train,
                                          java.util.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​(java.io.PrintWriter file,
                                                     Train train,
                                                     java.util.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.
      • pickUpCarTruncated

        protected void pickUpCarTruncated​(java.io.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​(java.io.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 java.lang.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​(java.io.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​(java.io.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 java.lang.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 java.lang.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​(java.io.PrintWriter file,
                                         java.util.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​(java.io.PrintWriter file,
                                         java.util.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 java.lang.String pickupUtilityCars​(java.util.List<Car> carList,
                                                  Car car,
                                                  boolean isManifest,
                                                  boolean isTwoColumnTrack)
      • setoutUtilityCars

        public java.lang.String setoutUtilityCars​(java.util.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 java.lang.String setoutUtilityCars​(java.util.List<Car> carList,
                                                     Car car,
                                                     boolean isLocal,
                                                     boolean isManifest,
                                                     boolean isTwoColumnTrack)
      • countSetoutUtilityCars

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

        protected int countUtilityCars​(java.lang.String[] format,
                                       java.util.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
      • addLine

        protected static void addLine​(java.io.PrintWriter file,
                                      java.lang.String level,
                                      java.lang.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​(java.io.PrintWriter file,
                               java.lang.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​(java.io.PrintWriter file,
                               java.lang.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​(java.io.PrintWriter file)
        Adds a blank line to the file.
        Parameters:
        file - The File to write to.
      • splitString

        public static java.lang.String splitString​(java.lang.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.
      • 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​(java.io.PrintWriter file,
                                              boolean isManifest)
      • printEngineHeader

        public void printEngineHeader​(java.io.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.
      • printDropEngineHeader

        public void printDropEngineHeader​(java.io.PrintWriter file,
                                          boolean isManifest)
      • printCarHeader

        public void printCarHeader​(java.io.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​(java.io.PrintWriter file,
                                         boolean isManifest,
                                         boolean isTwoColumnTrack)
      • printDropCarHeader

        public void printDropCarHeader​(java.io.PrintWriter file,
                                       boolean isManifest,
                                       boolean isTwoColumnTrack)
      • getPickupCarHeader

        public java.lang.String getPickupCarHeader​(boolean isManifest,
                                                   boolean isTwoColumnTrack)
      • getDropCarHeader

        public java.lang.String getDropCarHeader​(boolean isManifest,
                                                 boolean isTwoColumnTrack)
      • printTrackNameHeader

        protected void printTrackNameHeader​(java.io.PrintWriter file,
                                            java.lang.String trackName,
                                            boolean isManifest)
      • printHorizontalLine

        public void printHorizontalLine​(java.io.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​(java.io.PrintWriter file,
                                        int start,
                                        int end)
      • getISO8601Date

        public static java.lang.String getISO8601Date​(boolean isModelYear)
      • getDate

        public static java.lang.String getDate​(java.util.Date date)
      • getDate

        public static java.lang.String getDate​(boolean isModelYear)
      • padAndTruncateIfNeeded

        public static java.lang.String padAndTruncateIfNeeded​(java.lang.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 java.lang.String padAndTruncate​(java.lang.String s,
                                                      int fieldSize)
      • padString

        public static java.lang.String padString​(java.lang.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 java.lang.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 java.lang.String tabString​(java.lang.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.
      • getPageSize

        protected static java.awt.Dimension getPageSize​(java.lang.String orientation)
      • formatStringToCommaSeparated

        public static java.lang.String formatStringToCommaSeparated​(java.lang.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 java.lang.String formatColorString​(java.lang.String text,
                                                         java.awt.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 java.lang.String getTextColorString​(java.lang.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 java.awt.Color getTextColor​(java.lang.String string)