View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.object;
2   
3   import java.util.Objects;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.opentrafficsim.road.network.lane.Lane;
7   
8   /**
9    * Lane based perceived object.
10   * <p>
11   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   */
18  public class PerceivedLaneBasedObjectBase extends PerceivedObjectBase implements PerceivedLaneBasedObject
19  {
20  
21      /** Lane. */
22      private final Lane lane;
23  
24      /**
25       * Constructor.
26       * @param id object id
27       * @param objectType object type
28       * @param length length of the object
29       * @param kinematics kinematics of the object
30       * @param lane lane
31       */
32      public PerceivedLaneBasedObjectBase(final String id, final ObjectType objectType, final Length length,
33              final Kinematics kinematics, final Lane lane)
34      {
35          super(id, objectType, length, kinematics);
36          this.lane = lane;
37      }
38  
39      /**
40       * Lane at which the object is located.
41       * @return lane at which the object is located
42       */
43      @Override
44      public Lane getLane()
45      {
46          return this.lane;
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public int hashCode()
52      {
53          final int prime = 31;
54          int result = super.hashCode();
55          result = prime * result + Objects.hash(this.lane);
56          return result;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public boolean equals(final Object obj)
62      {
63          if (this == obj)
64          {
65              return true;
66          }
67          if (!super.equals(obj))
68          {
69              return false;
70          }
71          if (getClass() != obj.getClass())
72          {
73              return false;
74          }
75          PerceivedLaneBasedObjectBase other = (PerceivedLaneBasedObjectBase) obj;
76          return Objects.equals(this.lane, other.lane);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public String toString()
82      {
83          return "PerceivedLaneBasedObject [id=" + getId() + ", type=" + getObjectType() + "]";
84      }
85  
86  }