Class CarManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.jmrit.operations.rollingstock.RollingStockManager<Car>
-
- jmri.jmrit.operations.rollingstock.cars.CarManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,InstanceManagerAutoDefault
,InstanceManagerAutoInitialize
public class CarManager extends RollingStockManager<Car> implements InstanceManagerAutoDefault, InstanceManagerAutoInitialize
Manages the cars.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
_commentLength
-
Fields inherited from class jmri.jmrit.operations.rollingstock.RollingStockManager
_hashTable, BY_BLOCKING, BY_BUILT, BY_COLOR, BY_COMMENT, BY_DESTINATION, BY_LAST, BY_LOCATION, BY_MOVES, BY_NUMBER, BY_OWNER, BY_RFID, BY_ROAD, BY_TRAIN, BY_TYPE, BY_VALUE, LISTLENGTH_CHANGED_PROPERTY, NONE
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description CarManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
calculateCarWeight(java.lang.String carLength)
Determines a car's weight in ounces based on car's scale lengthvoid
deregister(Car car)
Unload RollingStock.java.util.List<Car>
getAvailableTrainList(Train train)
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.java.util.List<Car>
getByDivisionList()
java.util.List<Car>
getByFinalDestinationList()
java.util.List<Car>
getByKernelList()
Sort by car kernel namesjava.util.List<Car>
getByLoadList()
Sort by car loadsjava.util.List<Car>
getByLocationList()
Sort by rolling stock locationjava.util.List<Car>
getByPickupList()
java.util.List<Car>
getByRouteList()
java.util.List<Car>
getByRweList()
Sort by car return when empty location and trackjava.util.List<Car>
getByRwlList()
java.util.List<Car>
getByTrainDestinationList(Train train)
Provides a very sorted list of cars assigned to the train.java.util.List<Car>
getByWaitList()
Sort by car wait countjava.util.List<java.lang.String>
getCabooseRoadNames()
Get a list of car road names where the car was flagged as a caboose.java.util.List<Car>
getCarsLocationUnknown()
protected java.util.Comparator<Car>
getComparator(int attribute)
java.util.List<java.lang.String>
getFredRoadNames()
Get a list of car road names where the car was flagged with FREDint
getMaxCommentLength()
void
initialize()
Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.boolean
isThereDivisions()
Used to determine if any car has been assigned a divisionvoid
load(org.jdom2.Element root)
Car
newRS(java.lang.String road, java.lang.String number)
Finds an existing Car or creates a new Car if needed requires car's road and numbervoid
propertyChange(java.beans.PropertyChangeEvent evt)
void
replaceLoad(java.lang.String type, java.lang.String oldLoadName, java.lang.String newLoadName)
Replace car loadsprotected void
setDirtyAndFirePropertyChange(java.lang.String p, java.lang.Object old, java.lang.Object n)
protected java.util.List<Car>
sortByPriority(java.util.List<Car> list)
void
store(org.jdom2.Element root)
Create an XML element to represent this Entry.-
Methods inherited from class jmri.jmrit.operations.rollingstock.RollingStockManager
convertBuildDate, deleteAll, dispose, getByBuiltList, getByColorList, getByCommentList, getByDestinationList, getById, getByIdList, getByLastDateList, getByLastDateList, getByList, getByMovesList, getByNumberList, getByOwnerList, getByRfid, getByRfidList, getByRoadAndNumber, getByRoadNameList, getByTrainList, getByTrainList, getByTypeAndRoad, getByTypeList, getByTypeList, getByValueList, getList, getList, getList, getList, getNumEntries, register, resetMoves, resetMoves
-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
_commentLength
int _commentLength
-
-
Constructor Detail
-
CarManager
public CarManager()
-
-
Method Detail
-
newRS
public Car newRS(java.lang.String road, java.lang.String number)
Finds an existing Car or creates a new Car if needed requires car's road and number- Specified by:
newRS
in classRollingStockManager<Car>
- Parameters:
road
- car roadnumber
- car number- Returns:
- new car or existing Car
-
deregister
public void deregister(Car car)
Description copied from class:RollingStockManager
Unload RollingStock.- Overrides:
deregister
in classRollingStockManager<Car>
- Parameters:
car
- The RollingStock to delete.
-
getByLocationList
public java.util.List<Car> getByLocationList()
Sort by rolling stock location- Overrides:
getByLocationList
in classRollingStockManager<Car>
- Returns:
- list of cars ordered by the Car's location
-
getByKernelList
public java.util.List<Car> getByKernelList()
Sort by car kernel names- Returns:
- list of cars ordered by car kernel
-
getByLoadList
public java.util.List<Car> getByLoadList()
Sort by car loads- Returns:
- list of cars ordered by car loads
-
getByRweList
public java.util.List<Car> getByRweList()
Sort by car return when empty location and track- Returns:
- list of cars ordered by car return when empty
-
getByRwlList
public java.util.List<Car> getByRwlList()
-
getByRouteList
public java.util.List<Car> getByRouteList()
-
getByDivisionList
public java.util.List<Car> getByDivisionList()
-
getByFinalDestinationList
public java.util.List<Car> getByFinalDestinationList()
-
getByWaitList
public java.util.List<Car> getByWaitList()
Sort by car wait count- Returns:
- list of cars ordered by wait count
-
getByPickupList
public java.util.List<Car> getByPickupList()
-
getComparator
protected java.util.Comparator<Car> getComparator(int attribute)
- Overrides:
getComparator
in classRollingStockManager<Car>
-
getAvailableTrainList
public java.util.List<Car> getAvailableTrainList(Train train)
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.- Parameters:
train
- The Train to use.- Returns:
- List of cars with no assigned train on a route
-
sortByPriority
protected java.util.List<Car> sortByPriority(java.util.List<Car> list)
-
getByTrainDestinationList
public java.util.List<Car> getByTrainDestinationList(Train train)
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:
- Caboose or car with FRED to the end of the list, unless passenger.
- 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.
- Car's destination (alphabetical by location and track name or by track blocking order)
- Car is hazardous (hazardous placed after a non-hazardous car)
- Car's current location (alphabetical by location and track name)
- 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
public java.util.List<java.lang.String> getCabooseRoadNames()
Get a list of car road names where the car was flagged as a caboose.- Returns:
- List of caboose road names.
-
getFredRoadNames
public java.util.List<java.lang.String> 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(java.lang.String type, java.lang.String oldLoadName, java.lang.String newLoadName)
Replace car loads- Parameters:
type
- type of caroldLoadName
- old load namenewLoadName
- new load name
-
getCarsLocationUnknown
public java.util.List<Car> getCarsLocationUnknown()
-
calculateCarWeight
public static java.lang.String calculateCarWeight(java.lang.String carLength) throws java.lang.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:
java.lang.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
-
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(java.lang.String p, java.lang.Object old, java.lang.Object n)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Overrides:
propertyChange
in classRollingStockManager<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 interfaceInstanceManagerAutoInitialize
-
-