use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class Track method getNextScheduleItem.
public ScheduleItem getNextScheduleItem() {
Schedule sch = getSchedule();
if (sch == null) {
log.warn("Can not find schedule (" + getScheduleId() + ") assigned to track (" + getName() + ")");
return null;
}
List<ScheduleItem> items = sch.getItemsBySequenceList();
ScheduleItem nextSi = null;
for (int i = 0; i < items.size(); i++) {
nextSi = items.get(i);
if (getCurrentScheduleItem() == nextSi) {
if (++i < items.size()) {
nextSi = items.get(i);
} else {
nextSi = items.get(0);
}
setScheduleItemId(nextSi.getId());
break;
}
}
return nextSi;
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class Track method getCurrentScheduleItem.
/**
* Get's the current schedule item for this track Protects against user
* deleting an item in a shared schedule. Recommend using this versus
* getScheduleItemId() as the id can be obsolete.
* @return The current ScheduleItem.
*/
public ScheduleItem getCurrentScheduleItem() {
Schedule sch = getSchedule();
if (sch == null) {
log.debug("Can not find schedule id: ({}) assigned to track ({})", getScheduleId(), getName());
return null;
}
ScheduleItem currentSi = sch.getItemById(getScheduleItemId());
if (currentSi == null && sch.getSize() > 0) {
log.debug("Can not find schedule item id: ({}) for schedule ({})", getScheduleItemId(), getScheduleName());
// reset schedule
setScheduleItemId((sch.getItemsBySequenceList().get(0)).getId());
currentSi = sch.getItemById(getScheduleItemId());
}
return currentSi;
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class TrainBuilder method getScheduleItem.
/**
* Used when generating a car load from staging.
*
* @param car the car.
* @param track the car's destination track that has the schedule.
* @return ScheduleItem si if match found, null otherwise.
*/
private ScheduleItem getScheduleItem(Car car, Track track) throws BuildFailedException {
if (track.getSchedule() == null) {
return null;
}
if (!track.acceptsTypeName(car.getTypeName())) {
log.debug("Track ({}) doesn't service car type ({})", track.getName(), car.getTypeName());
if (!Setup.getRouterBuildReportLevel().equals(Setup.BUILD_REPORT_NORMAL)) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSpurNotThisType"), new Object[] { track.getLocation().getName(), track.getName(), track.getScheduleName(), car.getTypeName() }));
}
return null;
}
ScheduleItem si = null;
if (track.getScheduleMode() == Track.SEQUENTIAL) {
si = track.getCurrentScheduleItem();
if (si == null) {
throw new BuildFailedException(MessageFormat.format(Bundle.getMessage("buildErrorNoScheduleItem"), new Object[] { track.getScheduleItemId(), track.getScheduleName(), track.getName(), track.getLocation().getName() }));
}
return checkScheduleItem(si, car, track);
}
log.debug("Track ({}) in match mode", track.getName());
for (int i = 0; i < track.getSchedule().getSize(); i++) {
si = track.getNextScheduleItem();
if (si == null) {
throw new BuildFailedException(MessageFormat.format(Bundle.getMessage("buildErrorNoScheduleItem"), new Object[] { track.getScheduleItemId(), track.getScheduleName(), track.getName(), track.getLocation().getName() }));
}
si = checkScheduleItem(si, car, track);
if (si != null) {
break;
}
}
return si;
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedulesMatchMode.
/*
* Using the setup from the previous tests, use trains and schedules to move
* cars. This test creates 1 schedule in match mode with multiple items.
* Test uses car loads to activate schedule.
*/
public void testRoutingWithSchedulesMatchMode() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Car c7 = cmanager.getByRoadAndNumber("BA", "7");
Car c8 = cmanager.getByRoadAndNumber("BB", "8");
Car c9 = cmanager.getByRoadAndNumber("BC", "9");
Location Acton = lmanager.getLocationByName("Acton MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Location Danbury = lmanager.getLocationByName("Danbury MA");
Location Essex = lmanager.getLocationByName("Essex MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule AAA");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Empty");
schAItem1.setShipLoadName("Metal");
schAItem1.setDestination(Acton);
schAItem1.setDestinationTrack(AS1);
ScheduleItem schAItem2 = schA.addItem("Flat");
schAItem2.setReceiveLoadName("Junk");
schAItem2.setShipLoadName("Metal");
schAItem2.setDestination(Danbury);
schAItem2.setDestinationTrack(DS2);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Boxes");
schAItem3.setShipLoadName("Screws");
schAItem3.setDestination(Essex);
schAItem3.setDestinationTrack(ES1);
ScheduleItem schAItem4 = schA.addItem("Boxcar");
schAItem4.setReceiveLoadName("Boxes");
schAItem4.setShipLoadName("Bolts");
schAItem4.setDestination(Danbury);
schAItem4.setDestinationTrack(DS1);
ScheduleItem schAItem5 = schA.addItem("Boxcar");
schAItem5.setReceiveLoadName("");
schAItem5.setShipLoadName("Nuts");
schAItem5.setDestination(Essex);
schAItem5.setDestinationTrack(ES2);
// Add schedule to tracks
CS1.setScheduleId("");
ES1.setScheduleId(schA.getId());
// set schedule into match mode
ES1.setScheduleMode(Track.MATCH);
// c3 (BA 3) is a Boxcar
c3.setLoadName("Boxes");
// c4 (BB 4) is a Flat
c4.setLoadName("Junk");
// c5 (BC 5) is a Boxcar
c5.setLoadName("Boxes");
// c6 (BD 6) is a Boxcar
c6.setLoadName("Boxes");
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AS1));
// build train
Train ActonTrain = tmanager.getTrainByName("Acton Local");
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Essex Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Essex MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Essex Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Essex MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Essex Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Essex MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Essex Siding 1", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 7 destination", "Acton MA", c7.getDestinationName());
Assert.assertEquals("Car BD 7 destination track", "Acton Interchange", c7.getDestinationTrackName());
Assert.assertEquals("Car BD 7 final destination", "Essex MA", c7.getFinalDestinationName());
Assert.assertEquals("Car BD 7 final destination track", "Essex Siding 1", c7.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", schAItem3.getId(), c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", schAItem4.getId(), c6.getScheduleItemId());
Assert.assertEquals("Car BA 7 schedule id", schAItem5.getId(), c7.getScheduleItemId());
Assert.assertEquals("Car BB 8 schedule id", schAItem1.getId(), c8.getScheduleItemId());
Assert.assertEquals("Car BC 9 schedule id", schAItem5.getId(), c9.getScheduleItemId());
ActonTrain.reset();
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class ScheduleItemTest method testScheduleItemAttributes.
// test ScheduleItem attributes
public void testScheduleItemAttributes() {
ScheduleItem ltsi = new ScheduleItem("Test id", "Test Type");
Assert.assertEquals("Location ScheduleItem id", "Test id", ltsi.getId());
Assert.assertEquals("Location ScheduleItem Type", "Test Type", ltsi.getTypeName());
ltsi.setTypeName("New Test Type");
Assert.assertEquals("Location ScheduleItem set Type", "New Test Type", ltsi.getTypeName());
ltsi.setComment("New Test Comment");
Assert.assertEquals("Location ScheduleItem set Comment", "New Test Comment", ltsi.getComment());
ltsi.setRoadName("New Test Road");
Assert.assertEquals("Location ScheduleItem set Road", "New Test Road", ltsi.getRoadName());
ltsi.setReceiveLoadName("New Test Load");
Assert.assertEquals("Location ScheduleItem set Load", "New Test Load", ltsi.getReceiveLoadName());
ltsi.setShipLoadName("New Test Ship");
Assert.assertEquals("Location ScheduleItem set Ship", "New Test Ship", ltsi.getShipLoadName());
ltsi.setSequenceId(22);
Assert.assertEquals("Location ScheduleItem set SequenceId", 22, ltsi.getSequenceId());
ltsi.setCount(222);
Assert.assertEquals("Location ScheduleItem set Count", 222, ltsi.getCount());
}
Aggregations