Skip to content

Commit

Permalink
Do not use default method in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
marecabo committed Mar 18, 2024
1 parent b89ad74 commit e1ba68d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.matsim.contribs.discrete_mode_choice.components.utils;

import java.util.List;

import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.pt.routes.TransitPassengerRoute;

/**
Expand All @@ -9,8 +12,15 @@
* @author sebhoerl
*/
public class NullWaitingTimeEstimator implements PTWaitingTimeEstimator {

@Override
public double estimateWaitingTime(double agentDepartureTime, TransitPassengerRoute route) {
return 0.0;
}

@Override
public double estimateWaitingTime(List<? extends PlanElement> elements) {
return 0.0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.List;

import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.pt.routes.TransitPassengerRoute;

Expand All @@ -19,16 +17,6 @@ public interface PTWaitingTimeEstimator {

double estimateWaitingTime(double departureTime, TransitPassengerRoute route);

default double estimateWaitingTime(List<? extends PlanElement> elements) {
double totalWaitingTime = 0.0;
double estimateWaitingTime(List<? extends PlanElement> elements);

for (PlanElement element : elements) {
if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) {
TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute();
totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route);
}
}

return totalWaitingTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.core.utils.collections.Tuple;
import org.matsim.core.utils.misc.OptionalTime;
import org.matsim.core.utils.misc.Time;
Expand Down Expand Up @@ -52,6 +55,20 @@ private Tuple<Id<TransitLine>, Id<TransitRoute>> createId(TransitLine transitLin
return new Tuple<>(transitLine.getId(), transitRoute.getId());
}

@Override
public double estimateWaitingTime(List<? extends PlanElement> elements) {
double totalWaitingTime = 0.0;

for (PlanElement element : elements) {
if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) {
TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute();
totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route);
}
}

return totalWaitingTime;
}

@Override
public double estimateWaitingTime(double agentDepartureTime, TransitPassengerRoute route) {
TransitLine transitLine = transitSchedule.getTransitLines().get(route.getLineId());
Expand Down

0 comments on commit e1ba68d

Please sign in to comment.