View Javadoc
1   package org.opentrafficsim.imb.kpi;
2   
3   import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
4   import org.opentrafficsim.kpi.interfaces.GtuTypeDataInterface;
5   import org.opentrafficsim.kpi.interfaces.NodeDataInterface;
6   import org.opentrafficsim.kpi.interfaces.RouteDataInterface;
7   
8   /**
9    * <p>
10   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 okt. 2016 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   */
18  public class GtuData implements GtuDataInterface
19  {
20      /** id. */
21      private final String id;
22  
23      /** gtu type. */
24      private final GtuTypeData gtuType;
25      
26      /** route. */
27      private final RouteData route;
28     
29      /**
30       * @param id the id
31       * @param gtuType the gtu type
32       * @param route the route
33       */
34      public GtuData(final String id, final GtuTypeData gtuType, final RouteData route)
35      {
36          this.id = id;
37          this.gtuType = gtuType;
38          this.route = route;
39      }
40  
41      /** {@inheritDoc} */
42      @Override
43      public final String getId()
44      {
45          return this.id;
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public final NodeDataInterface getOriginNodeData()
51      {
52          return this.route.getStartNode();
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public final NodeDataInterface getDestinationNodeData()
58      {
59          return this.route.getEndNode();
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public final GtuTypeDataInterface getGtuTypeData()
65      {
66          return this.gtuType;
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public final RouteDataInterface getRouteData()
72      {
73          return this.route;
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public int hashCode()
79      {
80          final int prime = 31;
81          int result = 1;
82          result = prime * result + ((this.gtuType == null) ? 0 : this.gtuType.hashCode());
83          result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
84          return result;
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public boolean equals(Object obj)
90      {
91          if (this == obj)
92              return true;
93          if (obj == null)
94              return false;
95          if (getClass() != obj.getClass())
96              return false;
97          GtuData other = (GtuData) obj;
98          if (this.gtuType == null)
99          {
100             if (other.gtuType != null)
101                 return false;
102         }
103         else if (!this.gtuType.equals(other.gtuType))
104             return false;
105         if (this.id == null)
106         {
107             if (other.id != null)
108                 return false;
109         }
110         else if (!this.id.equals(other.id))
111             return false;
112         return true;
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public String toString()
118     {
119         return "GtuData [id=" + this.id + ", gtuType=" + this.gtuType + ", route=" + this.route + "]";
120     }
121     
122 }