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 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
9
10
11
12
13
14
15
16
17
18
19
20 public class PerceivedGtuSimple extends PerceivedObjectBase implements PerceivedGtu
21 {
22
23
24 private final GtuType gtuType;
25
26
27 private final Length width;
28
29
30 private final Signals signals;
31
32
33 private final Maneuver maneuver;
34
35
36
37
38
39
40
41
42
43
44
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
88
89
90
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
99 @Override
100 public int hashCode()
101 {
102 final int prime = 31;
103 int result = super.hashCode();
104 result = prime * result + Objects.hash(this.gtuType, this.maneuver, this.signals, this.width);
105 return result;
106 }
107
108
109 @Override
110 public boolean equals(final Object obj)
111 {
112 if (this == obj)
113 {
114 return true;
115 }
116 if (!super.equals(obj))
117 {
118 return false;
119 }
120 if (getClass() != obj.getClass())
121 {
122 return false;
123 }
124 PerceivedGtuSimple other = (PerceivedGtuSimple) obj;
125 return Objects.equals(this.gtuType, other.gtuType) && Objects.equals(this.maneuver, other.maneuver)
126 && Objects.equals(this.signals, other.signals) && Objects.equals(this.width, other.width);
127 }
128
129
130 @Override
131 public String toString()
132 {
133 return "PerceivedGtuSimple [id=" + getId() + ", gtuType=" + this.gtuType + "]";
134 }
135
136 }