use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class TrainBuilder method checkDepartureStagingTrack.
/**
* Check departure staging track to see if engines and cars are available to
* a new train. Also confirms that the engine and car type, load, road, etc.
* are accepted by the train.
*
* @return true is there are engines and cars available.
*/
private boolean checkDepartureStagingTrack(Track departStageTrack) {
// does this staging track service this train?
if (!departStageTrack.acceptsPickupTrain(_train)) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotTrain"), new Object[] { departStageTrack.getName() }));
return false;
}
if (departStageTrack.getNumberRS() == 0 && _train.getTrainDepartsRouteLocation().getMaxCarMoves() > 0) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingEmpty"), new Object[] { departStageTrack.getName() }));
return false;
}
if (departStageTrack.getUsedLength() > _train.getTrainDepartsRouteLocation().getMaxTrainLength()) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingTrainTooLong"), new Object[] { departStageTrack.getName(), departStageTrack.getUsedLength(), Setup.getLengthUnit().toLowerCase(), _train.getTrainDepartsRouteLocation().getMaxTrainLength() }));
return false;
}
if (departStageTrack.getNumberCars() > _train.getTrainDepartsRouteLocation().getMaxCarMoves()) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingTooManyCars"), new Object[] { departStageTrack.getName(), departStageTrack.getNumberCars(), _train.getTrainDepartsRouteLocation().getMaxCarMoves() }));
return false;
}
// does the staging track have the right number of locomotives?
if (_reqNumEngines > 0 && _reqNumEngines != departStageTrack.getNumberEngines()) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotEngines"), new Object[] { departStageTrack.getName(), departStageTrack.getNumberEngines(), _reqNumEngines }));
return false;
}
// is the staging track direction correct for this train?
if ((departStageTrack.getTrainDirections() & _train.getTrainDepartsRouteLocation().getTrainDirection()) == 0) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotDirection"), new Object[] { departStageTrack.getName() }));
return false;
}
if (departStageTrack.getNumberEngines() > 0) {
for (RollingStock rs : engineManager.getList()) {
Engine eng = (Engine) rs;
if (eng.getTrack() == departStageTrack) {
// has engine been assigned to another train?
if (eng.getRouteLocation() != null) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepart"), new Object[] { departStageTrack.getName(), eng.getTrainName() }));
return false;
}
if (eng.getTrain() != null && eng.getTrain() != _train) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineTrain"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getTrainName() }));
return false;
}
// does the train accept the engine type from the staging track?
if (!_train.acceptsTypeName(eng.getTypeName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineType"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getTypeName(), _train.getName() }));
return false;
}
// does the train accept the engine model from the staging track?
if (!_train.getEngineModel().equals(Train.NONE) && !_train.getEngineModel().equals(eng.getModel())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineModel"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getModel(), _train.getName() }));
return false;
}
// does the engine road match the train requirements?
if (!_train.getRoadOption().equals(Train.ALL_LOADS) && !_train.getEngineRoad().equals(Train.NONE) && !_train.getEngineRoad().equals(eng.getRoadName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineRoad"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getRoadName(), _train.getName() }));
return false;
}
// does the train accept the engine road from the staging track?
if (_train.getEngineRoad().equals(Train.NONE) && !_train.acceptsRoadName(eng.getRoadName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineRoad"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getRoadName(), _train.getName() }));
return false;
}
// does the train accept the engine owner from the staging track?
if (!_train.acceptsOwnerName(eng.getOwner())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineOwner"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getOwner(), _train.getName() }));
return false;
}
// does the train accept the engine built date from the staging track?
if (!_train.acceptsBuiltDate(eng.getBuilt())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineBuilt"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getBuilt(), _train.getName() }));
return false;
}
}
}
}
boolean foundCaboose = false;
boolean foundFRED = false;
if (departStageTrack.getNumberCars() > 0) {
for (RollingStock rs : carManager.getList()) {
Car car = (Car) rs;
if (car.getTrack() != departStageTrack) {
continue;
}
// ignore non-lead cars in kernels
if (car.getKernel() != null && !car.getKernel().isLead(car)) {
// ignore non-lead cars
continue;
}
// has car been assigned to another train?
if (car.getRouteLocation() != null) {
log.debug("Car ({}) has route location ({})", car.toString(), car.getRouteLocation().getName());
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepart"), new Object[] { departStageTrack.getName(), car.getTrainName() }));
return false;
}
if (car.getTrain() != null && car.getTrain() != _train) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarTrain"), new Object[] { departStageTrack.getName(), car.toString(), car.getTrainName() }));
return false;
}
// does the train accept the car type from the staging track?
if (!_train.acceptsTypeName(car.getTypeName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarType"), new Object[] { departStageTrack.getName(), car.toString(), car.getTypeName(), _train.getName() }));
return false;
}
// does the train accept the car road from the staging track?
if (!_train.acceptsRoadName(car.getRoadName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarRoad"), new Object[] { departStageTrack.getName(), car.toString(), car.getRoadName(), _train.getName() }));
return false;
}
// does the train accept the car load from the staging track?
if (!car.isCaboose() && !car.isPassenger() && (!car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) || !departStageTrack.isAddCustomLoadsEnabled() && !departStageTrack.isAddCustomLoadsAnySpurEnabled() && !departStageTrack.isAddCustomLoadsAnyStagingTrackEnabled()) && !_train.acceptsLoad(car.getLoadName(), car.getTypeName())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarLoad"), new Object[] { departStageTrack.getName(), car.toString(), car.getLoadName(), _train.getName() }));
return false;
}
// does the train accept the car owner from the staging track?
if (!_train.acceptsOwnerName(car.getOwner())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarOwner"), new Object[] { departStageTrack.getName(), car.toString(), car.getOwner(), _train.getName() }));
return false;
}
// does the train accept the car built date from the staging track?
if (!_train.acceptsBuiltDate(car.getBuilt())) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarBuilt"), new Object[] { departStageTrack.getName(), car.toString(), car.getBuilt(), _train.getName() }));
return false;
}
// does the car have a destination serviced by this train?
if (car.getDestination() != null) {
log.debug("Car ({}) has a destination ({}, {})", car.toString(), car.getDestinationName(), car.getDestinationTrackName());
if (!_train.services(car)) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarDestination"), new Object[] { departStageTrack.getName(), car.toString(), car.getDestinationName(), _train.getName() }));
return false;
}
}
// is this car a caboose with the correct road for this train?
if (car.isCaboose() && (_train.getCabooseRoad().equals(Train.NONE) || _train.getCabooseRoad().equals(car.getRoadName()))) {
foundCaboose = true;
}
// is this car have a FRED with the correct road for this train?
if (car.hasFred() && (_train.getCabooseRoad().equals(Train.NONE) || _train.getCabooseRoad().equals(car.getRoadName()))) {
foundFRED = true;
}
}
}
// does the train require a caboose and did we find one from staging?
if ((_train.getRequirements() & Train.CABOOSE) == Train.CABOOSE && !foundCaboose) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNoCaboose"), new Object[] { departStageTrack.getName(), _train.getCabooseRoad() }));
return false;
}
// does the train require a car with FRED and did we find one from staging?
if ((_train.getRequirements() & Train.FRED) == Train.FRED && !foundFRED) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNoCarFRED"), new Object[] { departStageTrack.getName(), _train.getCabooseRoad() }));
return false;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrainCanDepartTrack"), new Object[] { _train.getName(), departStageTrack.getName() }));
return true;
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class TrainBuilder method placeCars.
/**
* Main routine to place cars into the train. Can be called multiple times,
* percent controls how many cars are placed in any given pass. When
* departing staging, ignore those cars on the first pass unless the option
* to build normal was selected by user.
*
* @param percent How much of the available moves should be used in this
* pass.
* @param firstPass True if first pass, ignore cars in staging.
*/
private void placeCars(int percent, boolean firstPass) throws BuildFailedException {
// add line when in normal report mode
addLine(_buildReport, THREE, BLANK_LINE);
if (percent < 100) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildMultiplePass"), new Object[] { percent }));
multipass = true;
}
if (percent == 100 && multipass) {
addLine(_buildReport, THREE, Bundle.getMessage("buildFinalPass"));
}
// now go through each location starting at departure and place cars as requested
for (int routeIndex = 0; routeIndex < _routeList.size(); routeIndex++) {
RouteLocation rl = _routeList.get(routeIndex);
if (_train.skipsLocation(rl.getId())) {
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildLocSkipped"), new Object[] { rl.getName(), rl.getId(), _train.getName() }));
continue;
}
if (!rl.isPickUpAllowed()) {
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildLocNoPickups"), new Object[] { _train.getRoute().getName(), rl.getId(), rl.getName() }));
continue;
}
// no pick ups from staging unless at the start of the train's route
if (routeIndex > 0 && rl.getLocation().isStaging()) {
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildNoPickupsFromStaging"), new Object[] { rl.getName() }));
continue;
}
// the next check provides a build report message if there's an issue with the train direction
if (!checkPickUpTrainDirection(rl)) {
continue;
}
// the number of moves completed for this location
_completedMoves = 0;
// true when done with this location
_success = true;
// the number of moves requested
_reqNumOfMoves = (rl.getMaxCarMoves() - rl.getCarMoves()) * percent / 99;
// round up requested moves if less than half way through build. Improves pickups when the move count is small.
int remainder = (rl.getMaxCarMoves() - rl.getCarMoves()) % (100 / percent);
if (percent < 51 && remainder > 0) {
_reqNumOfMoves++;
}
// multiple pass build?
if (firstPass) {
// Departing staging?
if (routeIndex == 0 && _departStageTrack != null) {
// Move cars out of staging after working other locations
_reqNumOfMoves = 0;
// if leaving and returning to staging on the same track temporary pull cars off the track
if (_departStageTrack == _terminateStageTrack) {
if (!_train.isAllowReturnToStagingEnabled() && !Setup.isAllowReturnToStagingEnabled()) {
// takes care of cars in a kernel by getting all cars
for (RollingStock rs : carManager.getList()) {
// don't remove caboose or car with FRED already assigned to train
if (rs.getTrack() == _departStageTrack && rs.getRouteDestination() == null) {
rs.setLocation(rs.getLocation(), null);
}
}
} else {
// since all cars can return to staging, the track space is consumed for now
addLine(_buildReport, THREE, BLANK_LINE);
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildWarnDepartStaging"), new Object[] { _departStageTrack.getLocation().getName(), _departStageTrack.getName() }));
addLine(_buildReport, THREE, BLANK_LINE);
}
}
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildDepartStagingAggressive"), new Object[] { _departStageTrack.getLocation().getName() }));
}
} else if (routeIndex == 0 && _departStageTrack != null && _departStageTrack == _terminateStageTrack && !_train.isAllowReturnToStagingEnabled() && !Setup.isAllowReturnToStagingEnabled()) {
// restore departure track for cars departing staging
for (Car car : _carList) {
if (car.getLocation() == _departStageTrack.getLocation() && car.getTrack() == null) {
// force
car.setLocation(_departStageTrack.getLocation(), _departStageTrack, RollingStock.FORCE);
if (car.getKernel() != null) {
for (Car k : car.getKernel().getCars()) {
// force
k.setLocation(_departStageTrack.getLocation(), _departStageTrack, RollingStock.FORCE);
}
}
}
}
}
// save a copy for status message
int saveReqMoves = _reqNumOfMoves;
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildLocReqMoves"), new Object[] { rl.getName(), rl.getId(), _reqNumOfMoves, rl.getMaxCarMoves() - rl.getCarMoves(), rl.getMaxCarMoves() }));
// add line when in detailed report mode
addLine(_buildReport, FIVE, BLANK_LINE);
// show the car load generation options for staging
if (routeIndex == 0 && _departStageTrack != null && _reqNumOfMoves > 0 && (_departStageTrack.isAddCustomLoadsEnabled() || _departStageTrack.isAddCustomLoadsAnySpurEnabled() || _departStageTrack.isAddCustomLoadsAnyStagingTrackEnabled())) {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCustomLoadOptions"), new Object[] { _departStageTrack.getName() }));
if (_departStageTrack.isAddCustomLoadsEnabled()) {
addLine(_buildReport, FIVE, Bundle.getMessage("buildLoadCarLoads"));
}
if (_departStageTrack.isAddCustomLoadsAnySpurEnabled()) {
addLine(_buildReport, FIVE, Bundle.getMessage("buildLoadAnyCarLoads"));
}
if (_departStageTrack.isAddCustomLoadsAnyStagingTrackEnabled()) {
addLine(_buildReport, FIVE, Bundle.getMessage("buildLoadsStaging"));
}
// add line when in detailed report mode
addLine(_buildReport, FIVE, BLANK_LINE);
}
// see reportCarsNotMoved(rl, percent) below
_carIndex = 0;
findDestinationsForCarsFromLocation(rl, routeIndex, false);
// only in aggressive mode, and at least one car has a new destination
if (Setup.isBuildAggressive() && saveReqMoves != _reqNumOfMoves) {
log.debug("Perform extra pass at location ({})", rl.getName());
// use up to half of the available moves left for this location
if (_reqNumOfMoves < (rl.getMaxCarMoves() - rl.getCarMoves()) * percent / 200) {
_reqNumOfMoves = (rl.getMaxCarMoves() - rl.getCarMoves()) * percent / 200;
}
findDestinationsForCarsFromLocation(rl, routeIndex, true);
}
// we might have freed up space at a spur that has an alternate track
if (redirectCarsFromAlternateTrack()) {
// add line when in very detailed report mode
addLine(_buildReport, SEVEN, BLANK_LINE);
}
if (routeIndex == 0) {
// report ASAP that the build has failed
checkDepartureForStaging(percent);
}
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildStatusMsg"), new Object[] { (saveReqMoves <= _completedMoves ? Bundle.getMessage("Success") : Bundle.getMessage("Partial")), Integer.toString(_completedMoves), Integer.toString(saveReqMoves), rl.getName(), _train.getName() }));
reportCarsNotMoved(rl, percent);
}
// covers the cases: no pick ups, wrong train direction and train skips,
checkDepartureForStaging(percent);
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class CarManagerTest method testListCarsByTrain.
public void testListCarsByTrain() {
resetCarManager();
CarManager manager = CarManager.instance();
List<RollingStock> carList;
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
r.addLocation(l3);
Train t1;
Train t3;
t1 = new Train("id1", "F");
t1.setRoute(r);
t3 = new Train("id3", "E");
t3.setRoute(r);
c1.setTrain(t1);
c2.setTrain(t3);
c3.setTrain(t3);
c4.setTrain(new Train("id4", "B"));
c5.setTrain(t3);
c6.setTrain(new Train("id6", "A"));
// now get cars by train
carList = manager.getByTrainList();
Assert.assertEquals("Number of Cars by train", 6, carList.size());
Assert.assertEquals("1st car in list by train", c6, carList.get(0));
Assert.assertEquals("2nd car in list by train", c4, carList.get(1));
Assert.assertEquals("3rd car in list by train", c5, carList.get(2));
Assert.assertEquals("4th car in list by train", c2, carList.get(3));
Assert.assertEquals("5th car in list by train", c3, carList.get(4));
Assert.assertEquals("6th car in list by train", c1, carList.get(5));
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class CarsTableFrameTest method testCarsTableFrame.
@Test
public void testCarsTableFrame() throws Exception {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// remove previous cars
CarManager.instance().dispose();
CarRoads.instance().dispose();
// add Owner1 and Owner2
CarOwners co = CarOwners.instance();
co.addName("Owner1");
co.addName("Owner2");
// add road names
CarRoads cr = CarRoads.instance();
cr.addName("NH");
cr.addName("UP");
cr.addName("AA");
cr.addName("SP");
// add locations
LocationManager lManager = LocationManager.instance();
Location westford = lManager.newLocation("Newer Westford");
Track westfordYard = westford.addTrack("Yard", Track.YARD);
westfordYard.setLength(300);
Track westfordSiding = westford.addTrack("Siding", Track.SPUR);
westfordSiding.setLength(300);
Track westfordAble = westford.addTrack("Able", Track.SPUR);
westfordAble.setLength(300);
Location boxford = lManager.newLocation("Newer Boxford");
Track boxfordYard = boxford.addTrack("Yard", Track.YARD);
boxfordYard.setLength(300);
Track boxfordJacobson = boxford.addTrack("Jacobson", Track.SPUR);
boxfordJacobson.setLength(300);
Track boxfordHood = boxford.addTrack("Hood", Track.SPUR);
boxfordHood.setLength(300);
// enable rfid field
Setup.setRfidEnabled(true);
CarsTableFrame ctf = new CarsTableFrame(true, null, null);
// show all cars?
Assert.assertTrue("show all cars", ctf.showAllCars);
// table should be empty
Assert.assertEquals("number of cars", "0", ctf.numCars.getText());
CarManager cManager = CarManager.instance();
// confirm no cars
Assert.assertEquals("number of cars", 0, cManager.getNumEntries());
// add 5 cars to table
loadCars();
Car c1 = cManager.getByRoadAndNumber("NH", "1");
Assert.assertNotNull(c1);
Assert.assertEquals("c1 location", Track.OKAY, c1.setLocation(westford, westfordYard));
Assert.assertEquals("c1 destination", Track.OKAY, c1.setDestination(boxford, boxfordJacobson));
Car c2 = cManager.getByRoadAndNumber("UP", "22");
Assert.assertNotNull(c2);
Car c3 = cManager.getByRoadAndNumber("AA", "3");
Assert.assertNotNull(c3);
Assert.assertEquals("c3 location", Track.OKAY, c3.setLocation(boxford, boxfordHood));
Assert.assertEquals("c3 destination", Track.OKAY, c3.setDestination(boxford, boxfordYard));
Car c4 = cManager.getByRoadAndNumber("SP", "2");
Assert.assertNotNull(c4);
Assert.assertEquals("c4 location", Track.OKAY, c4.setLocation(westford, westfordSiding));
Assert.assertEquals("c4 destination", Track.OKAY, c4.setDestination(boxford, boxfordHood));
Car c5 = cManager.getByRoadAndNumber("NH", "5");
Assert.assertEquals("c5 location", Track.OKAY, c5.setLocation(westford, westfordAble));
Assert.assertEquals("c5 destination", Track.OKAY, c5.setDestination(westford, westfordAble));
Assert.assertEquals("number of cars", "5", ctf.numCars.getText());
// default is sort by number
List<RollingStock> cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by number list", c1.getId(), cars.get(0).getId());
Assert.assertEquals("2nd car in sort by number list", c4.getId(), cars.get(1).getId());
Assert.assertEquals("3rd car in sort by number list", c3.getId(), cars.get(2).getId());
Assert.assertEquals("4th car in sort by number list", c5.getId(), cars.get(3).getId());
Assert.assertEquals("5th car in sort by number list", c2.getId(), cars.get(4).getId());
// now sort by built date
enterClickAndLeave(ctf.sortByBuilt);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by built list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by built list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by built list", c2, cars.get(2));
Assert.assertEquals("4th car in sort by built list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by built list", c1, cars.get(4));
// now sort by color
enterClickAndLeave(ctf.sortByColor);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by color list", c4.getId(), cars.get(0).getId());
Assert.assertEquals("2nd car in sort by color list", c2.getId(), cars.get(1).getId());
Assert.assertEquals("3rd car in sort by color list", c5.getId(), cars.get(2).getId());
Assert.assertEquals("4th car in sort by color list", c1.getId(), cars.get(3).getId());
Assert.assertEquals("5th car in sort by color list", c3.getId(), cars.get(4).getId());
enterClickAndLeave(ctf.sortByDestination);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by destination list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by destination list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by destination list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by destination list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by destination list", c5, cars.get(4));
enterClickAndLeave(ctf.sortByKernel);
//TODO add kernels
// now sort by load
enterClickAndLeave(ctf.sortByLoad);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by load list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by load list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by load list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by load list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by load list", c5, cars.get(4));
// now sort by location
enterClickAndLeave(ctf.sortByLocation);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by location list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by location list", c3, cars.get(1));
Assert.assertEquals("3rd car in sort by location list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by location list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by location list", c1, cars.get(4));
// now sort by moves
enterClickAndLeave(ctf.sortByMoves);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by move list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by move list", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by move list", c3, cars.get(2));
Assert.assertEquals("4th car in sort by move list", c2, cars.get(3));
Assert.assertEquals("5th car in sort by move list", c1, cars.get(4));
// test sort by number again
enterClickAndLeave(ctf.sortByNumber);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by number list 2", c1, cars.get(0));
Assert.assertEquals("2nd car in sort by number list 2", c4, cars.get(1));
Assert.assertEquals("3rd car in sort by number list 2", c3, cars.get(2));
Assert.assertEquals("4th car in sort by number list 2", c5, cars.get(3));
Assert.assertEquals("5th car in sort by number list 2", c2, cars.get(4));
// test sort by owner
//enterClickAndLeave(ctf.sortByOwner);
ctf.sortByOwner.doClick();
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by owner list", c4, cars.get(0));
Assert.assertEquals("2nd car in sort by owner list", c3, cars.get(1));
Assert.assertEquals("3rd car in sort by owner list", c2, cars.get(2));
Assert.assertEquals("4th car in sort by owner list", c5, cars.get(3));
Assert.assertEquals("5th car in sort by owner list", c1, cars.get(4));
// test sort by rfid
//enterClickAndLeave(ctf.sortByRfid);
// use doClick() in case the radio button isn't visible due to scrollbars
ctf.sortByRfid.doClick();
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by rfid list", c5, cars.get(0));
Assert.assertEquals("2nd car in sort by rfid list", c2, cars.get(1));
Assert.assertEquals("3rd car in sort by rfid list", c1, cars.get(2));
Assert.assertEquals("4th car in sort by rfid list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by rfid list", c3, cars.get(4));
// test sort by road
enterClickAndLeave(ctf.sortByRoad);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by road list", c3, cars.get(0));
Assert.assertEquals("2nd car in sort by road list", c1, cars.get(1));
Assert.assertEquals("3rd car in sort by road list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by road list", c4, cars.get(3));
Assert.assertEquals("5th car in sort by road list", c2, cars.get(4));
enterClickAndLeave(ctf.sortByTrain);
//TODO add trains
// test sort by type
enterClickAndLeave(ctf.sortByType);
cars = ctf.carsTableModel.getSelectedCarList();
Assert.assertEquals("1st car in sort by type list", c2, cars.get(0));
Assert.assertEquals("2nd car in sort by type list", c1, cars.get(1));
Assert.assertEquals("3rd car in sort by type list", c5, cars.get(2));
Assert.assertEquals("4th car in sort by type list", c3, cars.get(3));
Assert.assertEquals("5th car in sort by type list", c4, cars.get(4));
// test find text field
ctf.findCarTextBox.setText("*2");
enterClickAndLeave(ctf.findButton);
// table is sorted by type, cars with number 2 are in the first and last rows
Assert.assertEquals("find car by number 1st", 0, ctf.carsTable.getSelectedRow());
enterClickAndLeave(ctf.findButton);
Assert.assertEquals("find car by number 2nd", 4, ctf.carsTable.getSelectedRow());
// create the CarEditFrame
enterClickAndLeave(ctf.addButton);
ctf.dispose();
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class CarManagerTest method testListCarsBySpecifiedTrain.
public void testListCarsBySpecifiedTrain() {
resetCarManager();
CarManager manager = CarManager.instance();
List<RollingStock> carList;
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
r.addLocation(l3);
Train t1;
Train t3;
t1 = new Train("id1", "F");
t1.setRoute(r);
t3 = new Train("id3", "E");
t3.setRoute(r);
c1.setTrain(t1);
c2.setTrain(t3);
c3.setTrain(t3);
c4.setTrain(new Train("id4", "B"));
c5.setTrain(t3);
c6.setTrain(new Train("id6", "A"));
// now get cars by specific train
carList = manager.getByTrainList(t1);
Assert.assertEquals("Number of Cars in t1", 1, carList.size());
Assert.assertEquals("1st car in list by t1", c1, carList.get(0));
carList = manager.getByTrainList(t3);
Assert.assertEquals("Number of Cars in t3", 3, carList.size());
Assert.assertEquals("1st car in list by t3", c5, carList.get(0));
Assert.assertEquals("2nd car in list by t3", c2, carList.get(1));
Assert.assertEquals("3rd car in list by t3", c3, carList.get(2));
}
Aggregations