Commit c2408a8f authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Extract method for waiting behavior

parent 54976b95
......@@ -61,31 +61,7 @@ public class TargetController {
if (target.getWaitingTime() <= 0) {
checkRemove(agent);
} else {
final int agentId = agent.getId();
// individual waiting behaviour, as opposed to waiting at a traffic light
if (target.getAttributes().isIndividualWaiting()) {
final Map<Integer, Double> enteringTimes = target.getEnteringTimes();
if (enteringTimes.containsKey(agentId)) {
if (simTimeInSec - enteringTimes.get(agentId) > target
.getWaitingTime()) {
enteringTimes.remove(agentId);
checkRemove(agent);
}
} else {
final int parallelWaiters = target.getParallelWaiters();
if (parallelWaiters <= 0 || (parallelWaiters > 0 &&
enteringTimes.size() < parallelWaiters)) {
enteringTimes.put(agentId, simTimeInSec);
}
}
} else {
// traffic light switching based on waiting time. Light starts green.
phase = getCurrentTrafficLightPhase(simTimeInSec);
if (phase == TrafficLightPhase.GREEN) {
checkRemove(agent);
}
}
waitingBehavior(simTimeInSec, agent);
}
}
}
......@@ -105,6 +81,34 @@ public class TargetController {
return elementsInRange;
}
private void waitingBehavior(double simTimeInSec, final Agent agent) {
final int agentId = agent.getId();
// individual waiting behaviour, as opposed to waiting at a traffic light
if (target.getAttributes().isIndividualWaiting()) {
final Map<Integer, Double> enteringTimes = target.getEnteringTimes();
if (enteringTimes.containsKey(agentId)) {
if (simTimeInSec - enteringTimes.get(agentId) > target
.getWaitingTime()) {
enteringTimes.remove(agentId);
checkRemove(agent);
}
} else {
final int parallelWaiters = target.getParallelWaiters();
if (parallelWaiters <= 0 || (parallelWaiters > 0 &&
enteringTimes.size() < parallelWaiters)) {
enteringTimes.put(agentId, simTimeInSec);
}
}
} else {
// traffic light switching based on waiting time. Light starts green.
phase = getCurrentTrafficLightPhase(simTimeInSec);
if (phase == TrafficLightPhase.GREEN) {
checkRemove(agent);
}
}
}
private <T extends DynamicElement> List<T> getObjectsInCircle(final Class<T> clazz, final VPoint center, final double radius) {
return topography.getSpatialMap(clazz).getObjects(center, radius);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment