View Javadoc
1   package org.opentrafficsim.road.network.sampling;
2   
3   import org.opentrafficsim.core.network.NetworkException;
4   import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
5   import org.opentrafficsim.kpi.interfaces.GtuTypeDataInterface;
6   import org.opentrafficsim.kpi.interfaces.NodeDataInterface;
7   import org.opentrafficsim.kpi.interfaces.RouteDataInterface;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   
10  /**
11   * <p>
12   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 okt. 2016 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
19   */
20  public class GtuData implements GtuDataInterface
21  {
22  
23      /** Gtu. */
24      private final LaneBasedGTU gtu;
25  
26      /**
27       * @param gtu gtu
28       */
29      public GtuData(final LaneBasedGTU gtu)
30      {
31          this.gtu = gtu;
32      }
33  
34      /**
35       * @return gtu.
36       */
37      public final LaneBasedGTU getGtu()
38      {
39          return this.gtu;
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      public final String getId()
45      {
46          return this.gtu.getId();
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public final NodeDataInterface getOriginNodeData()
52      {
53          try
54          {
55              return new NodeData(this.gtu.getStrategicalPlanner().getRoute().originNode());
56          }
57          catch (NetworkException exception)
58          {
59              throw new RuntimeException("Could not get origin node.", exception);
60          }
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public final NodeDataInterface getDestinationNodeData()
66      {
67          try
68          {
69              return new NodeData(this.gtu.getStrategicalPlanner().getRoute().destinationNode());
70          }
71          catch (NetworkException exception)
72          {
73              throw new RuntimeException("Could not get destination node.", exception);
74          }
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final GtuTypeDataInterface getGtuTypeData()
80      {
81          return new GtuTypeData(this.gtu.getGTUType());
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final RouteDataInterface getRouteData()
87      {
88          return new RouteData(this.gtu.getStrategicalPlanner().getRoute());
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public final String toString()
94      {
95          return "GtuData [gtu=" + this.gtu + "]";
96      }
97  
98  }