1 package org.opentrafficsim.graphs;
2
3 import java.rmi.RemoteException;
4 import java.util.HashSet;
5 import java.util.List;
6 import java.util.Set;
7
8 import org.opentrafficsim.core.gtu.GTU;
9 import org.opentrafficsim.core.network.Network;
10 import org.opentrafficsim.core.network.OTSNetwork;
11 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12 import org.opentrafficsim.road.network.lane.Lane;
13
14 import nl.tudelft.simulation.event.EventInterface;
15 import nl.tudelft.simulation.event.EventListenerInterface;
16
17
18
19
20
21
22
23
24
25
26
27
28 public class DataSampler implements EventListenerInterface
29 {
30 private final List<Lane> lanes;
31
32 private final OTSNetwork network;
33
34 private final Set<String> gtus = new HashSet<>();
35
36
37
38
39
40
41 public DataSampler(final OTSNetwork network, final List<Lane> lanes)
42 {
43 this.lanes = lanes;
44 this.network = network;
45 network.addListener(this, Network.GTU_ADD_EVENT);
46 network.addListener(this, Network.GTU_REMOVE_EVENT);
47 }
48
49
50 @Override
51 public final void notify(final EventInterface event) throws RemoteException
52 {
53 if (event.getType().equals(Network.GTU_ADD_EVENT))
54 {
55 Object[] addInfo = (Object[]) event.getContent();
56 this.gtus.add(addInfo[0].toString());
57 GTU gtu = this.network.getGTU(addInfo[0].toString());
58 gtu.addListener(this, LaneBasedGTU.MOVE_EVENT);
59 }
60 else if (event.getType().equals(Network.GTU_REMOVE_EVENT))
61 {
62 Object[] removeInfo = (Object[]) event.getContent();
63 this.gtus.remove(removeInfo[0].toString());
64 GTU gtu = this.network.getGTU(removeInfo[0].toString());
65 gtu.removeListener(this, LaneBasedGTU.MOVE_EVENT);
66 }
67 else if (event.getType().equals(LaneBasedGTU.MOVE_EVENT))
68 {
69
70 }
71 }
72
73 }
74 ;