@Override
 public void handleEvent(VehicleEntersTrafficEvent event) {
   if (modes.contains(event.getNetworkMode())) {
     delegate.handleEvent(event);
     vehicleIds.add(event.getVehicleId());
   }
 }
예제 #2
0
    @Override
    public void handleEvent(VehicleEntersTrafficEvent event) {
      // save drivers
      vehicleToDriver.put(event.getVehicleId(), event.getPersonId());

      if (!eventsByPerson.containsKey(event.getPersonId())) {
        eventsByPerson.put(event.getPersonId(), new LinkedList<Event>());
      }
      eventsByPerson.get(event.getPersonId()).add(event);
      allEvents.add(event);
    }
  @Override
  public boolean doProcessEvent(Event event) {
    Id linkId = null;
    Id vehId = null;
    if (event instanceof VehicleEntersTrafficEvent) {
      VehicleEntersTrafficEvent e = (VehicleEntersTrafficEvent) event;
      linkId = e.getLinkId();
      vehId = e.getVehicleId();
    } else if (event instanceof LinkEnterEvent) {
      LinkEnterEvent e = (LinkEnterEvent) event;
      linkId = e.getLinkId();
      vehId = e.getVehicleId();
    } else if (event instanceof PersonEntersVehicleEvent) {
      PersonEntersVehicleEvent e = (PersonEntersVehicleEvent) event;
      if (e.getPersonId().toString().startsWith("pt_")) {
        return false;
      }
      if (this.networkContainedLastLinkEnterByVehicleId.containsKey(e.getVehicleId())
          && this.networkContainedLastLinkEnterByVehicleId.get(e.getVehicleId())) {
        this.countedPersonIds.add(e.getPersonId());
        return true;
      }
    } else if (event instanceof PersonLeavesVehicleEvent) {
      PersonLeavesVehicleEvent e = (PersonLeavesVehicleEvent) event;
      if (e.getPersonId().toString().startsWith("pt_")) {
        return false;
      }
      if (this.networkContainedLastLinkEnterByVehicleId.containsKey(e.getVehicleId())
          && this.networkContainedLastLinkEnterByVehicleId.get(e.getVehicleId())
          && countedPersonIds.contains(e.getPersonId())) {
        countedPersonIds.remove(e.getPersonId());
        return true;
      } else if (this.countedPersonIds.contains(e.getPersonId())) {
        countedPersonIds.remove(e.getPersonId());
        return true;
      }
    }

    if (linkId != null) {
      if (this.network.getLinks().containsKey(linkId)) {
        this.networkContainedLastLinkEnterByVehicleId.put(vehId, true);
        return true;
      } else {
        this.networkContainedLastLinkEnterByVehicleId.put(vehId, false);
        return true;
      }
    }

    return false;
  }