Skip to content

Commit

Permalink
Java language: use add/getFirst()
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Jul 16, 2024
1 parent 6a1cc65 commit 128b9aa
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Leg createLeg(Route route, double dep_time, double transportTime) {
@Deprecated
public Builder insertLegAtBeginning(Leg leg) {
Gbl.assertNotNull(leg);
tourElements.add(0,leg);
tourElements.addFirst(leg);
return this;
}

Expand All @@ -183,7 +183,7 @@ public Builder schedulePickupAtBeginning(CarrierShipment shipment) {
}
// assertLastElementIsLeg();
Pickup pickup = createPickup(shipment);
tourElements.add(0, pickup);
tourElements.addFirst(pickup);
// previousElementIsActivity = true;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void handleEvent( PersonArrivalEvent event ){
} else{
Id<Link> startLink;
if(!currentRoute.isEmpty()){
startLink = currentRoute.get( 0 );
startLink = currentRoute.getFirst();
} else{
startLink = event.getLinkId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,23 @@ private double calculateRouteDistanceWithAssociatedPickup(JobInsertionContext co
if (positionOfRelatedPickup == 0 && context.getRoute().getActivities().isEmpty()) {
context.getRoute().getStart().setLocation(context.getNewVehicle().getStartLocation());
context.getRoute().getEnd().setLocation(context.getNewVehicle().getEndLocation());
routeDistance = getDistance(context.getAssociatedActivities().get(0), context.getRoute().getEnd(),
routeDistance = getDistance(context.getAssociatedActivities().getFirst(), context.getRoute().getEnd(),
context.getNewVehicle(), context.getNewDepTime());
return routeDistance;
} else if (positionOfRelatedPickup == 0 && !context.getRoute().getActivities().isEmpty()) {
routeDistance = getDistance(context.getAssociatedActivities().get(0),
context.getRoute().getActivities().get(0), context.getNewVehicle(), context.getNewDepTime());
routeDistance = getDistance(context.getAssociatedActivities().getFirst(),
context.getRoute().getActivities().getFirst(), context.getNewVehicle(), context.getNewDepTime());
} else {
routeDistance = getDistance(context.getRoute().getStart(), context.getRoute().getActivities().get(0),
routeDistance = getDistance(context.getRoute().getStart(), context.getRoute().getActivities().getFirst(),
context.getNewVehicle(), context.getNewDepTime());
}
// adds distances between every tour activity and adds the associated pickup on
// the correct position of the tour
while (context.getRoute().getTourActivities().getActivities().size() > (nextRouteActivity + 1)) {
if (positionOfRelatedPickup == (nextRouteActivity + 1) && positionOfRelatedPickup != 0) {
routeDistance = routeDistance + getDistance(context.getRoute().getActivities().get(nextRouteActivity),
context.getAssociatedActivities().get(0), context.getNewVehicle());
routeDistance = routeDistance + getDistance(context.getAssociatedActivities().get(0),
context.getAssociatedActivities().getFirst(), context.getNewVehicle());
routeDistance = routeDistance + getDistance(context.getAssociatedActivities().getFirst(),
context.getRoute().getActivities().get(nextRouteActivity), context.getNewVehicle());
} else {
routeDistance = routeDistance + getDistance(context.getRoute().getActivities().get(nextRouteActivity),
Expand All @@ -168,8 +168,8 @@ private double calculateRouteDistanceWithAssociatedPickup(JobInsertionContext co
}
if (positionOfRelatedPickup == context.getRoute().getActivities().size()) {
routeDistance = routeDistance + getDistance(context.getRoute().getActivities().get(nextRouteActivity),
context.getAssociatedActivities().get(0), context.getNewVehicle());
routeDistance = routeDistance + getDistance(context.getAssociatedActivities().get(0),
context.getAssociatedActivities().getFirst(), context.getNewVehicle());
routeDistance = routeDistance + getDistance(context.getAssociatedActivities().getFirst(),
context.getRoute().getEnd(), context.getNewVehicle());
} else
routeDistance = routeDistance + getDistance(context.getRoute().getActivities().get(nextRouteActivity),
Expand All @@ -189,7 +189,7 @@ private double calculateRouteDistance(JobInsertionContext context, Vehicle newVe
return realRouteDistance;
int n = 0;
realRouteDistance = getDistance(context.getRoute().getStart(),
context.getRoute().getTourActivities().getActivities().get(0), newVehicle);
context.getRoute().getTourActivities().getActivities().getFirst(), newVehicle);
while (context.getRoute().getTourActivities().getActivities().size() > (n + 1)) {
realRouteDistance = realRouteDistance
+ getDistance(context.getRoute().getTourActivities().getActivities().get(n),
Expand Down Expand Up @@ -260,7 +260,7 @@ private double findMinimalAdditionalDistance(JobInsertionContext context, TourAc
// the tour
if (!route.getTourActivities().getActivities().isEmpty()) {
TourActivity activityLastDelivery = route.getTourActivities().getActivities()
.get(route.getTourActivities().getActivities().size() - 1);
.getLast();
TourActivity activityEnd = route.getEnd();
double possibleAdditionalDistance = getDistance(activityLastDelivery, assignedDelivery, newVehicle)
+ getDistance(assignedDelivery, activityEnd, newVehicle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void testReaderReadsCorrectly() {
Carrier carrier = carriers.getCarriers().values().iterator().next();
Assertions.assertEquals(1, carrier.getSelectedPlan().getScheduledTours().size());
Leg leg = (Leg) carrier.getSelectedPlan().getScheduledTours()
.iterator().next().getTour().getTourElements().get(0);
.iterator().next().getTour().getTourElements().getFirst();
NetworkRoute route = (NetworkRoute) leg.getRoute();
Assertions.assertEquals(3, route.getLinkIds().size());
Assertions.assertEquals("23", route.getStartLinkId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void test_whenReadingPlans_nuOfToursIsCorrect(){
@Test
void test_whenReadingToursOfPlan1_nuOfActivitiesIsCorrect(){
List<CarrierPlan> plans = new ArrayList<>(testCarrier.getPlans());
CarrierPlan plan1 = plans.get(0);
CarrierPlan plan1 = plans.getFirst();
ScheduledTour tour1 = plan1.getScheduledTours().iterator().next();
Assertions.assertEquals(5,tour1.getTour().getTourElements().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void test_whenReadingPlans_nuOfToursIsCorrect(){
@Disabled
void test_whenReadingToursOfPlan1_nuOfActivitiesIsCorrect(){
List<CarrierPlan> plans = new ArrayList<>(testCarrier.getPlans());
CarrierPlan plan1 = plans.get(0);
CarrierPlan plan1 = plans.getFirst();
ScheduledTour tour1 = plan1.getScheduledTours().iterator().next();
Assertions.assertEquals(5,tour1.getTour().getTourElements().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void test_whenReadingPlans_nuOfToursIsCorrect(){
@Test
void test_whenReadingToursOfPlan1_nuOfActivitiesIsCorrect(){
List<CarrierPlan> plans = new ArrayList<>(testCarrier.getPlans());
CarrierPlan plan1 = plans.get(0);
CarrierPlan plan1 = plans.getFirst();
ScheduledTour tour1 = plan1.getScheduledTours().iterator().next();
assertEquals(5,tour1.getTour().getTourElements().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void test_whenReadingPlans_nuOfToursIsCorrect(){
@Test
void test_whenReadingToursOfPlan1_nuOfActivitiesIsCorrect(){
List<CarrierPlan> plans = new ArrayList<>(testCarrier.getPlans());
CarrierPlan plan1 = plans.get(0);
CarrierPlan plan1 = plans.getFirst();
ScheduledTour tour1 = plan1.getScheduledTours().iterator().next();
assertEquals(5,tour1.getTour().getTourElements().size());
}
Expand All @@ -137,7 +137,7 @@ void test_whenReadingToursOfPlan3_nuOfActivitiesIsCorrect(){
@Test
void test_whenReadingToursOfPlan1_SpritScoreIsCorrect(){
List<CarrierPlan> plans = new ArrayList<>(testCarrier.getPlans());
CarrierPlan plan1 = plans.get(0);
CarrierPlan plan1 = plans.getFirst();
plan1.getAttributes().getAttribute("jspritScore");
assertEquals(Double.NaN, CarriersUtils.getJspritScore(plan1), testUtils.EPSILON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void whenTransforming_matsimScheduledTourWithServiceAct2vehicleRoute_firstActIdM
ScheduledTour sTour = getMatsimServiceTour();
VehicleRoutingProblem vehicleRoutingProblem = getVehicleRoutingProblem(sTour);
VehicleRoute route = MatsimJspritFactory.createRoute(sTour, vehicleRoutingProblem);
assertEquals("to1", route.getTourActivities().getActivities().get(0).getLocation().getId());
assertEquals("to1", route.getTourActivities().getActivities().getFirst().getLocation().getId());
}

@Test
Expand Down

0 comments on commit 128b9aa

Please sign in to comment.