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.djutils.exceptions.Throw;
7   
8   /**
9    * Base class for perceived objects which stores the information.
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 PerceivedObjectBase implements PerceivedObject
19  {
20  
21      /** Object id. */
22      private final String id;
23  
24      /** Object type. */
25      private final ObjectType objectType;
26  
27      /** Length of the object. */
28      private final Length length;
29  
30      /** Kinematics of the object. */
31      private final Kinematics kinematics;
32  
33      /**
34       * Constructor.
35       * @param id object id
36       * @param objectType object type
37       * @param length length of the object
38       * @param kinematics kinematics of the object
39       * @throws NullPointerException when any input argument is {@code null}
40       */
41      public PerceivedObjectBase(final String id, final ObjectType objectType, final Length length, final Kinematics kinematics)
42      {
43          this.id = Throw.whenNull(id, "id");
44          this.objectType = Throw.whenNull(objectType, "objectType");
45          this.length = Throw.whenNull(length, "length");
46          this.kinematics = Throw.whenNull(kinematics, "kinematics");
47      }
48  
49      @Override
50      public String getId()
51      {
52          return this.id;
53      }
54  
55      @Override
56      public ObjectType getObjectType()
57      {
58          return this.objectType;
59      }
60  
61      @Override
62      public Length getLength()
63      {
64          return this.length;
65      }
66  
67      @Override
68      public Kinematics getKinematics()
69      {
70          return this.kinematics;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public int hashCode()
76      {
77          return Objects.hash(this.id, this.kinematics, this.length, this.objectType);
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public boolean equals(final Object obj)
83      {
84          if (this == obj)
85          {
86              return true;
87          }
88          if (obj == null)
89          {
90              return false;
91          }
92          if (getClass() != obj.getClass())
93          {
94              return false;
95          }
96          PerceivedObjectBase other = (PerceivedObjectBase) obj;
97          return Objects.equals(this.id, other.id) && Objects.equals(this.kinematics, other.kinematics)
98                  && Objects.equals(this.length, other.length) && this.objectType == other.objectType;
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public String toString()
104     {
105         return "PerceivedObjectBase [id=" + this.id + ", objectType=" + this.objectType + "]";
106     }
107 
108 }