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-2016 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  
43      /** {@inheritDoc} */
44      @Override
45      public final String getId()
46      {
47          return this.gtu.getId();
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public final NodeDataInterface getOriginNodeData()
53      {
54          try
55          {
56              return new NodeData(this.gtu.getStrategicalPlanner().getRoute().originNode());
57          }
58          catch (NetworkException exception)
59          {
60              throw new RuntimeException("Could not get origin node.", exception);
61          }
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public final NodeDataInterface getDestinationNodeData()
67      {
68          try
69          {
70              return new NodeData(this.gtu.getStrategicalPlanner().getRoute().destinationNode());
71          }
72          catch (NetworkException exception)
73          {
74              throw new RuntimeException("Could not get destination node.", exception);
75          }
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public final GtuTypeDataInterface getGtuTypeData()
81      {
82          return new GtuTypeData(this.gtu.getGTUType());
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public final RouteDataInterface getRouteData()
88      {
89          return new RouteData(this.gtu.getStrategicalPlanner().getRoute());
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final  String toString()
95      {
96          return "GtuData [gtu=" + this.gtu + "]";
97      }
98      
99  }