MATSIM
MyEventHandler.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * RunEmissionToolOffline.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2009 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 package tutorial.programming.example21tutorialTUBclass.events;
21 
22 import java.util.HashMap;
23 import java.util.Map;
24 
25 import org.matsim.api.core.v01.Id;
35 public class MyEventHandler implements ActivityEndEventHandler,
37 
38  private Map<Id<Person>,Double> startTimes = new HashMap<>();
39  private Id<Person> personWithHighestWorkDuration;
40  private double highestWorkDuration = 0;
41 
42  @Override
43  public void reset(int iteration) {
44 
45  }
46 
47  @Override
48  public void handleEvent(ActivityStartEvent event) {
49  if (event.getActType().equals("work")){
50  this.startTimes.put(event.getPersonId(), event.getTime());
51  }
52  }
53 
54  @Override
55  public void handleEvent(ActivityEndEvent event) {
56  if (event.getActType().equals("work")){
57  double workingTime = event.getTime() - this.startTimes.get(event.getPersonId());
58  if (workingTime> this.highestWorkDuration)
59  {
60  this.highestWorkDuration = workingTime;
61  this.personWithHighestWorkDuration = event.getPersonId();
62  }
63  }
64  }
65 
67  System.out.println(this.personWithHighestWorkDuration.toString() + ": "+this.highestWorkDuration);
68  }
69 
70 }