Class CarManager

All Implemented Interfaces:
PropertyChangeListener, EventListener, PropertyChangeFirer, PropertyChangeProvider, InstanceManagerAutoDefault, InstanceManagerAutoInitialize

Manages the cars.
  • Field Details

  • Constructor Details

  • Method Details

    • newRS

      public Car newRS(String road, String number)
      Finds an existing Car or creates a new Car if needed requires car's road and number
      Specified by:
      newRS in class RollingStockManager<Car>
      Parameters:
      road - car road
      number - car number
      Returns:
      new car or existing Car
    • deregister

      public void deregister(Car car)
      Description copied from class: RollingStockManager
      Unload RollingStock.
      Overrides:
      deregister in class RollingStockManager<Car>
      Parameters:
      car - The RollingStock to delete.
    • getByLocationList

      Sort by rolling stock location
      Overrides:
      getByLocationList in class RollingStockManager<Car>
      Returns:
      list of cars ordered by the Car's location
    • getByKernelList

      Sort by car kernel names
      Returns:
      list of cars ordered by car kernel
    • getByLoadList

      public List<Car> getByLoadList()
      Sort by car loads
      Returns:
      list of cars ordered by car loads
    • getByRweList

      public List<Car> getByRweList()
      Sort by car return when empty location and track
      Returns:
      list of cars ordered by car return when empty
    • getByRwlList

      public List<Car> getByRwlList()
    • getByRouteList

      public List<Car> getByRouteList()
    • getByDivisionList

    • getByFinalDestinationList

    • getByWaitList

      public List<Car> getByWaitList()
      Sort by car wait count
      Returns:
      list of cars ordered by wait count
    • getByPickupList

    • getComparator

      protected Comparator<Car> getComparator(int attribute)
      Overrides:
      getComparator in class RollingStockManager<Car>
    • getAvailableTrainList

      Return a list available cars (no assigned train or car already assigned to this train) on a route, cars are ordered least recently moved to most recently moved. Note that it is possible for a car to have a location, but no track assignment.
      Parameters:
      train - The Train to use.
      Returns:
      List of cars with no assigned train on a route
    • sortByLoadPriority

      protected List<Car> sortByLoadPriority(List<Car> list)
    • getByTrainDestinationList

      Provides a very sorted list of cars assigned to the train. Note that this isn't the final sort as the cars must be sorted by each location the train visits.

      The sort priority is as follows:

      1. Caboose or car with FRED to the end of the list, unless passenger.
      2. Passenger cars have blocking numbers which places them relative to each other. Passenger cars with positive blocking numbers to the end of the list, but before cabooses or car with FRED. Passenger cars with negative blocking numbers are placed at the front of the train.
      3. Car's destination (alphabetical by location and track name or by track blocking order)
      4. Car is hazardous (hazardous placed after a non-hazardous car)
      5. Car's current location (alphabetical by location and track name)
      6. Car's final destination (alphabetical by location and track name)

      Cars in a kernel are placed together by their kernel blocking numbers, except if they are type passenger. The kernel's position in the list is based on the lead car in the kernel.

      If the train is to be blocked by track blocking order, all of the tracks at that location need a blocking number greater than 0.

      Parameters:
      train - The selected Train.
      Returns:
      Ordered list of cars assigned to the train
    • getCabooseRoadNames

      Get a list of car road names where the car was flagged as a caboose.
      Returns:
      List of caboose road names.
    • getFredRoadNames

      Get a list of car road names where the car was flagged with FRED
      Returns:
      List of road names of cars with FREDs
    • replaceLoad

      public void replaceLoad(String type, String oldLoadName, String newLoadName)
      Replace car loads
      Parameters:
      type - type of car
      oldLoadName - old load name
      newLoadName - new load name
    • getCarsLocationUnknown

    • calculateCarWeight

      public static String calculateCarWeight(String carLength) throws NumberFormatException
      Determines a car's weight in ounces based on car's scale length
      Parameters:
      carLength - Car's scale length
      Returns:
      car's weight in ounces
      Throws:
      NumberFormatException - if length isn't a number
    • isThereDivisions

      public boolean isThereDivisions()
      Used to determine if any car has been assigned a division
      Returns:
      true if any car has been assigned a division, otherwise false
    • isThereClones

      public boolean isThereClones()
      Used to determine if there are clone cars.
      Returns:
      true if there are clone cars, otherwise false.
    • getCloneCreationOrder

      public int getCloneCreationOrder()
      Returns the highest clone creation order given to a clone.
      Returns:
      1 if the first clone created, otherwise the highest found plus one. Automatically increments.
    • getMaxCommentLength

      public int getMaxCommentLength()
    • load

      public void load(org.jdom2.Element root)
    • store

      public void store(org.jdom2.Element root)
      Create an XML element to represent this Entry. This member has to remain synchronized with the detailed DTD in operations-cars.dtd.
      Parameters:
      root - The common Element for operations-cars.dtd.
    • setDirtyAndFirePropertyChange

      protected void setDirtyAndFirePropertyChange(String p, Object old, Object n)
    • propertyChange

      Specified by:
      propertyChange in interface PropertyChangeListener
      Overrides:
      propertyChange in class RollingStockManager<Car>
    • initialize

      public void initialize()
      Description copied from interface: InstanceManagerAutoInitialize
      Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.
      Specified by:
      initialize in interface InstanceManagerAutoInitialize