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   import org.opentrafficsim.core.gtu.GtuType;
8   
9   /**
10   * Base class for perceived GTU's which stores the information.
11   * <p>
12   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public class PerceivedGtuBase extends PerceivedGtuSimple
20  {
21  
22      /** Behavior. */
23      private final Behavior behavior;
24  
25      /**
26       * Constructor.
27       * @param id GTU id
28       * @param gtuType GTU type
29       * @param length length of the GTU
30       * @param width width of the GTU
31       * @param kinematics kinematics
32       * @param signals signals
33       * @param maneuver maneuver
34       * @param behavior behavior
35       * @throws NullPointerException when any input argument is {@code null}
36       */
37      @SuppressWarnings("parameternumber")
38      public PerceivedGtuBase(final String id, final GtuType gtuType, final Length length, final Length width,
39              final Kinematics kinematics, final Signals signals, final Maneuver maneuver, final Behavior behavior)
40      {
41          super(id, gtuType, length, width, kinematics, signals, maneuver);
42          this.behavior = Throw.whenNull(behavior, "behavior");
43      }
44  
45      @Override
46      public Behavior getBehavior()
47      {
48          return this.behavior;
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public int hashCode()
54      {
55          final int prime = 31;
56          int result = super.hashCode();
57          result = prime * result + Objects.hash(this.behavior);
58          return result;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public boolean equals(final Object obj)
64      {
65          if (this == obj)
66          {
67              return true;
68          }
69          if (!super.equals(obj))
70          {
71              return false;
72          }
73          if (getClass() != obj.getClass())
74          {
75              return false;
76          }
77          PerceivedGtuBase other = (PerceivedGtuBase) obj;
78          return Objects.equals(this.behavior, other.behavior);
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public String toString()
84      {
85          return "PerceivedGtuBase [id=" + getId() + ", gtuType=" + getGtuType() + "]";
86      }
87  
88  }