diff --git a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle.properties b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle.properties index 0c50b45f80e..8d1e2afb0cb 100644 --- a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle.properties +++ b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle.properties @@ -860,7 +860,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra buildCanNotDropLocation = Car ({0}) type ({1}) isn''t serviced by destination ({2}) buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) -buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3}) buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6}) buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3}) buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3}) diff --git a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_da.properties b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_da.properties index e6ebd3f625b..fcf0f6892bb 100644 --- a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_da.properties +++ b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_da.properties @@ -790,7 +790,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra buildCanNotDropLocation = Can''t send ({0}) type ({1}) to destination ({2}) buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) -buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3}) buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6}) buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3}) buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3}) diff --git a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_de.properties b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_de.properties index 14770adb843..fcc94a17d2f 100644 --- a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_de.properties +++ b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_de.properties @@ -807,7 +807,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra buildCanNotDropLocation = Can''t send ({0}) type ({1}) to destination ({2}) buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) -buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3}) buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6}) buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3}) buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3}) diff --git a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_fr.properties b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_fr.properties index bfd96c1bfa3..ee99712d148 100644 --- a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_fr.properties +++ b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_fr.properties @@ -830,7 +830,6 @@ buildReturnCarToStaging = Le wagon ({0}) retourne \u00e0 la coulisse ({1}), buildCanNotDropLocation = Impossible de d\u00e9pos\u00e9 wagon ({0}) type ({1}) \u00e0 destination ({2}) buildSearchTrackNewLoad = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) charge ({2}) voie ({3}) -buildGenerateLoad = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) destination ({2}, {3}) buildSearchTrackLoadStaging = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) charge ({2}) voie ({3}) pour la coulisse ({4}, {5}) buildTrainNotNewLoad = Train ({0}) ne peut pas acheminer la charge ({1}) destination ({2}, {3}) buildTrackNotNewLoad = Voie de d\u00e9part ({0}) Impossible d'exp\u00e9dier la charge ({1}) \u00e0 destination ({2}, {3}) diff --git a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_it.properties b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_it.properties index ff4e55d5f99..d0a1466d60a 100644 --- a/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_it.properties +++ b/java/src/jmri/jmrit/operations/trains/JmritOperationsTrainsBundle_it.properties @@ -715,7 +715,6 @@ buildReturnCarToStaging = Riporto carro ({0}) al deposito nascosto ({1}), ne buildCanNotDropLocation = Non posso consegnare carro ({0}) tipo ({1}) alla destinazione ({2}) buildSearchTrackNewLoad = Genero carico per ({0}) tipo ({1}) carico ({2}) binario ({3}, {4}) -buildGenerateLoad = Genera carico per ({0}) tipo ({1}) destinazione ({2}, {3}) buildSearchTrackLoadStaging = Genera carico per ({0}) tipo ({1}) carico ({2}) binario ({3}, {4}) in deposito ({5}, {6}) buildTrainNotNewLoad = Treno ({0}) non serve carico ({1}) con destinazione ({2}, {3}) buildTrackNotNewLoad = Binario di partenza ({0}) non pu\u00f2 inviare carico ({1}) alla destinazione ({2}, {3}) diff --git a/java/src/jmri/jmrit/operations/trains/TrainBuilder.java b/java/src/jmri/jmrit/operations/trains/TrainBuilder.java index 15b4aeffec8..028d23e363f 100644 --- a/java/src/jmri/jmrit/operations/trains/TrainBuilder.java +++ b/java/src/jmri/jmrit/operations/trains/TrainBuilder.java @@ -3554,8 +3554,12 @@ private boolean findFinalDestinationForCarLoad(Car car) throws BuildFailedExcept * @throws BuildFailedException */ private boolean generateCarLoadFromStaging(Car car) throws BuildFailedException { - if (car.getTrack() == null || - !car.getTrack().isStaging() || + // Code Check, car should have a track assignment + if (car.getTrack() == null) { + throw new BuildFailedException(MessageFormat.format(Bundle.getMessage("buildErrorRsNoLoc"), + new Object[] { car.toString(), car.getLocationName() })); + } + if (!car.getTrack().isStaging() || (!car.getTrack().isAddCustomLoadsAnySpurEnabled() && !car.getTrack().isAddCustomLoadsEnabled()) || !car.getLoadName().equals(carLoads.getDefaultEmptyName()) || car.getDestination() != null || @@ -3566,8 +3570,7 @@ private boolean generateCarLoadFromStaging(Car car) throws BuildFailedException car.getLoadName(), car.getDestinationName(), car.getFinalDestinationName()); // NOI18N // if car has a destination or final destination add "no load generated" message // to report - if (car.getTrack() != null && - car.getTrack().isStaging() && + if (car.getTrack().isStaging() && car.getTrack().isAddCustomLoadsAnySpurEnabled() && car.getLoadName().equals(carLoads.getDefaultEmptyName())) { addLine(_buildReport, FIVE, @@ -3677,8 +3680,12 @@ private boolean generateCarLoadFromStaging(Car car) throws BuildFailedException * @throws BuildFailedException */ private boolean generateCarLoadStagingToStaging(Car car) throws BuildFailedException { - if (car.getTrack() == null || - !car.getTrack().isStaging() || + // Code Check, car should have a track assignment + if (car.getTrack() == null) { + throw new BuildFailedException(MessageFormat.format(Bundle.getMessage("buildErrorRsNoLoc"), + new Object[] { car.toString(), car.getLocationName() })); + } + if (!car.getTrack().isStaging() || !car.getTrack().isAddCustomLoadsAnyStagingTrackEnabled() || !car.getLoadName().equals(carLoads.getDefaultEmptyName()) || car.getDestination() != null || @@ -3847,8 +3854,8 @@ private ScheduleItem checkScheduleItem(ScheduleItem si, Car car, Track track) { if (!Setup.getRouterBuildReportLevel().equals(Setup.BUILD_REPORT_NORMAL)) { addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSpurScheduleNotUsed"), - new Object[] { track.getName(), track.getScheduleName(), si.getId(), si.getTypeName(), - si.getRoadName(), si.getReceiveLoadName() })); + new Object[] { track.getLocation().getName(), track.getName(), track.getScheduleName(), + si.getId(), si.getTypeName(), si.getRoadName(), si.getReceiveLoadName() })); } return null; } @@ -4380,6 +4387,7 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde start--; } } + // now search for a destination for this car for (int k = start; k < routeEnd; k++) { rld = _routeList.get(k); // if car can be picked up later at same location, set flag @@ -4513,54 +4521,12 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildSpurScheduleLoad"), new Object[] { testTrack.getName(), car.getLoadName() })); addCarToTrain(car, rl, rld, testTrack); - return true; - } - // is the destination a spur with a Schedule? - // and is car departing a staging track that can generate schedule loads? - // alternate track isn't checked - if (!status.equals(Track.OKAY) && !status.startsWith(Track.TYPE) // wrong car type for this spur - && !status.startsWith(Track.LENGTH) // can't generate load for spur that is full - && !status.startsWith(Track.CAPACITY) // can't use a spur that is too short - && - testTrack.isSpur() && - !testTrack.getScheduleId().equals(Track.NONE) && - (car.getTrack().isAddCustomLoadsEnabled() || - car.getTrack().isAddCustomLoadsAnySpurEnabled()) && - car.getLoadName().equals(carLoads.getDefaultEmptyName())) { - if (!testTrack.isSpaceAvailable(car)) { - addLine(_buildReport, SEVEN, - MessageFormat.format(Bundle.getMessage("buildNoDestTrackSpace"), - new Object[] { car.toString(), testTrack.getLocation().getName(), - testTrack.getName(), testTrack.getNumberOfCarsInRoute(), - testTrack.getReservedInRoute(), Setup.getLengthUnit().toLowerCase(), - testTrack.getReservationFactor() })); - continue; // no - } - addLine(_buildReport, SEVEN, - MessageFormat.format(Bundle.getMessage("buildGenerateLoad"), - new Object[] { car.toString(), car.getTypeName(), testDestination.getName(), - testTrack.getName() })); - String carLoad = car.getLoadName(); // save the car's load (default empty) - ScheduleItem si = getScheduleItem(car, testTrack); - if (si != null) { - car.setLoadName(si.getReceiveLoadName()); - if (car.testDestination(testDestination, testTrack).equals(Track.OKAY)) { - addLine(_buildReport, FIVE, - MessageFormat.format(Bundle.getMessage("buildAddingScheduleLoad"), - new Object[] { si.getReceiveLoadName(), car.toString() })); - car.setLoadGeneratedFromStaging(true); - testTrack.bumpSchedule(); - addCarToTrain(car, rl, rld, testTrack); - return true; - } - } - car.setLoadName(carLoad); // restore car's load (default empty) + return true; // done with this car } - // check to see if alternate track is available if track full and no schedule + // check to see if alternate track is available if track full if (status.startsWith(Track.LENGTH) && testTrack.getAlternateTrack() != null && car.getFinalDestination() == null && - testTrack.getScheduleId().equals(Track.NONE) && car.getTrack() != testTrack.getAlternateTrack() && checkTrainCanDrop(car, testTrack.getAlternateTrack())) { addLine(_buildReport, SEVEN, @@ -4577,7 +4543,7 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde } finalDestinationTrackTemp = testTrack; trackTemp = testTrack.getAlternateTrack(); // send car to alternate track - break; + break; // done with this destination } // okay to drop car? if (!status.equals(Track.OKAY)) { @@ -4586,38 +4552,11 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde car.toString(), testTrack.getName(), status, testTrack.getTrackTypeName() })); continue; } - // No local moves from spur to spur - if (_train.isLocalSwitcher() && - !Setup.isLocalSpurMovesEnabled() && - testTrack.isSpur() && - car.getTrack().isSpur()) { - addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoSpurToSpurMove"), - new Object[] { car.getTrackName(), testTrack.getName() })); - continue; - } - // No local moves from yard to yard, except for cabooses and cars with FRED - if (_train.isLocalSwitcher() && - !Setup.isLocalYardMovesEnabled() && - testTrack.isYard() && - car.getTrack().isYard() && - !car.isCaboose() && - !car.hasFred()) { - addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoYardToYardMove"), - new Object[] { car.getTrackName(), testTrack.getName() })); - continue; - } - // No local moves from interchange to interchange - if (_train.isLocalSwitcher() && - !Setup.isLocalInterchangeMovesEnabled() && - testTrack.isInterchange() && - car.getTrack().isInterchange()) { - addLine(_buildReport, SEVEN, - MessageFormat.format(Bundle.getMessage("buildNoInterchangeToInterchangeMove"), - new Object[] { car.getTrackName(), testTrack.getName() })); + if (!checkForLocalMove(car, testTrack)) { continue; } trackTemp = testTrack; - break; + break; // done with this destination } } // did we find a new destination? @@ -4635,28 +4574,13 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde } // if there's more than one available destination use the lowest ratio if (rldSave != null) { + // check for an earlier drop in the route + rld = checkForEarlierDrop(car, trackTemp, rld, start, routeEnd); double saveCarMoves = rldSave.getCarMoves(); double saveRatio = saveCarMoves / rldSave.getMaxCarMoves(); double nextCarMoves = rld.getCarMoves(); double nextRatio = nextCarMoves / rld.getMaxCarMoves(); - // check for an earlier drop in the route - for (int m = start; m < routeEnd; m++) { - RouteLocation rle = _routeList.get(m); - if (rle == rld) { - break; // done - } - if (rle.getName().equals(rld.getName()) && - (rle.getCarMoves() < rle.getMaxCarMoves()) && - rle.isDropAllowed() && - checkDropTrainDirection(car, rle, trackTemp)) { - log.debug("Found an earlier drop for car ({}) destination ({})", car.toString(), - rle.getName()); // NOI18N - nextCarMoves = rle.getCarMoves(); - nextRatio = nextCarMoves / rle.getMaxCarMoves(); - rld = rle; // set car drop to earlier stop - break; - } - } + // bias cars to the terminal if (rld == _train.getTrainTerminatesRouteLocation()) { nextRatio = nextRatio * nextRatio; @@ -4669,7 +4593,7 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde log.debug("Track ({}) has schedule ({}), adjusted nextRatio {}", trackTemp.getName(), trackTemp.getScheduleName(), Double.toString(nextRatio)); } - // bias cars with default loads to a track with a schedule + // bias cars with default loads to saved track with a schedule if (trackSave != null && !trackSave.getScheduleId().equals(Track.NONE)) { saveRatio = saveRatio * saveRatio; log.debug("Saved track ({}) has schedule ({}), adjusted nextRatio {}", trackSave.getName(), @@ -4715,6 +4639,61 @@ private boolean findDestinationAndTrack(Car car, RouteLocation rl, int routeInde return false; // no build errors, but car not given destination } + private RouteLocation checkForEarlierDrop(Car car, Track trackTemp, RouteLocation rld, int start, int routeEnd) { + for (int m = start; m < routeEnd; m++) { + RouteLocation rle = _routeList.get(m); + if (rle == rld) { + break; + } + if (rle.getName().equals(rld.getName()) && + (rle.getCarMoves() < rle.getMaxCarMoves()) && + rle.isDropAllowed() && + checkDropTrainDirection(car, rle, trackTemp)) { + log.debug("Found an earlier drop for car ({}) destination ({})", car.toString(), rle.getName()); // NOI18N + return rle; // earlier drop in train's route + } + } + return rld; + } + + /** + * Checks to see if local move is allowed for this car + * + * @param car the car being moved + * @param testTrack the destination track for this car + * @return false if local move not allowed + */ + private boolean checkForLocalMove(Car car, Track testTrack) { + if (_train.isLocalSwitcher()) { + // No local moves from spur to spur + if (!Setup.isLocalSpurMovesEnabled() && testTrack.isSpur() && car.getTrack().isSpur()) { + addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoSpurToSpurMove"), + new Object[] { car.getTrackName(), testTrack.getName() })); + return false; + } + // No local moves from yard to yard, except for cabooses and cars with FRED + if (!Setup.isLocalYardMovesEnabled() && + testTrack.isYard() && + car.getTrack().isYard() && + !car.isCaboose() && + !car.hasFred()) { + addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoYardToYardMove"), + new Object[] { car.getTrackName(), testTrack.getName() })); + return false; + } + // No local moves from interchange to interchange + if (!Setup.isLocalInterchangeMovesEnabled() && + testTrack.isInterchange() && + car.getTrack().isInterchange()) { + addLine(_buildReport, SEVEN, + MessageFormat.format(Bundle.getMessage("buildNoInterchangeToInterchangeMove"), + new Object[] { car.getTrackName(), testTrack.getName() })); + return false; + } + } + return true; + } + private Track tryStaging(Car car, RouteLocation rldSave) { // local switcher working staging? if (_train.isLocalSwitcher() && @@ -4939,7 +4918,7 @@ private boolean generateLoadCarDepartingAndTerminatingIntoStaging(Car car, Track private boolean redirectCarsFromAlternateTrack() throws BuildFailedException { // code check, should be aggressive if (!Setup.isBuildAggressive()) { - throw new BuildFailedException("Coding issue, should be using aggressive mode"); + throw new BuildFailedException("ERROR coding issue, should be using aggressive mode"); } boolean redirected = false; List cars = carManager.getByTrainList(_train); @@ -5046,7 +5025,7 @@ private void checkEngineHP() throws BuildFailedException { // there should be at least one engine assigned to this train Engine leadEngine = _train.getLeadEngine(); if (leadEngine == null) - throw new BuildFailedException("Coding issue, engine missing from checkEngineHP()"); + throw new BuildFailedException("ERROR coding issue, engine missing from checkEngineHP()"); addLine(_buildReport, ONE, BLANK_LINE); addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildDetermineHpNeeded"), new Object[] { leadEngine.toString(), leadEngine.getHp(), Setup.getHorsePowerPerTon() })); diff --git a/java/src/jmri/jmrit/operations/trains/TrainCommon.java b/java/src/jmri/jmrit/operations/trains/TrainCommon.java index d9a37766c90..cdbd6951d28 100644 --- a/java/src/jmri/jmrit/operations/trains/TrainCommon.java +++ b/java/src/jmri/jmrit/operations/trains/TrainCommon.java @@ -36,7 +36,7 @@ /** * Common routines for trains * - * @author Daniel Boudreau (C) Copyright 2008, 2009, 2010, 2011, 2012, 2013 + * @author Daniel Boudreau (C) Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2021 */ public class TrainCommon { @@ -50,7 +50,6 @@ public class TrainCommon { protected static final String VERTICAL_LINE_CHAR = "|"; protected static final String TEXT_COLOR_START = " engineList, Ro } /** - * Adds a list of locomotive pick ups for the route location to the output - * file. Used to generate "Standard" format. + * Adds a list of locomotive pick ups for the route location to the output file. + * Used to generate "Standard" format. * * @param file Manifest or Switch List File * @param engineList List of engines for this train. @@ -129,7 +128,7 @@ private void pickupEngine(PrintWriter file, Engine engine, boolean isManifest) { String s = getEngineAttribute(engine, attribute, PICKUP); if (!checkStringLength(buf.toString() + s, isManifest)) { addLine(file, buf.toString()); - buf = new StringBuffer(TAB); + buf = new StringBuffer(TAB); // new line } buf.append(s); } @@ -137,8 +136,8 @@ private void pickupEngine(PrintWriter file, Engine engine, boolean isManifest) { } /** - * Adds a list of locomotive drops for the route location to the output - * file. Used to generate "Standard" format. + * Adds a list of locomotive drops for the route location to the output file. + * Used to generate "Standard" format. * * @param file Manifest or Switch List File * @param engineList List of engines for this train. @@ -166,7 +165,7 @@ private void dropEngine(PrintWriter file, Engine engine, boolean isManifest) { String s = getEngineAttribute(engine, attribute, !PICKUP); if (!checkStringLength(buf.toString() + s, isManifest)) { addLine(file, buf.toString()); - buf = new StringBuffer(TAB); + buf = new StringBuffer(TAB); // new line } buf.append(s); } @@ -209,8 +208,8 @@ public String dropEngine(Engine engine) { boolean printLocalMoveHeader = true; /** - * 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. + * 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. * * @param file Manifest or switch list File * @param train The train being printed. @@ -285,10 +284,6 @@ else if (isManifest && pickUpCar(file, car, isManifest); } pickupCars = true; -// cars++; -// if (car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) { -// emptyCars++; -// } } } if (isOnlyPassenger) { @@ -348,11 +343,6 @@ else if (isManifest && dropCar(file, car, isManifest); } dropCars = true; -// cars--; -// if (InstanceManager.getDefault(CarLoads.class).getLoadType(car.getTypeName(), car.getLoadName()) -// .equals(CarLoad.LOAD_TYPE_EMPTY)) { -// emptyCars--; -// } } } if (!Setup.isSortByTrackNameEnabled()) { @@ -362,9 +352,8 @@ else if (isManifest && } /** - * Produces a two column format for car pick ups and set outs. Sorted by - * track and then by destination. This routine is used for the "Two Column" - * format. + * Produces a two column format for car pick ups and set outs. Sorted by track + * and then by destination. This routine is used for the "Two Column" format. * * @param file Manifest or switch list File * @param carList List of cars for this train @@ -373,8 +362,8 @@ else if (isManifest && * @param printHeader True if new location. * @param isManifest True if manifest, false if switch list. */ - protected void blockCarsTwoColumn(PrintWriter file, List carList, - List routeList, RouteLocation rl, boolean printHeader, boolean isManifest) { + protected void blockCarsTwoColumn(PrintWriter file, List carList, List routeList, + RouteLocation rl, boolean printHeader, boolean isManifest) { index = 0; int lineLength = getLineLength(isManifest); List tracks = rl.getLocation().getTracksByNameList(null); @@ -408,10 +397,6 @@ protected void blockCarsTwoColumn(PrintWriter file, List carList, continue; } pickupCars = true; -// cars++; -// if (car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) { -// emptyCars++; -// } String s; if (car.isUtility()) { s = pickupUtilityCars(carList, car, isManifest, !IS_TWO_COLUMN_TRACK); @@ -462,10 +447,9 @@ protected void blockCarsTwoColumn(PrintWriter file, List carList, List doneCars = new ArrayList<>(); /** - * 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. + * 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. * * @param file Manifest or switch list File * @param carList List of cars for this train @@ -474,8 +458,8 @@ protected void blockCarsTwoColumn(PrintWriter file, List carList, * @param printHeader True if new location. * @param isManifest True if manifest, false if switch list. */ - protected void blockCarsByTrackNameTwoColumn(PrintWriter file, List carList, - List routeList, RouteLocation rl, boolean printHeader, boolean isManifest) { + protected void blockCarsByTrackNameTwoColumn(PrintWriter file, List carList, List routeList, + RouteLocation rl, boolean printHeader, boolean isManifest) { index = 0; List tracks = rl.getLocation().getTracksByNameList(null); List trackNames = new ArrayList<>(); @@ -508,10 +492,6 @@ protected void blockCarsByTrackNameTwoColumn(PrintWriter file, List carList } trackNames.add(trackName); // use a track name once pickupCars = true; -// cars++; -// if (car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) { -// emptyCars++; -// } String s; if (car.isUtility()) { s = pickupUtilityCars(carList, car, isManifest, IS_TWO_COLUMN_TRACK); @@ -590,8 +570,8 @@ protected void printTrackComments(PrintWriter file, RouteLocation rl, List int index = 0; /* - * Used by two column format. Local moves (pulls and spots) are lined up - * when using this format, + * Used by two column format. Local moves (pulls and spots) are lined up when + * using this format, */ private String appendSetoutString(String s, List carList, RouteLocation rl, boolean local, boolean isManifest, boolean isTwoColumnTrack) { @@ -635,17 +615,12 @@ private String appendSetoutString(String s, String trackName, List carList, } /* - * Appends to string the vertical line character, and the car set out - * string. Used in two column format. + * Appends to string the vertical line character, and the car set out string. + * Used in two column format. */ private String appendSetoutString(String s, List carList, RouteLocation rl, Car car, boolean isManifest, boolean isTwoColumnTrack) { dropCars = true; -// cars--; -// if (car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) { -// emptyCars--; -// } - String dropText; if (car.isUtility()) { @@ -663,8 +638,8 @@ private String appendSetoutString(String s, List carList, RouteLocation rl, } /** - * Adds the car's pick up string to the output file using the truncated - * manifest format + * Adds the car's pick up string to the output file using the truncated manifest + * format * * @param file Manifest or switch list File * @param car The car being printed. @@ -677,8 +652,8 @@ protected void pickUpCarTruncated(PrintWriter file, Car car, boolean isManifest) } /** - * Adds the car's pick up string to the output file using the manifest or - * switch list format + * Adds the car's pick up string to the output file using the manifest or switch + * list format * * @param file Manifest or switch list File * @param car The car being printed. @@ -687,7 +662,8 @@ protected void pickUpCarTruncated(PrintWriter file, Car car, boolean isManifest) protected void pickUpCar(PrintWriter file, Car car, boolean isManifest) { if (isManifest) { pickUpCar(file, car, - new StringBuffer(padAndTruncateIfNeeded(Setup.getPickupCarPrefix(), Setup.getManifestPrefixLength())), + new StringBuffer( + padAndTruncateIfNeeded(Setup.getPickupCarPrefix(), Setup.getManifestPrefixLength())), Setup.getPickupManifestMessageFormat(), isManifest); } else { pickUpCar(file, car, new StringBuffer( @@ -704,7 +680,7 @@ private void pickUpCar(PrintWriter file, Car car, StringBuffer buf, String[] for String s = getCarAttribute(car, attribute, PICKUP, !LOCAL); if (!checkStringLength(buf.toString() + s, isManifest)) { addLine(file, buf.toString()); - buf = new StringBuffer(TAB); + buf = new StringBuffer(TAB); // new line } buf.append(s); } @@ -715,14 +691,14 @@ private void pickUpCar(PrintWriter file, Car car, StringBuffer buf, String[] for } /** - * Returns the pick up car string. Useful for frames like train conductor - * and yardmaster. + * Returns the pick up car string. Useful for frames like train conductor and + * yardmaster. * * @param car The car being printed. - * @param isManifest when true use manifest format, when false use - * switch list format - * @param isTwoColumnTrack True if printing using two column format sorted - * by track name. + * @param isManifest when true use manifest format, when false use switch + * list format + * @param isTwoColumnTrack True if printing using two column format sorted by + * track name. * @return pick up car string */ public String pickupCar(Car car, boolean isManifest, boolean isTwoColumnTrack) { @@ -745,9 +721,9 @@ public String pickupCar(Car car, boolean isManifest, boolean isTwoColumnTrack) { } /** - * 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. + * 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. * * @param file Manifest or switch list File * @param car The car being printed. @@ -763,8 +739,8 @@ protected void truncatedDropCar(PrintWriter file, Car car, boolean isManifest) { } /** - * Adds the car's set out string to the output file using the manifest or - * switch list format + * Adds the car's set out string to the output file using the manifest or switch + * list format * * @param file Manifest or switch list File * @param car The car being printed. @@ -800,7 +776,7 @@ private void dropCar(PrintWriter file, Car car, StringBuffer buf, String[] forma String s = getCarAttribute(car, attribute, !PICKUP, isLocal); if (!checkStringLength(buf.toString() + s, isManifest)) { addLine(file, buf.toString()); - buf = new StringBuffer(TAB); + buf = new StringBuffer(TAB); // new line } buf.append(s); } @@ -815,8 +791,8 @@ private void dropCar(PrintWriter file, Car car, StringBuffer buf, String[] forma * yardmaster. * * @param car The car being printed. - * @param isManifest when true use manifest format, when false use - * switch list format + * @param isManifest when true use manifest format, when false use switch + * list format * @param isTwoColumnTrack True if printing using two column format. * @return drop car string */ @@ -852,8 +828,8 @@ public String dropCar(Car car, boolean isManifest, boolean isTwoColumnTrack) { * yardmaster. * * @param car The car being printed. - * @param isManifest when true use manifest format, when false use switch - * list format + * @param isManifest when true use manifest format, when false use switch list + * format * @return move car string */ public String localMoveCar(Car car, boolean isManifest) { @@ -875,8 +851,8 @@ public String localMoveCar(Car car, boolean isManifest) { private static final int UTILITY_CAR_COUNT_FIELD_SIZE = 3; /** - * Add a list of utility cars scheduled for pick up from the route location - * to the output file. The cars are blocked by destination. + * Add a list of utility cars scheduled for pick up from the route location to + * the output file. The cars are blocked by destination. * * @param file Manifest or Switch List File. * @param carList List of cars for this train. @@ -895,15 +871,17 @@ protected void pickupUtilityCars(PrintWriter file, List carList, Car car, b if (count == 0) { return; // already printed out this car type } - pickUpCar(file, car, new StringBuffer(padAndTruncateIfNeeded(Setup.getPickupCarPrefix(), - isManifest ? Setup.getManifestPrefixLength() : Setup.getSwitchListPrefixLength()) + - " " + - padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)), format, isManifest); + pickUpCar(file, car, + new StringBuffer(padAndTruncateIfNeeded(Setup.getPickupCarPrefix(), + isManifest ? Setup.getManifestPrefixLength() : Setup.getSwitchListPrefixLength()) + + SPACE + + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)), + format, isManifest); } /** - * Add a list of utility cars scheduled for drop at the route location to - * the output file. + * Add a list of utility cars scheduled for drop at the route location to the + * output file. * * @param file Manifest or Switch List File. * @param carList List of cars for this train. @@ -933,7 +911,7 @@ protected void setoutUtilityCars(PrintWriter file, List carList, Car car, b if (count == 0) { return; // already printed out this car type } - buf.append(" " + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); + buf.append(SPACE + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); dropCar(file, car, buf, format, isLocal, isManifest); } @@ -952,7 +930,7 @@ public String pickupUtilityCars(List carList, Car car, boolean isManifest, } else { format = Setup.getPickupTwoColumnByTrackUtilitySwitchListMessageFormat(); } - StringBuffer buf = new StringBuffer(" " + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); + StringBuffer buf = new StringBuffer(SPACE + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); for (String attribute : format) { String s = getCarAttribute(car, attribute, PICKUP, !LOCAL); buf.append(s); @@ -1005,7 +983,7 @@ protected String setoutUtilityCars(List carList, Car car, boolean isLocal, } else { format = Setup.getDropTwoColumnByTrackUtilitySwitchListMessageFormat(); } - StringBuffer buf = new StringBuffer(" " + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); + StringBuffer buf = new StringBuffer(SPACE + padString(Integer.toString(count), UTILITY_CAR_COUNT_FIELD_SIZE)); // TODO the Setup.Location doesn't work correctly for the conductor // window due to the fact that the car can be in the train and not // at its starting location. @@ -1036,9 +1014,9 @@ public int countSetoutUtilityCars(List carList, Car car, boolean isLocal, b } /** - * 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. + * 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. * * @param format Message format. * @param carList List of cars for this train @@ -1180,13 +1158,13 @@ private static void printLine(PrintWriter file, String level, String string) { if (sb.length() + word.length() < lineLengthMax) { sb.append(word + SPACE); } else { - file.println(level + BUILD_REPORT_CHAR + " " + sb.toString()); + file.println(level + BUILD_REPORT_CHAR + SPACE + sb.toString()); sb = new StringBuffer(word + SPACE); } } string = sb.toString(); } - file.println(level + BUILD_REPORT_CHAR + " " + string); + file.println(level + BUILD_REPORT_CHAR + SPACE + string); } /** @@ -1203,13 +1181,13 @@ protected void addLine(PrintWriter file, String string) { } /** - * Writes a string to a file. Checks for string length, and will - * automatically wrap lines. + * Writes a string to a file. Checks for string length, and will automatically + * wrap lines. * * @param file The File to write to. * @param string The string to write. - * @param isManifest set true for manifest page orientation, false for - * switch list orientation + * @param isManifest set true for manifest page orientation, false for switch + * list orientation */ protected void newLine(PrintWriter file, String string, boolean isManifest) { String[] lines = string.split(NEW_LINE); @@ -1244,9 +1222,9 @@ protected void newLine(PrintWriter file) { } /** - * 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 "(". + * 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 + * "(". * * @param name The string to split if necessary. * @return First half of the string. @@ -1354,12 +1332,12 @@ private void addSearchForCar(PrintWriter file, Car car) { // @param isPickup true when rolling stock is being picked up private String getEngineAttribute(Engine engine, String attribute, boolean isPickup) { if (attribute.equals(Setup.MODEL)) { - return " " + + return SPACE + padAndTruncateIfNeeded(splitStringLeftParenthesis(engine.getModel()), InstanceManager.getDefault(EngineModels.class).getMaxNameLength()); } if (attribute.equals(Setup.CONSIST)) { - return " " + padAndTruncateIfNeeded(engine.getConsistName(), engineManager.getConsistMaxNameLength()); + return SPACE + padAndTruncateIfNeeded(engine.getConsistName(), engineManager.getConsistMaxNameLength()); } return getRollingStockAttribute(engine, attribute, isPickup, false); } @@ -1367,40 +1345,40 @@ private String getEngineAttribute(Engine engine, String attribute, boolean isPic private String getCarAttribute(Car car, String attribute, boolean isPickup, boolean isLocal) { if (attribute.equals(Setup.LOAD)) { return ((car.isCaboose() && !Setup.isPrintCabooseLoadEnabled()) || - (car.isPassenger() && - !Setup.isPrintPassengerLoadEnabled())) ? padAndTruncateIfNeeded("", - InstanceManager.getDefault(CarLoads.class).getMaxNameLength() + - 1) - : " " + - padAndTruncateIfNeeded(car.getLoadName().split(HYPHEN)[0], - InstanceManager.getDefault(CarLoads.class).getMaxNameLength()); + (car.isPassenger() && !Setup.isPrintPassengerLoadEnabled())) + ? padAndTruncateIfNeeded("", + InstanceManager.getDefault(CarLoads.class).getMaxNameLength() + 1) + : SPACE + + padAndTruncateIfNeeded(car.getLoadName().split(HYPHEN)[0], + InstanceManager.getDefault(CarLoads.class).getMaxNameLength()); } else if (attribute.equals(Setup.LOAD_TYPE)) { - return " " + + return SPACE + padAndTruncateIfNeeded(car.getLoadType(), TrainManifestHeaderText.getStringHeader_Load_Type().length()); } else if (attribute.equals(Setup.HAZARDOUS)) { - return (car.isHazardous() ? " " + - Setup.getHazardousMsg() : padAndTruncateIfNeeded("", Setup.getHazardousMsg().length() + 1)); + return (car.isHazardous() ? SPACE + Setup.getHazardousMsg() + : padAndTruncateIfNeeded("", Setup.getHazardousMsg().length() + 1)); } else if (attribute.equals(Setup.DROP_COMMENT)) { - return " " + car.getDropComment(); + return SPACE + car.getDropComment(); } else if (attribute.equals(Setup.PICKUP_COMMENT)) { - return " " + car.getPickupComment(); + return SPACE + car.getPickupComment(); } else if (attribute.equals(Setup.KERNEL)) { - return " " + padAndTruncateIfNeeded(car.getKernelName(), carManager.getKernelMaxNameLength()); + return SPACE + padAndTruncateIfNeeded(car.getKernelName(), carManager.getKernelMaxNameLength()); } else if (attribute.equals(Setup.KERNEL_SIZE)) { if (car.isLead()) { - return " " + padAndTruncateIfNeeded(Integer.toString(car.getKernel().getSize()), 2); + return SPACE + padAndTruncateIfNeeded(Integer.toString(car.getKernel().getSize()), 2); } else { - return " "; // assumes that kernel size is 99 or less + return SPACE + SPACE + SPACE; // assumes that kernel size is 99 or less } } else if (attribute.equals(Setup.RWE)) { if (!car.getReturnWhenEmptyDestName().equals(Car.NONE)) { - return " " + - padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_RWE() + - " " + - splitString(car.getReturnWhenEmptyDestinationName()) + - " ," + - splitString(car.getReturnWhenEmptyDestTrackName()), + return SPACE + + padAndTruncateIfNeeded( + TrainManifestHeaderText.getStringHeader_RWE() + + SPACE + + splitString(car.getReturnWhenEmptyDestinationName()) + + " ," + + splitString(car.getReturnWhenEmptyDestTrackName()), locationManager.getMaxLocationAndTrackNameLength() + TrainManifestHeaderText.getStringHeader_RWE().length() + 3); @@ -1408,13 +1386,15 @@ private String getCarAttribute(Car car, String attribute, boolean isPickup, bool return ""; } else if (attribute.equals(Setup.FINAL_DEST)) { if (!car.getFinalDestinationName().equals(Car.NONE)) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(car.getFinalDestinationName()), - locationManager.getMaxLocationNameLength()) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringFinalDestination() + - " " + - splitString(car.getFinalDestinationName()), + return Setup.isPrintHeadersEnabled() + ? SPACE + + padAndTruncateIfNeeded(splitString(car.getFinalDestinationName()), + locationManager.getMaxLocationNameLength()) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringFinalDestination() + + SPACE + + splitString(car.getFinalDestinationName()), locationManager.getMaxLocationNameLength() + TrainManifestText.getStringFinalDestination().length() + 1); @@ -1422,18 +1402,20 @@ private String getCarAttribute(Car car, String attribute, boolean isPickup, bool return ""; } else if (attribute.equals(Setup.FINAL_DEST_TRACK)) { if (!car.getFinalDestinationName().equals(Car.NONE)) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(car.getFinalDestinationName()) + - ", " + - splitString(car.getFinalDestinationTrackName()), - locationManager.getMaxLocationAndTrackNameLength() + - 2) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringFinalDestination() + - " " + + return Setup.isPrintHeadersEnabled() + ? SPACE + + padAndTruncateIfNeeded( splitString(car.getFinalDestinationName()) + - ", " + - splitString(car.getFinalDestinationTrackName()), + ", " + + splitString(car.getFinalDestinationTrackName()), + locationManager.getMaxLocationAndTrackNameLength() + 2) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringFinalDestination() + + SPACE + + splitString(car.getFinalDestinationName()) + + ", " + + splitString(car.getFinalDestinationTrackName()), locationManager.getMaxLocationAndTrackNameLength() + TrainManifestText.getStringFinalDestination().length() + 3); @@ -1445,47 +1427,46 @@ private String getCarAttribute(Car car, String attribute, boolean isPickup, bool private String getRollingStockAttribute(RollingStock rs, String attribute, boolean isPickup, boolean isLocal) { if (attribute.equals(Setup.NUMBER)) { - return " " + padAndTruncateIfNeeded(splitString(rs.getNumber()), Control.max_len_string_print_road_number); + return SPACE + padAndTruncateIfNeeded(splitString(rs.getNumber()), Control.max_len_string_print_road_number); } else if (attribute.equals(Setup.ROAD)) { String road = rs.getRoadName().split(HYPHEN)[0]; - return " " + padAndTruncateIfNeeded(road, InstanceManager.getDefault(CarRoads.class).getMaxNameLength()); + return SPACE + padAndTruncateIfNeeded(road, InstanceManager.getDefault(CarRoads.class).getMaxNameLength()); } else if (attribute.equals(Setup.TYPE)) { String type = rs.getTypeName().split(HYPHEN)[0]; - return " " + padAndTruncateIfNeeded(type, InstanceManager.getDefault(CarTypes.class).getMaxNameLength()); + return SPACE + padAndTruncateIfNeeded(type, InstanceManager.getDefault(CarTypes.class).getMaxNameLength()); } else if (attribute.equals(Setup.LENGTH)) { - return " " + + return SPACE + padAndTruncateIfNeeded(rs.getLength() + Setup.getLengthUnitAbv(), InstanceManager.getDefault(CarLengths.class).getMaxNameLength()); } else if (attribute.equals(Setup.WEIGHT)) { - return " " + + return SPACE + padAndTruncateIfNeeded(Integer.toString(rs.getAdjustedWeightTons()), Control.max_len_string_weight_name); } else if (attribute.equals(Setup.COLOR)) { - return " " + - padAndTruncateIfNeeded(rs.getColor(), InstanceManager.getDefault(CarColors.class).getMaxNameLength()); + return SPACE + + padAndTruncateIfNeeded(rs.getColor(), + InstanceManager.getDefault(CarColors.class).getMaxNameLength()); } else if (((attribute.equals(Setup.LOCATION)) && (isPickup || isLocal)) || (attribute.equals(Setup.TRACK) && isPickup)) { if (rs.getTrack() != null) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(rs.getTrackName()), - locationManager.getMaxTrackNameLength()) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringFrom() + - " " + - splitString(rs.getTrackName()), + return Setup.isPrintHeadersEnabled() ? SPACE + + padAndTruncateIfNeeded(splitString(rs.getTrackName()), locationManager.getMaxTrackNameLength()) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringFrom() + SPACE + splitString(rs.getTrackName()), TrainManifestText.getStringFrom().length() + locationManager.getMaxTrackNameLength() + 1); } return ""; } else if (attribute.equals(Setup.LOCATION) && !isPickup && !isLocal) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(rs.getLocationName()), - locationManager.getMaxLocationNameLength()) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringFrom() + - " " + - splitString(rs.getLocationName()), + return Setup.isPrintHeadersEnabled() + ? SPACE + + padAndTruncateIfNeeded(splitString(rs.getLocationName()), + locationManager.getMaxLocationNameLength()) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringFrom() + SPACE + splitString(rs.getLocationName()), locationManager.getMaxLocationNameLength() + TrainManifestText.getStringFrom().length() + 1); @@ -1493,80 +1474,80 @@ private String getRollingStockAttribute(RollingStock rs, String attribute, boole if (rs.getDestination() == null) return ""; if (Setup.isPrintHeadersEnabled()) { - return " " + + return SPACE + padAndTruncateIfNeeded(splitString(rs.getDestinationName()), locationManager.getMaxLocationNameLength()); } if (Setup.isTabEnabled()) { - return " " + - padAndTruncateIfNeeded(TrainManifestText.getStringDest() + - " " + - splitString(rs.getDestinationName()), + return SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringDest() + SPACE + splitString(rs.getDestinationName()), TrainManifestText.getStringDest().length() + locationManager.getMaxLocationNameLength() + 1); } else { - return " " + TrainManifestText.getStringDestination() + " " + splitString(rs.getDestinationName()); + return SPACE + TrainManifestText.getStringDestination() + SPACE + splitString(rs.getDestinationName()); } } else if ((attribute.equals(Setup.DESTINATION) || attribute.equals(Setup.TRACK)) && !isPickup) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(rs.getDestinationTrackName()), - locationManager.getMaxTrackNameLength()) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringTo() + - " " + - splitString(rs.getDestinationTrackName()), + return Setup.isPrintHeadersEnabled() + ? SPACE + + padAndTruncateIfNeeded(splitString(rs.getDestinationTrackName()), + locationManager.getMaxTrackNameLength()) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringTo() + SPACE + splitString(rs.getDestinationTrackName()), locationManager.getMaxTrackNameLength() + TrainManifestText.getStringTo().length() + 1); } else if (attribute.equals(Setup.DEST_TRACK)) { - return Setup.isPrintHeadersEnabled() ? " " + - padAndTruncateIfNeeded(splitString(rs.getDestinationName()) + - ", " + - splitString(rs.getDestinationTrackName()), - locationManager.getMaxLocationAndTrackNameLength() + - 2) - : " " + - padAndTruncateIfNeeded(TrainManifestText.getStringDest() + - " " + - splitString(rs.getDestinationName()) + - ", " + - splitString(rs.getDestinationTrackName()), + return Setup.isPrintHeadersEnabled() ? SPACE + + padAndTruncateIfNeeded( + splitString(rs.getDestinationName()) + ", " + splitString(rs.getDestinationTrackName()), + locationManager.getMaxLocationAndTrackNameLength() + 2) + : SPACE + + padAndTruncateIfNeeded( + TrainManifestText.getStringDest() + + SPACE + + splitString(rs.getDestinationName()) + + ", " + + splitString(rs.getDestinationTrackName()), locationManager.getMaxLocationAndTrackNameLength() + TrainManifestText.getStringDest().length() + 3); } else if (attribute.equals(Setup.OWNER)) { - return " " + - padAndTruncateIfNeeded(rs.getOwner(), InstanceManager.getDefault(CarOwners.class).getMaxNameLength()); + return SPACE + + padAndTruncateIfNeeded(rs.getOwner(), + InstanceManager.getDefault(CarOwners.class).getMaxNameLength()); } else if (attribute.equals(Setup.COMMENT)) { - return " " + rs.getComment(); + return SPACE + rs.getComment(); } else if (attribute.equals(Setup.BLANK)) { return ""; } // the three utility attributes that don't get printed but need to be // tabbed out else if (attribute.equals(Setup.NO_NUMBER)) { - return " " + - padAndTruncateIfNeeded("", Control.max_len_string_print_road_number - - (UTILITY_CAR_COUNT_FIELD_SIZE + 1)); + return SPACE + + padAndTruncateIfNeeded("", + Control.max_len_string_print_road_number - (UTILITY_CAR_COUNT_FIELD_SIZE + 1)); } else if (attribute.equals(Setup.NO_ROAD)) { - return " " + padAndTruncateIfNeeded("", InstanceManager.getDefault(CarRoads.class).getMaxNameLength()); + return SPACE + padAndTruncateIfNeeded("", InstanceManager.getDefault(CarRoads.class).getMaxNameLength()); } else if (attribute.equals(Setup.NO_COLOR)) { - return " " + padAndTruncateIfNeeded("", InstanceManager.getDefault(CarColors.class).getMaxNameLength()); + return SPACE + padAndTruncateIfNeeded("", InstanceManager.getDefault(CarColors.class).getMaxNameLength()); } // there are four truncated manifest attributes else if (attribute.equals(Setup.NO_DEST_TRACK)) { - return Setup.isPrintHeadersEnabled() ? padAndTruncateIfNeeded("", - locationManager.getMaxLocationAndTrackNameLength() + - 2) + return Setup.isPrintHeadersEnabled() + ? padAndTruncateIfNeeded("", locationManager.getMaxLocationAndTrackNameLength() + 2) : ""; } else if ((attribute.equals(Setup.NO_LOCATION) && !isPickup) || (attribute.equals(Setup.NO_DESTINATION) && isPickup)) { - return Setup.isPrintHeadersEnabled() ? padAndTruncateIfNeeded("", locationManager.getMaxLocationNameLength() + - 1) : ""; + return Setup.isPrintHeadersEnabled() + ? padAndTruncateIfNeeded("", locationManager.getMaxLocationNameLength() + 1) + : ""; } else if (attribute.equals(Setup.NO_TRACK) || attribute.equals(Setup.NO_LOCATION) || attribute.equals(Setup.NO_DESTINATION)) { - return Setup.isPrintHeadersEnabled() ? padAndTruncateIfNeeded("", locationManager.getMaxTrackNameLength() + - 1) : ""; + return Setup.isPrintHeadersEnabled() + ? padAndTruncateIfNeeded("", locationManager.getMaxTrackNameLength() + 1) + : ""; } else if (attribute.equals(Setup.TAB)) { return createTabIfNeeded(Setup.getTab1Length()); } else if (attribute.equals(Setup.TAB2)) { @@ -1574,9 +1555,8 @@ else if (attribute.equals(Setup.NO_DEST_TRACK)) { } else if (attribute.equals(Setup.TAB3)) { return createTabIfNeeded(Setup.getTab3Length()); } - return MessageFormat.format(Bundle.getMessage("ErrorPrintOptions"), new Object[]{attribute}); // something - // isn't - // right! + // something isn't right! + return MessageFormat.format(Bundle.getMessage("ErrorPrintOptions"), new Object[] { attribute }); } /** @@ -1593,11 +1573,10 @@ public void printEngineHeader(PrintWriter file, boolean isManifest) { } if (!Setup.getPickupEnginePrefix().trim().isEmpty() || !Setup.getDropEnginePrefix().trim().isEmpty()) { // center engine pick up and set out text - String s = padAndTruncate(tabString(Setup.getPickupEnginePrefix().trim(), lineLength / 4 - - Setup.getPickupEnginePrefix().length() / 2), lineLength / 2) + + String s = padAndTruncate(tabString(Setup.getPickupEnginePrefix().trim(), + lineLength / 4 - Setup.getPickupEnginePrefix().length() / 2), lineLength / 2) + VERTICAL_LINE_CHAR + - tabString(Setup.getDropEnginePrefix(), - lineLength / 4 - Setup.getDropEnginePrefix().length() / 2); + tabString(Setup.getDropEnginePrefix(), lineLength / 4 - Setup.getDropEnginePrefix().length() / 2); s = padAndTruncate(s, lineLength); addLine(file, s); printHorizontalLine(file, 0, lineLength); @@ -1612,8 +1591,8 @@ public void printEngineHeader(PrintWriter file, boolean isManifest) { public void printPickupEngineHeader(PrintWriter file, boolean isManifest) { int lineLength = getLineLength(isManifest); printHorizontalLine(file, 0, lineLength); - String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + - getPickupEngineHeader(), lineLength); + String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + getPickupEngineHeader(), + lineLength); addLine(file, s); printHorizontalLine(file, 0, lineLength); } @@ -1621,8 +1600,8 @@ public void printPickupEngineHeader(PrintWriter file, boolean isManifest) { public void printDropEngineHeader(PrintWriter file, boolean isManifest) { int lineLength = getLineLength(isManifest); printHorizontalLine(file, 0, lineLength); - String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + - getDropEngineHeader(), lineLength); + String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + getDropEngineHeader(), + lineLength); addLine(file, s); printHorizontalLine(file, 0, lineLength); } @@ -1642,8 +1621,9 @@ public void printCarHeader(PrintWriter file, boolean isManifest, boolean isTwoCo return; } // center pick up and set out text - String s = padAndTruncate(tabString(Setup.getPickupCarPrefix(), lineLength / 4 - - Setup.getPickupCarPrefix().length() / 2), lineLength / 2) + + String s = padAndTruncate( + tabString(Setup.getPickupCarPrefix(), lineLength / 4 - Setup.getPickupCarPrefix().length() / 2), + lineLength / 2) + VERTICAL_LINE_CHAR + tabString(Setup.getDropCarPrefix(), lineLength / 4 - Setup.getDropCarPrefix().length() / 2); s = padAndTruncate(s, lineLength); @@ -1651,9 +1631,7 @@ public void printCarHeader(PrintWriter file, boolean isManifest, boolean isTwoCo printHorizontalLine(file, 0, lineLength); s = padAndTruncate(getPickupCarHeader(isManifest, isTwoColumnTrack), lineLength / 2); - s = padAndTruncate(s + - VERTICAL_LINE_CHAR + - getDropCarHeader(isManifest, isTwoColumnTrack), lineLength); + s = padAndTruncate(s + VERTICAL_LINE_CHAR + getDropCarHeader(isManifest, isTwoColumnTrack), lineLength); addLine(file, s); printHorizontalLine(file, 0, lineLength); } @@ -1674,8 +1652,9 @@ public void printDropCarHeader(PrintWriter file, boolean isManifest, boolean isT return; } printHorizontalLine(file, isManifest); - String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + - getDropCarHeader(isManifest, isTwoColumnTrack), getLineLength(isManifest)); + String s = padAndTruncate( + createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + getDropCarHeader(isManifest, isTwoColumnTrack), + getLineLength(isManifest)); addLine(file, s); printHorizontalLine(file, isManifest); } @@ -1685,8 +1664,9 @@ public void printLocalCarMoveHeader(PrintWriter file, boolean isManifest) { return; } printHorizontalLine(file, isManifest); - String s = padAndTruncate(createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + - getLocalMoveHeader(isManifest), getLineLength(isManifest)); + String s = padAndTruncate( + createTabIfNeeded(Setup.getManifestPrefixLength() + 1) + getLocalMoveHeader(isManifest), + getLineLength(isManifest)); addLine(file, s); printHorizontalLine(file, isManifest); } @@ -1739,100 +1719,76 @@ private String getHeader(String[] format, boolean isPickup, boolean isLocal, boo } if (attribute.equals(Setup.ROAD)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Road(), - InstanceManager.getDefault(CarRoads.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarRoads.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.NUMBER) && !isEngine) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Number(), - Control.max_len_string_print_road_number) + - " "); + Control.max_len_string_print_road_number) + SPACE); } else if (attribute.equals(Setup.NUMBER) && isEngine) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_EngineNumber(), - Control.max_len_string_print_road_number) + - " "); + Control.max_len_string_print_road_number) + SPACE); } else if (attribute.equals(Setup.TYPE)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Type(), - InstanceManager.getDefault(CarTypes.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarTypes.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.MODEL)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Model(), - InstanceManager.getDefault(EngineModels.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(EngineModels.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.CONSIST)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Consist(), - engineManager.getConsistMaxNameLength()) + - " "); + engineManager.getConsistMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.KERNEL)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Kernel(), - carManager.getKernelMaxNameLength()) + - " "); + carManager.getKernelMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.KERNEL_SIZE)) { buf.append(" "); // assume kernel size is 99 or less } else if (attribute.equals(Setup.LOAD)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Load(), - InstanceManager.getDefault(CarLoads.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarLoads.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.LOAD_TYPE)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Load_Type(), - TrainManifestHeaderText.getStringHeader_Load_Type().length()) + - " "); + TrainManifestHeaderText.getStringHeader_Load_Type().length()) + SPACE); } else if (attribute.equals(Setup.COLOR)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Color(), - InstanceManager.getDefault(CarColors.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarColors.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.OWNER)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Owner(), - InstanceManager.getDefault(CarOwners.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarOwners.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.LENGTH)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Length(), - InstanceManager.getDefault(CarLengths.class).getMaxNameLength()) + - " "); + InstanceManager.getDefault(CarLengths.class).getMaxNameLength()) + SPACE); } else if (attribute.equals(Setup.WEIGHT)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Weight(), - Control.max_len_string_weight_name) + - " "); + Control.max_len_string_weight_name) + SPACE); } else if (attribute.equals(Setup.TRACK)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Track(), - locationManager.getMaxTrackNameLength()) + - " "); + locationManager.getMaxTrackNameLength()) + SPACE); } else if (attribute.equals(Setup.LOCATION) && (isPickup || isLocal)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Location(), - locationManager.getMaxTrackNameLength()) + - " "); + locationManager.getMaxTrackNameLength()) + SPACE); } else if (attribute.equals(Setup.LOCATION) && !isPickup) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Location(), - locationManager.getMaxLocationNameLength()) + - " "); + locationManager.getMaxLocationNameLength()) + SPACE); } else if (attribute.equals(Setup.DESTINATION) && !isPickup) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Destination(), - locationManager.getMaxTrackNameLength()) + - " "); + locationManager.getMaxTrackNameLength()) + SPACE); } else if (attribute.equals(Setup.DESTINATION) && isPickup) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Destination(), - locationManager.getMaxLocationNameLength()) + - " "); + locationManager.getMaxLocationNameLength()) + SPACE); } else if (attribute.equals(Setup.DEST_TRACK)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Dest_Track(), - locationManager.getMaxLocationAndTrackNameLength() + - 2) + - " "); + locationManager.getMaxLocationAndTrackNameLength() + 2) + SPACE); } else if (attribute.equals(Setup.FINAL_DEST)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Final_Dest(), - locationManager.getMaxLocationNameLength()) + - " "); + locationManager.getMaxLocationNameLength()) + SPACE); } else if (attribute.equals(Setup.FINAL_DEST_TRACK)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Final_Dest_Track(), - locationManager.getMaxLocationAndTrackNameLength() + - 2) + - " "); + locationManager.getMaxLocationAndTrackNameLength() + 2) + SPACE); } else if (attribute.equals(Setup.HAZARDOUS)) { buf.append(padAndTruncateIfNeeded(TrainManifestHeaderText.getStringHeader_Hazardous(), - Setup.getHazardousMsg().length()) + - " "); + Setup.getHazardousMsg().length()) + SPACE); } else if (attribute.equals(Setup.RWE)) { - buf.append(TrainManifestHeaderText.getStringHeader_RWE() + " "); + buf.append(TrainManifestHeaderText.getStringHeader_RWE() + SPACE); } else if (attribute.equals(Setup.COMMENT)) { - buf.append(TrainManifestHeaderText.getStringHeader_Comment() + " "); + buf.append(TrainManifestHeaderText.getStringHeader_Comment() + SPACE); } else if (attribute.equals(Setup.TAB)) { buf.append(createTabIfNeeded(Setup.getTab1Length())); } else if (attribute.equals(Setup.TAB2)) { @@ -1840,7 +1796,7 @@ private String getHeader(String[] format, boolean isPickup, boolean isLocal, boo } else if (attribute.equals(Setup.TAB3)) { buf.append(createTabIfNeeded(Setup.getTab3Length())); } else { - buf.append(attribute + " "); + buf.append(attribute + SPACE); } } return buf.toString(); @@ -1849,8 +1805,8 @@ private String getHeader(String[] format, boolean isPickup, boolean isLocal, boo protected void printTrackNameHeader(PrintWriter file, String trackName, boolean isManifest) { printHorizontalLine(file, isManifest); int lineLength = getLineLength(isManifest); - String s = padAndTruncate(tabString(trackName.trim(), lineLength / 4 - - trackName.trim().length() / 2), lineLength / 2) + + String s = padAndTruncate(tabString(trackName.trim(), lineLength / 4 - trackName.trim().length() / 2), + lineLength / 2) + VERTICAL_LINE_CHAR + tabString(trackName.trim(), lineLength / 4 - trackName.trim().length() / 2); s = padAndTruncate(s, lineLength); @@ -1916,9 +1872,8 @@ public static String getDate(boolean isModelYear) { } /** - * 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. + * 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. * * @param s The string to pad. * @param fieldSize The maximum length of the string. @@ -1926,11 +1881,11 @@ public static String getDate(boolean isModelYear) { */ public static String padAndTruncateIfNeeded(String s, int fieldSize) { if (Setup.isTabEnabled()) { - return padAndTruncate(s, fieldSize); + return padAndTruncate(s, fieldSize); } return s; } - + public static String padAndTruncate(String s, int fieldSize) { s = padString(s, fieldSize); if (s.length() > fieldSize) { @@ -1940,8 +1895,8 @@ public static String padAndTruncate(String s, int fieldSize) { } /** - * Adjusts string to be a certain number of characters by adding spaces to - * the end of the string. + * Adjusts string to be a certain number of characters by adding spaces to the + * end of the string. * * @param s The string to pad * @param fieldSize The fixed length of the string. @@ -1950,14 +1905,14 @@ public static String padAndTruncate(String s, int fieldSize) { public static String padString(String s, int fieldSize) { StringBuffer buf = new StringBuffer(s); while (buf.length() < fieldSize) { - buf.append(" "); + buf.append(SPACE); } return buf.toString(); } /** - * Creates a String of spaces to create a tab for text. Tabs must be - * enabled. Setup.isTabEnabled() + * Creates a String of spaces to create a tab for text. Tabs must be enabled. + * Setup.isTabEnabled() * * @param tabSize the length of tab * @return tab @@ -1968,20 +1923,20 @@ public static String createTabIfNeeded(int tabSize) { } return ""; } - + protected static String tabString(String s, int tabSize) { StringBuffer buf = new StringBuffer(); // TODO this doesn't consider the length of s string. while (buf.length() < tabSize) { - buf.append(" "); + buf.append(SPACE); } buf.append(s); return buf.toString(); } /** - * Returns the line length for manifest or switch list printout. Always an - * even number. + * Returns the line length for manifest or switch list printout. Always an even + * number. * * @param isManifest True if manifest. * @return line length for manifest or switch list. @@ -2052,8 +2007,8 @@ protected static Dimension getPageSize(String orientation) { } /** - * Produces a string using commas and spaces between the strings provided in - * the array. Does not check for embedded commas in the 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. * * @param array The string array to be formated. * @return formated string using commas and spaces @@ -2072,9 +2027,9 @@ public static String formatStringToCommaSeparated(String[] array) { } /** - * 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. + * 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. * * @param text the text to be modified * @param color the color the text is to be printed diff --git a/java/src/jmri/jmrit/operations/trains/TrainPrintUtilities.java b/java/src/jmri/jmrit/operations/trains/TrainPrintUtilities.java index 3da8e5db012..74274347779 100644 --- a/java/src/jmri/jmrit/operations/trains/TrainPrintUtilities.java +++ b/java/src/jmri/jmrit/operations/trains/TrainPrintUtilities.java @@ -44,8 +44,8 @@ public class TrainPrintUtilities { * @param orientation Setup.LANDSCAPE, Setup.PORTRAIT, or Setup.HANDHELD * @param fontSize font size */ - public static void printReport(File file, String name, boolean isPreview, String fontName, - boolean isBuildReport, String logoURL, String printerName, String orientation, int fontSize) { + public static void printReport(File file, String name, boolean isPreview, String fontName, boolean isBuildReport, + String logoURL, String printerName, String orientation, int fontSize) { // obtain a HardcopyWriter to do this HardcopyWriter writer = null; boolean isLandScape = false; @@ -64,8 +64,8 @@ public static void printReport(File file, String name, boolean isPreview, String TrainCommon.getPageSize(orientation).height + TrainCommon.PAPER_MARGINS.height); } try { - writer = new HardcopyWriter(new Frame(), name, fontSize, margin, margin, .5, .5, - isPreview, printerName, isLandScape, printHeader, pagesize); + writer = new HardcopyWriter(new Frame(), name, fontSize, margin, margin, .5, .5, isPreview, printerName, + isLandScape, printHeader, pagesize); } catch (HardcopyWriter.PrintCanceledException ex) { log.debug("Print cancelled"); return; @@ -142,23 +142,23 @@ public static void printReport(File file, String name, boolean isPreview, String // determine if line is a pickup or drop if ((!Setup.getPickupEnginePrefix().trim().isEmpty() && - line.startsWith(Setup.getPickupEnginePrefix())) || + line.startsWith(Setup.getPickupEnginePrefix() + TrainCommon.SPACE)) || (!Setup.getPickupCarPrefix().trim().isEmpty() && - line.startsWith(Setup.getPickupCarPrefix())) || + line.startsWith(Setup.getPickupCarPrefix() + TrainCommon.SPACE)) || (!Setup.getSwitchListPickupCarPrefix().trim().isEmpty() && - line.startsWith(Setup.getSwitchListPickupCarPrefix()))) { + line.startsWith(Setup.getSwitchListPickupCarPrefix() + TrainCommon.SPACE))) { c = Setup.getPickupColor(); } else if ((!Setup.getDropEnginePrefix().trim().isEmpty() && - line.startsWith(Setup.getDropEnginePrefix())) || + line.startsWith(Setup.getDropEnginePrefix() + TrainCommon.SPACE)) || (!Setup.getDropCarPrefix().trim().isEmpty() && - line.startsWith(Setup.getDropCarPrefix())) || + line.startsWith(Setup.getDropCarPrefix() + TrainCommon.SPACE)) || (!Setup.getSwitchListDropCarPrefix().trim().isEmpty() && - line.startsWith(Setup.getSwitchListDropCarPrefix()))) { + line.startsWith(Setup.getSwitchListDropCarPrefix() + TrainCommon.SPACE))) { c = Setup.getDropColor(); } else if ((!Setup.getLocalPrefix().trim().isEmpty() && - line.startsWith(Setup.getLocalPrefix())) || + line.startsWith(Setup.getLocalPrefix() + TrainCommon.SPACE)) || (!Setup.getSwitchListLocalPrefix().trim().isEmpty() && - line.startsWith(Setup.getSwitchListLocalPrefix()))) { + line.startsWith(Setup.getSwitchListLocalPrefix() + TrainCommon.SPACE))) { c = Setup.getLocalColor(); } else if (line.contains(TrainCommon.TEXT_COLOR_START)) { c = TrainCommon.getTextColor(line); @@ -251,11 +251,11 @@ public static void editReport(File file, String name) { return; } PrintWriter out; - File buildReport = InstanceManager.getDefault(TrainManagerXml.class).createTrainBuildReportFile( - Bundle.getMessage("Report") + " " + name); + File buildReport = InstanceManager.getDefault(TrainManagerXml.class) + .createTrainBuildReportFile(Bundle.getMessage("Report") + " " + name); try { - out = new PrintWriter(new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(buildReport), StandardCharsets.UTF_8)), true); + out = new PrintWriter(new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(buildReport), StandardCharsets.UTF_8)), true); } catch (IOException e) { log.error("Can not create build report file"); try { diff --git a/java/test/jmri/jmrit/operations/locations/YardmasterFrameTest.java b/java/test/jmri/jmrit/operations/locations/YardmasterFrameTest.java index 64d25a59ea1..f44d7d72954 100644 --- a/java/test/jmri/jmrit/operations/locations/YardmasterFrameTest.java +++ b/java/test/jmri/jmrit/operations/locations/YardmasterFrameTest.java @@ -3,11 +3,12 @@ import java.awt.GraphicsEnvironment; import org.junit.Assert; -import org.junit.jupiter.api.*; import org.junit.Assume; +import org.junit.jupiter.api.Test; import jmri.InstanceManager; import jmri.jmrit.operations.OperationsTestCase; +import jmri.jmrit.operations.setup.Setup; import jmri.jmrit.operations.trains.Train; import jmri.jmrit.operations.trains.TrainManager; import jmri.util.JUnitOperationsUtil; @@ -34,6 +35,8 @@ public void testLocationWithWork() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); JUnitOperationsUtil.initOperationsData(); + // improve test coverage + Setup.setPrintHeadersEnabled(true); // build a train to create data for the Yardmaster window Train train = InstanceManager.getDefault(TrainManager.class).getTrainByName("STF"); diff --git a/java/test/jmri/jmrit/operations/setup/SetupTest.java b/java/test/jmri/jmrit/operations/setup/SetupTest.java index a288421ed6f..a80b0f20190 100644 --- a/java/test/jmri/jmrit/operations/setup/SetupTest.java +++ b/java/test/jmri/jmrit/operations/setup/SetupTest.java @@ -1,8 +1,9 @@ package jmri.jmrit.operations.setup; -import jmri.jmrit.operations.OperationsTestCase; import org.junit.Assert; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Test; + +import jmri.jmrit.operations.OperationsTestCase; /** * @@ -15,6 +16,100 @@ public void testCTor() { Setup t = new Setup(); Assert.assertNotNull("exists",t); } + + @Test + public void testPrefixLength() { + Setup.setSwitchListFormatSameAsManifest(false); + + Assert.assertEquals("Default length", 12, Setup.getManifestPrefixLength()); + Assert.assertEquals("Default length", 12, Setup.getSwitchListPrefixLength()); + + Setup.setDropEnginePrefix("ABCDEFGHIJKLM"); // now 13 characters + Assert.assertEquals("new length 1", 13, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 1", 13, Setup.getSwitchListPrefixLength()); + + Setup.setDropCarPrefix("ABCDEFGHIJKLMN"); // now 14 characters + Assert.assertEquals("new length 2", 14, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 2", 13, Setup.getSwitchListPrefixLength()); + + Setup.setPickupCarPrefix("ABCDEFGHIJKLMNO"); // now 15 characters + Assert.assertEquals("new length 3", 15, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 3", 13, Setup.getSwitchListPrefixLength()); + + Setup.setLocalPrefix("ABCDEFGHIJKLMNOP"); // now 16 characters + Assert.assertEquals("new length 4", 16, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 4", 13, Setup.getSwitchListPrefixLength()); + + Setup.setSwitchListDropCarPrefix("ABCDEFGHIJKLMNOPQ"); // now 17 characters + Assert.assertEquals("new length 5", 16, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 5", 17, Setup.getSwitchListPrefixLength()); + + Setup.setSwitchListPickupCarPrefix("ABCDEFGHIJKLMNOPQR"); // now 18 characters + Assert.assertEquals("new length 6", 16, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 6", 18, Setup.getSwitchListPrefixLength()); + + Setup.setSwitchListLocalPrefix("ABCDEFGHIJKLMNOPQRS"); // now 19 characters + Assert.assertEquals("new length 7", 16, Setup.getManifestPrefixLength()); + Assert.assertEquals("new length 7", 19, Setup.getSwitchListPrefixLength()); + + Setup.setSwitchListFormatSameAsManifest(true); + Assert.assertEquals("confirm length", 16, Setup.getSwitchListPrefixLength()); + } + + @Test + public void testDropTruncatedMessageFormat() { + Assert.assertEquals("default message", 10, Setup.getDropTruncatedManifestMessageFormat().length); + // confirm + Assert.assertEquals("attribute 1", Setup.ROAD, Setup.getDropTruncatedManifestMessageFormat()[0]); + Assert.assertEquals("attribute 2", Setup.NUMBER, Setup.getDropTruncatedManifestMessageFormat()[1]); + Assert.assertEquals("attribute 3", Setup.TYPE, Setup.getDropTruncatedManifestMessageFormat()[2]); + Assert.assertEquals("attribute 4", Setup.LENGTH, Setup.getDropTruncatedManifestMessageFormat()[3]); + Assert.assertEquals("attribute 5", Setup.COLOR, Setup.getDropTruncatedManifestMessageFormat()[4]); + Assert.assertEquals("attribute 7", Setup.LOAD, Setup.getDropTruncatedManifestMessageFormat()[5]); + Assert.assertEquals("attribute 6", Setup.HAZARDOUS, Setup.getDropTruncatedManifestMessageFormat()[6]); + Assert.assertEquals("attribute 7", Setup.NO_DESTINATION, Setup.getDropTruncatedManifestMessageFormat()[7]); + Assert.assertEquals("attribute 8", Setup.COMMENT, Setup.getDropTruncatedManifestMessageFormat()[8]); + Assert.assertEquals("attribute 9", Setup.DROP_COMMENT, Setup.getDropTruncatedManifestMessageFormat()[9]); + } + + @Test + public void testPickupTruncatedMessageFormat() { + Assert.assertEquals("default message", 10, Setup.getPickupTruncatedManifestMessageFormat().length); + // confirm + Assert.assertEquals("attribute 1", Setup.ROAD, Setup.getPickupTruncatedManifestMessageFormat()[0]); + Assert.assertEquals("attribute 2", Setup.NUMBER, Setup.getPickupTruncatedManifestMessageFormat()[1]); + Assert.assertEquals("attribute 3", Setup.TYPE, Setup.getPickupTruncatedManifestMessageFormat()[2]); + Assert.assertEquals("attribute 4", Setup.LENGTH, Setup.getPickupTruncatedManifestMessageFormat()[3]); + Assert.assertEquals("attribute 5", Setup.COLOR, Setup.getPickupTruncatedManifestMessageFormat()[4]); + Assert.assertEquals("attribute 7", Setup.LOAD, Setup.getPickupTruncatedManifestMessageFormat()[5]); + Assert.assertEquals("attribute 6", Setup.HAZARDOUS, Setup.getPickupTruncatedManifestMessageFormat()[6]); + Assert.assertEquals("attribute 7", Setup.NO_LOCATION, Setup.getPickupTruncatedManifestMessageFormat()[7]); + Assert.assertEquals("attribute 8", Setup.COMMENT, Setup.getPickupTruncatedManifestMessageFormat()[8]); + Assert.assertEquals("attribute 9", Setup.PICKUP_COMMENT, Setup.getPickupTruncatedManifestMessageFormat()[9]); + } + + @Test + public void testEngineMessageComboBox() { + Assert.assertEquals("default size", 13, Setup.getEngineMessageComboBox().getItemCount()); + Setup.setTabEnabled(true); + Assert.assertEquals("with tabs", 16, Setup.getEngineMessageComboBox().getItemCount()); + } + + @Test + public void testCarMessageComboBox() { + Assert.assertEquals("default size", 23, Setup.getCarMessageComboBox().getItemCount()); + Setup.setTabEnabled(true); + Assert.assertEquals("with tabs", 26, Setup.getCarMessageComboBox().getItemCount()); + } + + @Test + public void testDirectionInt() { + Assert.assertEquals("east", 1, Setup.getDirectionInt(Setup.EAST_DIR)); + Assert.assertEquals("west", 2, Setup.getDirectionInt(Setup.WEST_DIR)); + Assert.assertEquals("south", 8, Setup.getDirectionInt(Setup.SOUTH_DIR)); + Assert.assertEquals("north", 4, Setup.getDirectionInt(Setup.NORTH_DIR)); + Assert.assertEquals("error", 0, Setup.getDirectionInt("X")); + } // private final static Logger log = LoggerFactory.getLogger(SetupTest.class); diff --git a/java/test/jmri/jmrit/operations/trains/TrainBuilderTest.java b/java/test/jmri/jmrit/operations/trains/TrainBuilderTest.java index 933e8039443..682ecfad35b 100644 --- a/java/test/jmri/jmrit/operations/trains/TrainBuilderTest.java +++ b/java/test/jmri/jmrit/operations/trains/TrainBuilderTest.java @@ -773,6 +773,7 @@ public void testTrainLengthRestricions() { */ @Test public void testCarDestinationsA() { + String carTypes[] = Bundle.getMessage("carTypeNames").split(","); // Route Acton-Boston-Chelmsford-Chelmsford-Boston-Acton @@ -7953,49 +7954,48 @@ public void testScheduleLoads() { sch1Item3.setShipLoadName("Tin"); InstanceManager.getDefault(CarLoads.class).addName(carTypes[3], "Tin"); // Allows c13 which is part of a kernel // to get a new load - Schedule sch2 = smanager.newSchedule("Schedule 2"); ScheduleItem sch2Item1 = sch2.addItem(carTypes[4]); sch2Item1.setCount(2); sch2.addItem(carTypes[1]); // Create locations used - Location loc1; - loc1 = lmanager.newLocation("Westford"); + Location westford; + westford = lmanager.newLocation("Westford"); - Location loc2; - loc2 = lmanager.newLocation("Chelmsford"); + Location chelmsford; + chelmsford = lmanager.newLocation("Chelmsford"); - Location loc3; - loc3 = lmanager.newLocation("Bedford"); + Location bedford; + bedford = lmanager.newLocation("Bedford"); Track loc1trk1; - loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD); + loc1trk1 = westford.addTrack("Westford Yard 1", Track.YARD); loc1trk1.setTrainDirections(Track.WEST + Track.EAST); loc1trk1.setLength(900); Track loc1trk2; - loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD); + loc1trk2 = westford.addTrack("Westford Yard 2", Track.YARD); loc1trk2.setTrainDirections(Track.WEST + Track.EAST); loc1trk2.setLength(500); loc1trk2.deleteTypeName(carTypes[4]); Track loc1trk3; - loc1trk3 = loc1.addTrack("Westford Express 3", Track.SPUR); + loc1trk3 = westford.addTrack("Westford Express 3", Track.SPUR); loc1trk3.setTrainDirections(Track.WEST + Track.EAST); loc1trk3.setLength(300); loc1trk3.deleteTypeName(carTypes[3]); loc1trk3.deleteTypeName(carTypes[4]); Track loc1trk4; - loc1trk4 = loc1.addTrack("Westford Express 4", Track.SPUR); + loc1trk4 = westford.addTrack("Westford Express 4", Track.SPUR); loc1trk4.setTrainDirections(Track.WEST + Track.EAST); loc1trk4.setLength(300); loc1trk4.deleteTypeName(carTypes[3]); loc1trk4.deleteTypeName(carTypes[4]); Track loc2trk1; - loc2trk1 = loc2.addTrack("Chelmsford Freight 1", Track.SPUR); + loc2trk1 = chelmsford.addTrack("Chelmsford Freight 1", Track.SPUR); loc2trk1.setTrainDirections(Track.WEST + Track.EAST); loc2trk1.setLength(900); loc2trk1.deleteTypeName(carTypes[4]); @@ -8005,7 +8005,7 @@ public void testScheduleLoads() { loc2trk1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId()); Track loc2trk2; - loc2trk2 = loc2.addTrack("Chelmsford Freight 2", Track.SPUR); + loc2trk2 = chelmsford.addTrack("Chelmsford Freight 2", Track.SPUR); loc2trk2.setTrainDirections(Track.WEST + Track.EAST); loc2trk2.setLength(900); loc2trk2.deleteTypeName(carTypes[4]); @@ -8015,21 +8015,21 @@ public void testScheduleLoads() { loc2trk2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId()); Track loc2trk3; - loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD); + loc2trk3 = chelmsford.addTrack("Chelmsford Yard 3", Track.YARD); loc2trk3.setTrainDirections(Track.WEST + Track.EAST); loc2trk3.setLength(900); loc2trk3.deleteTypeName(carTypes[3]); loc2trk3.deleteTypeName(carTypes[4]); Track loc2trk4; - loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR); + loc2trk4 = chelmsford.addTrack("Chelmsford Freight 4", Track.SPUR); loc2trk4.setTrainDirections(Track.WEST + Track.EAST); loc2trk4.setLength(900); loc2trk4.setSchedule(sch2); loc2trk4.setScheduleMode(Track.SEQUENTIAL); Track loc3trk1; - loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.STAGING); + loc3trk1 = bedford.addTrack("Bedford Yard 1", Track.STAGING); loc3trk1.setTrainDirections(Track.WEST + Track.EAST); loc3trk1.setLength(900); loc3trk1.setRemoveCustomLoadsEnabled(true); @@ -8037,13 +8037,13 @@ public void testScheduleLoads() { // Create route with 2 location Route rte1; rte1 = rmanager.newRoute("Two Location Route"); - RouteLocation rl1 = rte1.addLocation(loc1); + RouteLocation rl1 = rte1.addLocation(westford); rl1.setTrainDirection(RouteLocation.EAST); rl1.setMaxCarMoves(12); rl1.setTrainIconX(25); // set the train icon coordinates rl1.setTrainIconY(75); - RouteLocation rl2 = rte1.addLocation(loc2); + RouteLocation rl2 = rte1.addLocation(chelmsford); rl2.setTrainDirection(RouteLocation.EAST); rl2.setMaxCarMoves(12); rl2.setTrainIconX(75); // set the train icon coordinates @@ -8073,7 +8073,7 @@ public void testScheduleLoads() { c3.setLength("70"); c3.setMoves(0); c3.setLoadName("L"); - c3.setDestination(loc2, null); // force this car to Chelmsford + c3.setDestination(chelmsford, null); // force this car to Chelmsford cmanager.register(c3); Car c4 = new Car(roadNames[2], "S4"); @@ -8149,21 +8149,21 @@ public void testScheduleLoads() { cmanager.register(c13); // place the cars in the yards - Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1)); + Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(westford, loc1trk1)); - Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2)); - Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2)); - Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2)); - Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2)); - Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2)); + Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(westford, loc1trk2)); + Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(westford, loc1trk2)); + Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(westford, loc1trk2)); + Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(westford, loc1trk2)); + Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(westford, loc1trk2)); - Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1)); - Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk2)); + Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(westford, loc1trk1)); + Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(westford, loc1trk2)); train1.reset(); @@ -8225,12 +8225,12 @@ public void testScheduleLoads() { // Create route with 2 location Route rte2; rte2 = rmanager.newRoute("Chelmsford to Staging"); - RouteLocation r2rl1 = rte2.addLocation(loc2); + RouteLocation r2rl1 = rte2.addLocation(chelmsford); r2rl1.setTrainDirection(RouteLocation.EAST); r2rl1.setMaxCarMoves(12); r2rl1.setTrainIconX(125); // set the train icon coordinates r2rl1.setTrainIconY(75); - RouteLocation r2rl3 = rte2.addLocation(loc3); + RouteLocation r2rl3 = rte2.addLocation(bedford); r2rl3.setTrainDirection(RouteLocation.EAST); r2rl3.setMaxCarMoves(12); r2rl3.setTrainIconX(175); // set the train icon coordinates @@ -8277,15 +8277,15 @@ public void testScheduleLoads() { // Create route with 3 locations Route rte3; rte3 = rmanager.newRoute("Staging to Chelmsford"); - RouteLocation r3rl1 = rte3.addLocation(loc3); + RouteLocation r3rl1 = rte3.addLocation(bedford); r3rl1.setTrainDirection(RouteLocation.EAST); r3rl1.setMaxCarMoves(11); // there are 11 cars departing staging r3rl1.setTrainIconX(25); // set the train icon coordinates r3rl1.setTrainIconY(100); - RouteLocation r3rl2 = rte3.addLocation(loc2); + RouteLocation r3rl2 = rte3.addLocation(chelmsford); r3rl2.setTrainDirection(RouteLocation.EAST); r3rl2.setMaxCarMoves(12); - RouteLocation r3rl3 = rte3.addLocation(loc1); + RouteLocation r3rl3 = rte3.addLocation(westford); r3rl3.setTrainDirection(RouteLocation.EAST); r3rl3.setMaxCarMoves(12); r3rl3.setTrainIconX(75); // set the train icon coordinates @@ -8297,10 +8297,10 @@ public void testScheduleLoads() { sch1Item1.setReceiveLoadName("Metal 1"); // request these loads from staging sch1Item2.setReceiveLoadName("Metal 2"); sch1Item3.setReceiveLoadName("Metal 3"); - + + InstanceManager.getDefault(CarLoads.class).addName(carTypes[2], "Metal 2"); InstanceManager.getDefault(CarLoads.class).addName(carTypes[3], "Metal 3"); // Allows c13 which is part of a // kernel to get a new load - train1.setRoute(rte3); train1.setName("BCW"); train1.reset(); @@ -13435,6 +13435,7 @@ public void testAggressiveBuildOption() { // improve test coverage Setup.setRouterBuildReportLevel(Setup.BUILD_REPORT_DETAILED); + Setup.setManifestFormat(Setup.TWO_COLUMN_TRACK_FORMAT); String carTypes[] = Bundle.getMessage("carTypeNames").split(","); String engineTypes[] = Bundle.getMessage("engineDefaultTypes").split(","); @@ -14404,6 +14405,9 @@ public void testFinalDestinationForCarLoadNoMatch() { */ @Test public void testFindFinalDestinationForCarLoadAlternateTrack() { + + // improve test coverage + Setup.setPrintHeadersEnabled(false); setupCustomCarLoad(); @@ -15440,5 +15444,12 @@ public void setUp() { // increase test coverage Setup.setGenerateCsvManifestEnabled(true); Setup.setAllowReturnToStagingEnabled(true); + Setup.setPrintHeadersEnabled(true); + // use all of the car attributes when creating Manifests + Setup.setDropManifestMessageFormat(Setup.getCarAttributes()); + Setup.setPickupManifestMessageFormat(Setup.getCarAttributes()); + // use all of the engine attribures when creating Manifests + Setup.setDropEngineMessageFormat(Setup.getEngineAttributes()); + Setup.setPickupEngineMessageFormat(Setup.getEngineAttributes()); } } diff --git a/java/test/jmri/jmrit/operations/trains/TrainTest.java b/java/test/jmri/jmrit/operations/trains/TrainTest.java index c91eebdf3c0..f947e3e33fc 100644 --- a/java/test/jmri/jmrit/operations/trains/TrainTest.java +++ b/java/test/jmri/jmrit/operations/trains/TrainTest.java @@ -1897,11 +1897,11 @@ public void testLocal() { } /** - * tests cars with custom loads. A train with two locations, a train to staging, - * and a train out of staging. + * tests cars with custom loads. A train with two locations, the second has + * schedules. */ @Test - public void testScheduleLoads() { + public void testScheduleLoadsA() { ScheduleManager smanager = InstanceManager.getDefault(ScheduleManager.class); @@ -1929,7 +1929,6 @@ public void testScheduleLoads() { // Create locations used Location newWestford = lmanager.newLocation("New Westford"); Location newChelmsford = lmanager.newLocation("New Chelmsford"); - Location newBedford = lmanager.newLocation("New Bedford"); Track westfordYard1; westfordYard1 = newWestford.addTrack("Westford Yard 1", Track.YARD); @@ -1990,26 +1989,16 @@ public void testScheduleLoads() { chelmsfordFreight4.setSchedule(sch2); chelmsfordFreight4.setScheduleMode(Track.SEQUENTIAL); - Track bedfordYard1; - bedfordYard1 = newBedford.addTrack("Bedford Yard 1", Track.STAGING); - bedfordYard1.setTrainDirections(Track.WEST + Track.EAST); - bedfordYard1.setLength(900); - bedfordYard1.setRemoveCustomLoadsEnabled(true); - // Create route with 2 location Route rte1; rte1 = rmanager.newRoute("Two Location Route"); RouteLocation rl1 = rte1.addLocation(newWestford); rl1.setTrainDirection(RouteLocation.EAST); rl1.setMaxCarMoves(12); - rl1.setTrainIconX(25); // set the train icon coordinates - rl1.setTrainIconY(75); RouteLocation rl2 = rte1.addLocation(newChelmsford); rl2.setTrainDirection(RouteLocation.EAST); rl2.setMaxCarMoves(12); - rl2.setTrainIconX(75); // set the train icon coordinates - rl2.setTrainIconY(75); // Create train Train train1; @@ -2105,23 +2094,84 @@ public void testScheduleLoads() { Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName()); Assert.assertEquals("c13 load", "Tin", c13.getLoadName()); - // create a route to staging to test remove schedule load + JUnitOperationsUtil.checkOperationsShutDownTask(); + } + + /** + * tests cars with custom loads. train to staging, staging removes custom loads. + */ + @Test + public void testScheduleLoadsB() { + + // Create locations used + Location newChelmsford = lmanager.newLocation("New Chelmsford"); + Location newBedford = lmanager.newLocation("New Bedford"); + + Track chelmsfordFreight1; + chelmsfordFreight1 = newChelmsford.addTrack("Chelmsford Freight 1", Track.SPUR); + chelmsfordFreight1.setLength(900); + + Track chelmsfordFreight2; + chelmsfordFreight2 = newChelmsford.addTrack("Chelmsford Freight 2", Track.SPUR); + chelmsfordFreight2.setLength(900); + + Track chelmsfordYard3; + chelmsfordYard3 = newChelmsford.addTrack("Chelmsford Yard 3", Track.YARD); + chelmsfordYard3.setLength(900); + + Track chelmsfordFreight4; + chelmsfordFreight4 = newChelmsford.addTrack("Chelmsford Freight 4", Track.SPUR); + chelmsfordFreight4.setLength(900); + + Track bedfordYard1; + bedfordYard1 = newBedford.addTrack("Bedford Yard 1", Track.STAGING); + bedfordYard1.setLength(900); + bedfordYard1.setRemoveCustomLoadsEnabled(true); + + // Set up 13 cars + Car c1 = JUnitOperationsUtil.createAndPlaceCar("BM", "S1", "Gon", "90", chelmsfordFreight1, 13); + c1.setLoadName("Tin"); + Car c2 = JUnitOperationsUtil.createAndPlaceCar("UP", "2", "Boxcar", "80", chelmsfordFreight2, 12); + c2.setLoadName("L"); + Car c3 = JUnitOperationsUtil.createAndPlaceCar("XP", "S3", "Flat Car", "70", chelmsfordYard3, 0); + c3.setLoadName("L"); + Car c4 = JUnitOperationsUtil.createAndPlaceCar("PU", "S4", "Boxcar", "60", chelmsfordYard3, 10); + Car c5 = JUnitOperationsUtil.createAndPlaceCar("UP", "S5", "Gon", "50", chelmsfordFreight2, 9); + c5.setLoadName("Tin"); + Car c6 = JUnitOperationsUtil.createAndPlaceCar("CP", "S6", "Boxcar", "40", chelmsfordYard3, 8); + c6.setLoadName("L"); + Car c7 = JUnitOperationsUtil.createAndPlaceCar("UP", "S7", "Boxcar", "50", chelmsfordFreight4, 7); + c7.setLoadName("L"); + + Car c9 = JUnitOperationsUtil.createAndPlaceCar("XP", "S9", "Flat Car", "90", chelmsfordFreight1, 5); + c9.setLoadName("Scrap"); + Car c10 = JUnitOperationsUtil.createAndPlaceCar("CP", "S10", "Coil Car", "40", chelmsfordFreight4, 2); + c10.setLoadName("E"); + Car c11 = JUnitOperationsUtil.createAndPlaceCar("CP", "S11", "Coil Car", "40", chelmsfordFreight4, 3); + c11.setLoadName("E"); + + Car c13 = JUnitOperationsUtil.createAndPlaceCar("UP", "S13", "Gon", "50", chelmsfordFreight2, 1); + c13.setLoadName("Tin"); + + // place two cars in a kernel + Kernel k1 = cmanager.newKernel("TwoCars"); + c5.setKernel(k1); + c13.setKernel(k1); + + // create a route to staging to test remove custom loads // Create route with 2 location Route rte2; rte2 = rmanager.newRoute("Chelmsford to Staging"); RouteLocation r2rl1 = rte2.addLocation(newChelmsford); r2rl1.setTrainDirection(RouteLocation.EAST); r2rl1.setMaxCarMoves(12); - r2rl1.setTrainIconX(125); // set the train icon coordinates - r2rl1.setTrainIconY(75); RouteLocation r2rl3 = rte2.addLocation(newBedford); r2rl3.setTrainDirection(RouteLocation.EAST); r2rl3.setMaxCarMoves(12); - r2rl3.setTrainIconX(175); // set the train icon coordinates - r2rl3.setTrainIconY(75); + // Create train + Train train1 = tmanager.newTrain("Chelmsford to Bedford"); train1.setRoute(rte2); - train1.setName("Chelmsford to Bedford"); Assert.assertTrue(train1.build()); // move and terminate train @@ -2143,53 +2193,280 @@ public void testScheduleLoads() { Assert.assertEquals("c6 load to staging", "L", c6.getLoadName()); Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName()); Assert.assertEquals("c7 load to staging", "L", c7.getLoadName()); - Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName()); - Assert.assertEquals("c8 load to staging", "E", c8.getLoadName()); + Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName()); Assert.assertEquals("c9 load to staging", "E", c9.getLoadName()); Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName()); Assert.assertEquals("c10 load to staging", "E", c10.getLoadName()); Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName()); Assert.assertEquals("c11 load to staging", "E", c11.getLoadName()); - Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName()); - Assert.assertEquals("c12 load to staging", "E", c12.getLoadName()); + Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName()); Assert.assertEquals("c13 load to staging", "E", c13.getLoadName()); + JUnitOperationsUtil.checkOperationsShutDownTask(); + } + + /** + * tests cars with custom loads. Train out of staging should generate custom loads. + */ + @Test + public void testScheduleLoadsC() { + + ScheduleManager smanager = InstanceManager.getDefault(ScheduleManager.class); + + // create schedules + Schedule sch1 = smanager.newSchedule("Schedule 1"); + ScheduleItem sch1Item1 = sch1.addItem("Boxcar"); + // request a UP Boxcar + sch1Item1.setRoadName("UP"); + sch1Item1.setReceiveLoadName("Metal 1"); + + ScheduleItem sch1Item2 = sch1.addItem("Flat Car"); + // request an empty car and load it with Scrap + sch1Item2.setReceiveLoadName("Metal 2"); + sch1Item2.setShipLoadName("Scrap"); + + ScheduleItem sch1Item3 = sch1.addItem("Gon"); + // request a loaded car and load it with Tin + sch1Item3.setReceiveLoadName("Metal 3"); + sch1Item3.setShipLoadName("Tin"); + + InstanceManager.getDefault(CarLoads.class).addName("Boxcar", "Metal 1"); + InstanceManager.getDefault(CarLoads.class).addName("Flat Car", "Metal 2"); + InstanceManager.getDefault(CarLoads.class).addName("Gon", "Metal 3"); + + Schedule sch2 = smanager.newSchedule("Schedule 2"); + ScheduleItem sch2Item1 = sch2.addItem("Coil Car"); + sch2Item1.setCount(2); + sch2.addItem("Boxcar"); + + // Create locations used + Location newWestford = lmanager.newLocation("New Westford"); + Location newChelmsford = lmanager.newLocation("New Chelmsford"); + Location newBedford = lmanager.newLocation("New Bedford"); + + Track westfordYard1; + westfordYard1 = newWestford.addTrack("Westford Yard 1", Track.YARD); + westfordYard1.setTrainDirections(Track.WEST + Track.EAST); + westfordYard1.setLength(900); + + Track westfordYard2; + westfordYard2 = newWestford.addTrack("Westford Yard 2", Track.YARD); + westfordYard2.setTrainDirections(Track.WEST + Track.EAST); + westfordYard2.setLength(500); + westfordYard2.deleteTypeName("Coil Car"); + + Track westfordExpress3; + westfordExpress3 = newWestford.addTrack("Westford Express 3", Track.SPUR); + westfordExpress3.setTrainDirections(Track.WEST + Track.EAST); + westfordExpress3.setLength(300); + westfordExpress3.deleteTypeName("Gon"); + westfordExpress3.deleteTypeName("Coil Car"); + + Track westfordExpress4; + westfordExpress4 = newWestford.addTrack("Westford Express 4", Track.SPUR); + westfordExpress4.setTrainDirections(Track.WEST + Track.EAST); + westfordExpress4.setLength(300); + westfordExpress4.deleteTypeName("Gon"); + westfordExpress4.deleteTypeName("Coil Car"); + + Track chelmsfordFreight1; + chelmsfordFreight1 = newChelmsford.addTrack("Chelmsford Freight 1", Track.SPUR); + chelmsfordFreight1.setTrainDirections(Track.WEST + Track.EAST); + chelmsfordFreight1.setLength(900); + chelmsfordFreight1.deleteTypeName("Coil Car"); + chelmsfordFreight1.setSchedule(sch1); + chelmsfordFreight1.setScheduleMode(Track.SEQUENTIAL); + // start the schedule with 2nd item Flat Car + chelmsfordFreight1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId()); + + Track chelmsfordFreight2; + chelmsfordFreight2 = newChelmsford.addTrack("Chelmsford Freight 2", Track.SPUR); + chelmsfordFreight2.setTrainDirections(Track.WEST + Track.EAST); + chelmsfordFreight2.setLength(900); + chelmsfordFreight2.deleteTypeName("Coil Car"); + chelmsfordFreight2.setSchedule(sch1); + chelmsfordFreight2.setScheduleMode(Track.SEQUENTIAL); + // start the schedule with 3rd item Gon + chelmsfordFreight2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId()); + + Track chelmsfordYard3; + chelmsfordYard3 = newChelmsford.addTrack("Chelmsford Yard 3", Track.YARD); + chelmsfordYard3.setTrainDirections(Track.WEST + Track.EAST); + chelmsfordYard3.setLength(900); + chelmsfordYard3.deleteTypeName("Gon"); + chelmsfordYard3.deleteTypeName("Coil Car"); + + Track chelmsfordFreight4; + chelmsfordFreight4 = newChelmsford.addTrack("Chelmsford Freight 4", Track.SPUR); + chelmsfordFreight4.setTrainDirections(Track.WEST + Track.EAST); + chelmsfordFreight4.setLength(900); + chelmsfordFreight4.setSchedule(sch2); + chelmsfordFreight4.setScheduleMode(Track.SEQUENTIAL); + + Track bedfordYard1; + bedfordYard1 = newBedford.addTrack("Bedford Yard 1", Track.STAGING); + bedfordYard1.setTrainDirections(Track.WEST + Track.EAST); + bedfordYard1.setLength(900); + bedfordYard1.setRemoveCustomLoadsEnabled(true); + // create a route from staging to test generate schedule load // Create route with 3 locations Route rte3; - rte3 = rmanager.newRoute("Staging to Chelmsford"); + rte3 = rmanager.newRoute("Staging to Westford"); RouteLocation r3rl1 = rte3.addLocation(newBedford); r3rl1.setTrainDirection(RouteLocation.EAST); r3rl1.setMaxCarMoves(11); // there are 11 cars departing staging - r3rl1.setTrainIconX(25); // set the train icon coordinates - r3rl1.setTrainIconY(100); RouteLocation r3rl2 = rte3.addLocation(newChelmsford); r3rl2.setTrainDirection(RouteLocation.EAST); r3rl2.setMaxCarMoves(12); RouteLocation r3rl3 = rte3.addLocation(newWestford); r3rl3.setTrainDirection(RouteLocation.EAST); r3rl3.setMaxCarMoves(12); - r3rl3.setTrainIconX(75); // set the train icon coordinates - r3rl3.setTrainIconY(100); - bedfordYard1.setRemoveCustomLoadsEnabled(false); - bedfordYard1.setAddCustomLoadsAnySpurEnabled(true); // generate schedule loads + // Create train + Train train1; + train1 = tmanager.newTrain("BCW"); + train1.setRoute(rte3); - sch1Item1.setReceiveLoadName("Metal 1"); // request these loads from staging - sch1Item2.setReceiveLoadName("Metal 2"); - sch1Item3.setReceiveLoadName("Metal 3"); + // Set up 13 cars + Car c1 = JUnitOperationsUtil.createAndPlaceCar("BM", "S1", "Gon", "90", bedfordYard1, 13); + c1.setLoadName("E"); + Car c2 = JUnitOperationsUtil.createAndPlaceCar("UP", "2", "Boxcar", "80", bedfordYard1, 12); + c2.setLoadName("L"); + Car c3 = JUnitOperationsUtil.createAndPlaceCar("XP", "S3", "Flat Car", "70", bedfordYard1, 0); + c3.setLoadName("L"); + Car c4 = JUnitOperationsUtil.createAndPlaceCar("PU", "S4", "Boxcar", "60", bedfordYard1, 10); + Car c5 = JUnitOperationsUtil.createAndPlaceCar("UP", "S5", "Gon", "50", bedfordYard1, 9); + c5.setLoadName("E"); + Car c6 = JUnitOperationsUtil.createAndPlaceCar("CP", "S6", "Boxcar", "40", bedfordYard1, 8); + c6.setLoadName("L"); + Car c7 = JUnitOperationsUtil.createAndPlaceCar("UP", "S7", "Boxcar", "50", bedfordYard1, 7); + c7.setLoadName("L"); + Car c8 = JUnitOperationsUtil.createAndPlaceCar("XP", "S8", "Gon", "60", westfordYard2, 6); + Car c9 = JUnitOperationsUtil.createAndPlaceCar("XP", "S9", "Flat Car", "90", bedfordYard1, 5); + Car c10 = JUnitOperationsUtil.createAndPlaceCar("CP", "S10", "Coil Car", "40", bedfordYard1, 2); + c10.setLoadName("E"); + Car c11 = JUnitOperationsUtil.createAndPlaceCar("CP", "S11", "Coil Car", "40", bedfordYard1, 3); + c11.setLoadName("E"); + Car c12 = JUnitOperationsUtil.createAndPlaceCar("CP", "S12", "Coil Car", "40", westfordYard1, 4); + Car c13 = JUnitOperationsUtil.createAndPlaceCar("UP", "S13", "Gon", "50", bedfordYard1, 1); + c13.setLoadName("E"); - InstanceManager.getDefault(CarLoads.class).addName("Gon", "Metal 3"); // Allows c13 which is part of a kernel to - // get a new load + // place two cars in a kernel + Kernel k1 = cmanager.newKernel("TwoCars"); + c5.setKernel(k1); + c13.setKernel(k1); - train1.setRoute(rte3); - train1.setName("BCW"); - Assert.assertTrue(train1.build()); +// Assert.assertTrue(train1.build()); + +// // Schedule sch1 should cause c2 to be delivered to Chelmsford Freight 2 +// Assert.assertEquals("c2 destination", "Chelmsford Freight 2", c2.getDestinationTrackName()); +// Assert.assertEquals("c2 next load", "", c2.getNextLoadName()); +// // Schedule sch1 and sch2 should reject c3, to be delivered to Chelmsford Yard 3 +// Assert.assertEquals("c3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName()); +// Assert.assertEquals("c3 next load", "", c3.getNextLoadName()); +// Assert.assertEquals("c4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName()); +// // Schedule sch1 should cause c5 & c13 to be delivered to Chelmsford Freight 2 +// Assert.assertEquals("c5 destination", "Chelmsford Freight 2", c5.getDestinationTrackName()); +// Assert.assertEquals("c5 next load", "Tin", c5.getNextLoadName()); +// Assert.assertEquals("c6 destination", "Chelmsford Yard 3", c6.getDestinationTrackName()); +// Assert.assertEquals("c7 destination", "Chelmsford Freight 4", c7.getDestinationTrackName()); +// Assert.assertEquals("c9 destination", "Chelmsford Freight 1", c9.getDestinationTrackName()); +// Assert.assertEquals("c9 next load", "Scrap", c9.getNextLoadName()); +// Assert.assertEquals("c10 destination", "Chelmsford Freight 4", c10.getDestinationTrackName()); +// Assert.assertEquals("c11 destination", "Chelmsford Freight 4", c11.getDestinationTrackName()); +// // C13 is part of kernel +// Assert.assertEquals("c13 destination", "Chelmsford Freight 2", c13.getDestinationTrackName()); +// Assert.assertEquals("c13 next load", "Tin", c13.getNextLoadName()); +// +// // move and terminate train +// train1.move(); +// train1.move(); +// train1.move(); +// +// Assert.assertEquals("c1 track", "Chelmsford Freight 1", c1.getTrackName()); +// Assert.assertEquals("c1 load", "Tin", c1.getLoadName()); +// Assert.assertEquals("c2 track", "Chelmsford Freight 2", c2.getTrackName()); +// Assert.assertEquals("c2 load", "L", c2.getLoadName()); +// Assert.assertEquals("c3 track", "Chelmsford Yard 3", c3.getTrackName()); +// Assert.assertEquals("c3 load", "L", c3.getLoadName()); +// Assert.assertEquals("c4 track", "Chelmsford Yard 3", c4.getTrackName()); +// Assert.assertEquals("c4 load", "E", c4.getLoadName()); +// Assert.assertEquals("c5 track", "Chelmsford Freight 2", c5.getTrackName()); +// Assert.assertEquals("c5 load", "Tin", c5.getLoadName()); +// Assert.assertEquals("c6 track", "Chelmsford Yard 3", c6.getTrackName()); +// Assert.assertEquals("c6 load", "L", c6.getLoadName()); +// Assert.assertEquals("c7 track", "Chelmsford Freight 4", c7.getTrackName()); +// Assert.assertEquals("c7 load", "L", c7.getLoadName()); +// Assert.assertEquals("c8 track", "Westford Yard 2", c8.getTrackName()); +// Assert.assertEquals("c8 load", "E", c8.getLoadName()); +// Assert.assertEquals("c9 track", "Chelmsford Freight 1", c9.getTrackName()); +// Assert.assertEquals("c9 load", "Scrap", c9.getLoadName()); +// Assert.assertEquals("c10 track", "Chelmsford Freight 4", c10.getTrackName()); +// Assert.assertEquals("c10 load", "E", c10.getLoadName()); +// Assert.assertEquals("c11 track", "Chelmsford Freight 4", c11.getTrackName()); +// Assert.assertEquals("c11 load", "E", c11.getLoadName()); +// Assert.assertEquals("c12 track", "Westford Yard 1", c12.getTrackName()); +// Assert.assertEquals("c12 load", "E", c12.getLoadName()); +// Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName()); +// Assert.assertEquals("c13 load", "Tin", c13.getLoadName()); +// +// // create a route to staging to test remove schedule load +// // Create route with 2 location +// Route rte2; +// rte2 = rmanager.newRoute("Chelmsford to Staging"); +// RouteLocation r2rl1 = rte2.addLocation(newChelmsford); +// r2rl1.setTrainDirection(RouteLocation.EAST); +// r2rl1.setMaxCarMoves(12); +// RouteLocation r2rl3 = rte2.addLocation(newBedford); +// r2rl3.setTrainDirection(RouteLocation.EAST); +// r2rl3.setMaxCarMoves(12); +// +// train1.setRoute(rte2); +// train1.setName("Chelmsford to Bedford"); +// Assert.assertTrue(train1.build()); +// +// // move and terminate train +// train1.move(); +// train1.move(); +// train1.move(); + Assert.assertEquals("c1 track to staging", "Bedford Yard 1", c1.getTrackName()); + Assert.assertEquals("c1 load to staging", "E", c1.getLoadName()); + Assert.assertEquals("c2 track to staging", "Bedford Yard 1", c2.getTrackName()); + Assert.assertEquals("c2 load to staging", "L", c2.getLoadName()); + Assert.assertEquals("c3 track to staging", "Bedford Yard 1", c3.getTrackName()); + Assert.assertEquals("c3 load to staging", "L", c3.getLoadName()); + Assert.assertEquals("c4 track to staging", "Bedford Yard 1", c4.getTrackName()); + Assert.assertEquals("c4 load to staging", "E", c4.getLoadName()); + Assert.assertEquals("c5 track to staging", "Bedford Yard 1", c5.getTrackName()); + Assert.assertEquals("c5 load to staging", "E", c5.getLoadName()); + Assert.assertEquals("c6 track to staging", "Bedford Yard 1", c6.getTrackName()); + Assert.assertEquals("c6 load to staging", "L", c6.getLoadName()); + Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName()); + Assert.assertEquals("c7 load to staging", "L", c7.getLoadName()); + Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName()); + Assert.assertEquals("c8 load to staging", "E", c8.getLoadName()); + Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName()); + Assert.assertEquals("c9 load to staging", "E", c9.getLoadName()); + Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName()); + Assert.assertEquals("c10 load to staging", "E", c10.getLoadName()); + Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName()); + Assert.assertEquals("c11 load to staging", "E", c11.getLoadName()); + Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName()); + Assert.assertEquals("c12 load to staging", "E", c12.getLoadName()); + Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName()); + Assert.assertEquals("c13 load to staging", "E", c13.getLoadName()); + +// bedfordYard1.setRemoveCustomLoadsEnabled(false); + bedfordYard1.setAddCustomLoadsAnySpurEnabled(true); // generate schedule loads + + Assert.assertTrue(train1.build()); Assert.assertEquals("Train Bedford Chelmsford Westford build status", true, train1.isBuilt()); - Assert.assertEquals("c1 load from staging", "E", c1.getLoadName()); + + Assert.assertEquals("c1 load from staging", "Metal 3", c1.getLoadName()); Assert.assertEquals("c2 load from staging", "L", c2.getLoadName()); Assert.assertEquals("c3 load from staging", "L", c3.getLoadName()); Assert.assertEquals("c4 load from staging", "E", c4.getLoadName()); @@ -2209,8 +2486,8 @@ public void testScheduleLoads() { train1.move(); train1.move(); - Assert.assertEquals("c1 track from staging terminated", "Westford Yard 1", c1.getTrackName()); - Assert.assertEquals("c1 load from staging terminated", "E", c1.getLoadName()); + Assert.assertEquals("c1 track from staging terminated", "Chelmsford Freight 1", c1.getTrackName()); + Assert.assertEquals("c1 load from staging terminated", "Tin", c1.getLoadName()); Assert.assertEquals("c2 track from staging terminated", "Westford Yard 2", c2.getTrackName()); Assert.assertEquals("c2 load from staging terminated", "L", c2.getLoadName()); Assert.assertEquals("c3 track from staging terminated", "Westford Yard 1", c3.getTrackName()); @@ -2225,7 +2502,7 @@ public void testScheduleLoads() { Assert.assertEquals("c7 load from staging terminated", "L", c7.getLoadName()); Assert.assertEquals("c8 track from staging terminated", "Westford Yard 2", c8.getTrackName()); Assert.assertEquals("c8 load from staging terminated", "E", c8.getLoadName()); - Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 2", c9.getTrackName()); + Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 1", c9.getTrackName()); Assert.assertEquals("c9 load from staging terminated", "Scrap", c9.getLoadName()); Assert.assertEquals("c10 track from staging terminated", "Chelmsford Freight 4", c10.getTrackName()); Assert.assertEquals("c10 load from staging terminated", "L", c10.getLoadName()); @@ -2234,7 +2511,7 @@ public void testScheduleLoads() { Assert.assertEquals("c12 track from staging terminated", "Westford Yard 1", c12.getTrackName()); Assert.assertEquals("c12 load from staging terminated", "E", c12.getLoadName()); Assert.assertEquals("c13 track from staging terminated", "Chelmsford Freight 2", c13.getTrackName()); - Assert.assertEquals("c13 load from staging terminated", "Tin", c13.getLoadName()); + Assert.assertEquals("c13 load from staging terminated", "E", c13.getLoadName()); JUnitOperationsUtil.checkOperationsShutDownTask(); }