1 package org.opentrafficsim.road.gtu.lane;
2
3 import java.rmi.RemoteException;
4
5 import org.djutils.event.Event;
6 import org.djutils.event.EventListener;
7 import org.opentrafficsim.core.gtu.MoveCheckerException;
8 import org.opentrafficsim.core.network.Network;
9
10
11
12
13
14
15
16
17
18
19
20 public abstract class AbstractLaneBasedMoveChecker implements EventListener
21 {
22
23 private static final long serialVersionUID = 1L;
24
25
26 private final Network network;
27
28
29
30
31
32 public AbstractLaneBasedMoveChecker(final Network network)
33 {
34 network.addListener(this, Network.GTU_ADD_EVENT);
35 network.addListener(this, Network.GTU_REMOVE_EVENT);
36 this.network = network;
37 }
38
39
40 @Override
41 public void notify(final Event event) throws RemoteException
42 {
43 if (event.getType().equals(LaneBasedGtu.LANEBASED_MOVE_EVENT))
44 {
45 try
46 {
47 Object[] payload = (Object[]) event.getContent();
48 checkMove((LaneBasedGtu) this.network.getGTU((String) payload[0]));
49 }
50 catch (Exception ex)
51 {
52 throw new MoveCheckerException(ex);
53 }
54 }
55 else if (event.getType().equals(Network.GTU_ADD_EVENT))
56 {
57 this.network.getGTU((String) event.getContent()).addListener(this, LaneBasedGtu.LANEBASED_MOVE_EVENT);
58 }
59 else if (event.getType().equals(Network.GTU_REMOVE_EVENT))
60 {
61 this.network.getGTU((String) event.getContent()).removeListener(this, LaneBasedGtu.LANEBASED_MOVE_EVENT);
62 }
63 else
64 {
65 throw new RemoteException("AbstractMoveChecker is a listener to an unknown event type.");
66 }
67 }
68
69
70
71
72
73
74 public abstract void checkMove(LaneBasedGtu gtu) throws Exception;
75
76 }