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