From b8b0c07cdd4d65ade14e58604065506d9fefa0e3 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 14 Aug 2024 15:32:07 +0200 Subject: [PATCH] minor internal simplification --- .../CollectionCarrierScheduler.java | 24 +++++++++---------- .../DistributionCarrierScheduler.java | 17 ++++++------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index 4d8c35b3..c3448994 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -29,6 +29,7 @@ import org.matsim.freight.carriers.ScheduledTour; import org.matsim.freight.carriers.Tour; import org.matsim.freight.carriers.Tour.Leg; +import org.matsim.freight.carriers.Tour.ServiceActivity; import org.matsim.freight.carriers.Tour.TourElement; import org.matsim.freight.logistics.*; import org.matsim.freight.logistics.shipment.LspShipment; @@ -82,14 +83,12 @@ public void scheduleResource() { } private CarrierService convertToCarrierService(LspShipment lspShipment) { - Id serviceId = - Id.create(lspShipment.getId().toString(), CarrierService.class); - CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()); - builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()); - builder.setCapacityDemand(lspShipment.getSize()); - builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); - CarrierService carrierService = builder.build(); + Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); + CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()) + .setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()) + .setCapacityDemand(lspShipment.getSize()) + .setServiceDuration(lspShipment.getDeliveryServiceTime()) + .build(); pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @@ -100,11 +99,10 @@ protected void updateShipments() { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { - if (element instanceof Tour.ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); + if (element instanceof ServiceActivity serviceActivity) { for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == carrierPair.lspShipment - && pair.carrierService.getId() == carrierPair.carrierService.getId()) { + if (pair.lspShipment == lspShipment + && pair.carrierService.getId() == serviceActivity.getService().getId()) { addShipmentLoadElement(lspShipment, tour, serviceActivity); addShipmentTransportElement(lspShipment, tour, serviceActivity); addShipmentUnloadElement(lspShipment, tour); @@ -119,7 +117,7 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java index 16aae7ca..2dc40979 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -171,13 +171,11 @@ private Collection unifyTourIds(Collection carrierPl } private CarrierService convertToCarrierService(LspShipment lspShipment) { - Id serviceId = - Id.create(lspShipment.getId().toString(), CarrierService.class); - CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()); - builder.setCapacityDemand(lspShipment.getSize()); - builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); - CarrierService carrierService = builder.build(); + Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); + CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()) + .setCapacityDemand(lspShipment.getSize()) + .setServiceDuration(lspShipment.getDeliveryServiceTime()) + .build(); pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @@ -189,10 +187,9 @@ protected void updateShipments() { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == carrierPair.lspShipment - && pair.carrierService.getId() == carrierPair.carrierService.getId()) { + if (pair.lspShipment == lspShipment + && pair.carrierService.getId() == serviceActivity.getService().getId()) { addShipmentLoadElement(lspShipment, tour); addShipmentTransportElement(lspShipment, tour, serviceActivity); addShipmentUnloadElement(lspShipment, tour, serviceActivity);