View Javadoc
1   package org.opentrafficsim.road.network.sampling;
2   
3   import org.opentrafficsim.core.network.NetworkException;
4   import org.opentrafficsim.kpi.interfaces.GtuData;
5   import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
6   
7   /**
8    * Gtu representation in road sampler.
9    * <p>
10   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * </p>
13   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
14   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
15   * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
16   */
17  public class GtuDataRoad implements GtuData
18  {
19  
20      /** Gtu. */
21      private final LaneBasedGtu gtu;
22  
23      /**
24       * @param gtu LaneBasedGtu; gtu
25       */
26      public GtuDataRoad(final LaneBasedGtu gtu)
27      {
28          this.gtu = gtu;
29      }
30  
31      /**
32       * @return gtu.
33       */
34      public final LaneBasedGtu getGtu()
35      {
36          return this.gtu;
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      public final String getId()
42      {
43          return this.gtu.getId();
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public final String getOriginId()
49      {
50          try
51          {
52              return this.gtu.getStrategicalPlanner().getRoute().originNode().getId();
53          }
54          catch (NetworkException exception)
55          {
56              throw new RuntimeException("Could not get origin node.", exception);
57          }
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public final String getDestinationId()
63      {
64          try
65          {
66              return this.gtu.getStrategicalPlanner().getRoute().destinationNode().getId();
67          }
68          catch (NetworkException exception)
69          {
70              throw new RuntimeException("Could not get destination node.", exception);
71          }
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final String getGtuId()
77      {
78          return this.gtu.getType().getId();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final String getRouteId()
84      {
85          return this.gtu.getStrategicalPlanner().getRoute().getId();
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public final String toString()
91      {
92          return "GtuData [gtu=" + this.gtu + "]";
93      }
94  
95  }