1 package org.opentrafficsim.kpi.sampling;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.opentrafficsim.kpi.interfaces.LaneDataInterface;
7
8 import nl.tudelft.simulation.language.Throw;
9
10
11
12
13
14
15
16
17
18
19
20 public class KpiLaneDirection implements Serializable
21 {
22
23 private static final long serialVersionUID = 20160330L;
24
25
26 private final LaneDataInterface lane;
27
28
29 private final KpiGtuDirectionality direction;
30
31
32
33
34
35 public KpiLaneDirection(final LaneDataInterface lane, final KpiGtuDirectionality direction)
36 {
37 Throw.whenNull(lane, "Lane may not be null.");
38 Throw.whenNull(direction, "Direction may not be null.");
39 this.lane = lane;
40 this.direction = direction;
41 }
42
43
44
45
46 public final LaneDataInterface getLaneData()
47 {
48 return this.lane;
49 }
50
51
52
53
54 public final KpiGtuDirectionality getKpiDirection()
55 {
56 return this.direction;
57 }
58
59
60
61
62
63
64
65 public final Length getPositionInDirection(Length position)
66 {
67 Throw.whenNull(position, "Position may not be null.");
68 return this.direction.equals(KpiGtuDirectionality.DIR_PLUS) ? position : this.lane.getLength().minus(position);
69 }
70
71
72 @Override
73 public String toString()
74 {
75 return "[" + this.lane + (this.direction.isPlus() ? " +]" : " -]");
76 }
77
78
79 @Override
80 public final int hashCode()
81 {
82 final int prime = 31;
83 int result = 1;
84 result = prime * result + ((this.direction == null) ? 0 : this.direction.hashCode());
85 result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
86 return result;
87 }
88
89
90 @Override
91 public final boolean equals(final Object obj)
92 {
93 if (this == obj)
94 {
95 return true;
96 }
97 if (obj == null)
98 {
99 return false;
100 }
101 if (getClass() != obj.getClass())
102 {
103 return false;
104 }
105 KpiLaneDirection other = (KpiLaneDirection) obj;
106 if (this.direction != other.direction)
107 {
108 return false;
109 }
110 if (this.lane == null)
111 {
112 if (other.lane != null)
113 {
114 return false;
115 }
116 }
117 else if (!this.lane.equals(other.lane))
118 {
119 return false;
120 }
121 return true;
122 }
123
124 }