View Javadoc
1   package org.opentrafficsim.road.gtu.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   import org.opentrafficsim.road.gtu.LaneBasedGtu;
9   
10  /**
11   * Simple implementation of perceived GTU's which stores the information. This class does not support the behavioral component.
12   * <p>
13   * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author Alexander Verbraeck
17   * @author Peter Knoppers
18   * @author Wouter Schakel
19   */
20  public class PerceivedGtuSimple extends PerceivedObjectBase implements PerceivedGtu
21  {
22  
23      /** GTU type. */
24      private final GtuType gtuType;
25  
26      /** GTU width. */
27      private final Length width;
28  
29      /** Signals. */
30      private final Signals signals;
31  
32      /** Maneuver. */
33      private final Maneuver maneuver;
34  
35      /**
36       * Constructor.
37       * @param id GTU id
38       * @param gtuType GTU type
39       * @param length length of the GTU
40       * @param width width of the GTU
41       * @param kinematics kinematics
42       * @param signals signals
43       * @param maneuver maneuver
44       * @throws NullPointerException when any input argument is {@code null}
45       */
46      public PerceivedGtuSimple(final String id, final GtuType gtuType, final Length length, final Length width,
47              final Kinematics kinematics, final Signals signals, final Maneuver maneuver)
48      {
49          super(id, ObjectType.GTU, length, kinematics);
50          this.gtuType = Throw.whenNull(gtuType, "gtuType");
51          this.width = Throw.whenNull(width, "width");
52          this.signals = Throw.whenNull(signals, "signals");
53          this.maneuver = Throw.whenNull(maneuver, "maneuver");
54      }
55  
56      @Override
57      public Length getWidth()
58      {
59          return this.width;
60      }
61  
62      @Override
63      public GtuType getGtuType()
64      {
65          return this.gtuType;
66      }
67  
68      @Override
69      public Signals getSignals()
70      {
71          return this.signals;
72      }
73  
74      @Override
75      public Maneuver getManeuver()
76      {
77          return this.maneuver;
78      }
79  
80      @Override
81      public Behavior getBehavior()
82      {
83          throw new UnsupportedOperationException("HeadwayGtuSimple does not support behavior in HeadwyaGtu.");
84      }
85  
86      /**
87       * Returns perceived GTU with given kinematics, but without {@code Behavior}.
88       * @param gtu GTU that is perceived
89       * @param kinematics kinematics for the vehicle
90       * @return perceived view of the GTU
91       */
92      public static PerceivedGtuSimple of(final LaneBasedGtu gtu, final Kinematics kinematics)
93      {
94          return new PerceivedGtuSimple(gtu.getId(), gtu.getType(), gtu.getLength(), gtu.getWidth(), kinematics, Signals.of(gtu),
95                  Maneuver.of(gtu));
96      }
97  
98      @Override
99      public int hashCode()
100     {
101         final int prime = 31;
102         int result = super.hashCode();
103         result = prime * result + Objects.hash(this.gtuType, this.maneuver, this.signals, this.width);
104         return result;
105     }
106 
107     @Override
108     public boolean equals(final Object obj)
109     {
110         if (this == obj)
111         {
112             return true;
113         }
114         if (!super.equals(obj))
115         {
116             return false;
117         }
118         if (getClass() != obj.getClass())
119         {
120             return false;
121         }
122         PerceivedGtuSimple other = (PerceivedGtuSimple) obj;
123         return Objects.equals(this.gtuType, other.gtuType) && Objects.equals(this.maneuver, other.maneuver)
124                 && Objects.equals(this.signals, other.signals) && Objects.equals(this.width, other.width);
125     }
126 
127     @Override
128     public String toString()
129     {
130         return "PerceivedGtuSimple [id=" + getId() + ", gtuType=" + this.gtuType + "]";
131     }
132 
133 }