From 8be99e1ea0d184333bbccbe2bd341ac7a46afb9e Mon Sep 17 00:00:00 2001 From: u228298 Date: Tue, 19 Nov 2024 23:09:19 +0100 Subject: [PATCH] refactor: rename vehicle type and product to category in core and supply package --- .../converter/core/NetworkGraphicConverter.java | 13 ++++++------- .../core/supply/RollingStockRepository.java | 2 +- .../converter/core/supply/SupplyBuilder.java | 2 +- .../converter/core/supply/TransitLineInfo.java | 2 +- .../supply/fallback/NoRollingStockRepository.java | 4 ++-- .../supply/fallback/NoVehicleCircuitsPlanner.java | 10 +++++----- .../converter/matsim/MatsimSupplyBuilder.java | 4 ++-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/NetworkGraphicConverter.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/NetworkGraphicConverter.java index b312ff0..5fa7bd0 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/NetworkGraphicConverter.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/NetworkGraphicConverter.java @@ -102,10 +102,9 @@ private void addTrains() { private void createAndAddTransitLine(Trainrun train, EnumMap> sequence) { - // get vehicle type info from train category and create line id based on forward direction or trainrun name - String vehicleType = lookup.categories.get(train.getCategoryId()).getShortName(); - String lineId = createTransitLineId(train, sequence.get(RouteDirection.FORWARD), vehicleType); - builder.addTransitLine(lineId, vehicleType); + String category = lookup.categories.get(train.getCategoryId()).getShortName(); + String lineId = createTransitLineId(train, sequence.get(RouteDirection.FORWARD), category); + builder.addTransitLine(lineId, category); // add transit route for each direction for (RouteDirection direction : RouteDirection.values()) { @@ -180,15 +179,15 @@ private void createAndAddTransitRoute(String lineId, Trainrun train, List builder.addDeparture(routeId, departure)); } - private String createTransitLineId(Trainrun train, List sections, String vehicleType) { + private String createTransitLineId(Trainrun train, List sections, String category) { // check if option is set to use train name; also avoid name if it is empty (optional field in NGE) String lineId; if (config.isUseTrainNamesAsIds() && !train.getName().isBlank()) { lineId = train.getName(); } else { - // create id from vehicle type with origin and destination, ignore the train name from nge - lineId = String.format("%s_%s_%s", vehicleType, + // create id from category with origin and destination, ignore the train name from nge + lineId = String.format("%s_%s_%s", category, lookup.nodes.get(sections.getFirst().getSourceNodeId()).getBetriebspunktName(), lookup.nodes.get(sections.getLast().getTargetNodeId()).getBetriebspunktName()); } diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/RollingStockRepository.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/RollingStockRepository.java index f5b25ea..591782b 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/RollingStockRepository.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/RollingStockRepository.java @@ -2,6 +2,6 @@ public interface RollingStockRepository { - VehicleTypeInfo getVehicleType(String productId); + VehicleTypeInfo getVehicleType(String category); } diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/SupplyBuilder.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/SupplyBuilder.java index 0a2cd31..aacb6a5 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/SupplyBuilder.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/SupplyBuilder.java @@ -7,7 +7,7 @@ public interface SupplyBuilder { SupplyBuilder addStopFacility(String id, double x, double y); - SupplyBuilder addTransitLine(String id, String productId); + SupplyBuilder addTransitLine(String id, String category); SupplyBuilder addTransitRoute(String id, String lineId, String originStopId, Duration dwellTimeAtOrigin); diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/TransitLineInfo.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/TransitLineInfo.java index 5909064..d48f273 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/TransitLineInfo.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/TransitLineInfo.java @@ -6,6 +6,6 @@ public class TransitLineInfo { String id; - String productId; + String category; } diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoRollingStockRepository.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoRollingStockRepository.java index caa654b..5e3ee6a 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoRollingStockRepository.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoRollingStockRepository.java @@ -12,8 +12,8 @@ public class NoRollingStockRepository implements RollingStockRepository { public static final double DEFAULT_MAX_VELOCITY = 120 / 3.6; // meters per second @Override - public VehicleTypeInfo getVehicleType(String productId) { - return new VehicleTypeInfo(productId, DEFAULT_CAPACITY, DEFAULT_LENGTH, DEFAULT_MAX_VELOCITY, Map.of()); + public VehicleTypeInfo getVehicleType(String category) { + return new VehicleTypeInfo(category, DEFAULT_CAPACITY, DEFAULT_LENGTH, DEFAULT_MAX_VELOCITY, Map.of()); } } diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoVehicleCircuitsPlanner.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoVehicleCircuitsPlanner.java index 7ba8741..b9a4384 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoVehicleCircuitsPlanner.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/core/supply/fallback/NoVehicleCircuitsPlanner.java @@ -34,12 +34,12 @@ public List plan() { return departureInfos.stream().sorted(Comparator.comparing(DepartureInfo::getTime)).map(departureInfo -> { - // get vehicle type based on product - String productId = departureInfo.getTransitRouteInfo().getTransitLineInfo().getProductId(); - VehicleTypeInfo vehicleTypeInfo = vehicleTypeInfos.get(productId); + // get vehicle type based on category (product) + String category = departureInfo.getTransitRouteInfo().getTransitLineInfo().getCategory(); + VehicleTypeInfo vehicleTypeInfo = vehicleTypeInfos.get(category); if (vehicleTypeInfo == null) { - vehicleTypeInfo = rollingStockRepository.getVehicleType(productId); - vehicleTypeInfos.put(productId, vehicleTypeInfo); + vehicleTypeInfo = rollingStockRepository.getVehicleType(category); + vehicleTypeInfos.put(category, vehicleTypeInfo); } // update vehicle counts and departure counts diff --git a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/matsim/MatsimSupplyBuilder.java b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/matsim/MatsimSupplyBuilder.java index 6b9b52b..d3a4f5d 100644 --- a/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/matsim/MatsimSupplyBuilder.java +++ b/src/main/java/ch/sbb/pfi/netzgrafikeditor/converter/matsim/MatsimSupplyBuilder.java @@ -57,12 +57,12 @@ public SupplyBuilder addStopFacility(String id, double x, double y) { } @Override - public SupplyBuilder addTransitLine(String id, String productId) { + public SupplyBuilder addTransitLine(String id, String category) { if (transitLineInfos.containsKey(id)) { throw new RuntimeException("Transit line already exists for id " + id); } - transitLineInfos.put(id, new TransitLineInfo(id, productId)); + transitLineInfos.put(id, new TransitLineInfo(id, category)); return this; }