1 package org.opentrafficsim.road.gtu.generator.headway;
2
3 import org.djunits.value.vdouble.scalar.Frequency;
4 import org.djunits.value.vdouble.scalar.Time;
5 import org.djunits.value.vdouble.vector.FrequencyVector;
6 import org.djunits.value.vdouble.vector.TimeVector;
7 import org.opentrafficsim.road.gtu.strategical.od.Interpolation;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class DemandPattern implements Arrivals
21 {
22
23
24 private final FrequencyVector demandVector;
25
26
27 private final TimeVector timeVector;
28
29
30 private final Interpolation interpolation;
31
32
33
34
35
36
37
38 public DemandPattern(final FrequencyVector demandVector, final TimeVector timeVector, final Interpolation interpolation)
39 {
40 this.demandVector = demandVector;
41 this.timeVector = timeVector;
42 this.interpolation = interpolation;
43 }
44
45
46
47
48
49 public final FrequencyVector getDemandVector()
50 {
51 return this.demandVector;
52 }
53
54
55
56
57
58 public final TimeVector getTimeVector()
59 {
60 return this.timeVector;
61 }
62
63
64
65
66
67 public final Interpolation getInterpolation()
68 {
69 return this.interpolation;
70 }
71
72
73 @Override
74 public Frequency getFrequency(final Time time, final boolean sliceStart)
75 {
76 return this.interpolation.interpolateVector(time, this.demandVector, this.timeVector, sliceStart);
77 }
78
79
80 @Override
81 public Time nextTimeSlice(final Time time)
82 {
83 for (Time d : this.timeVector)
84 {
85 if (d.gt(time))
86 {
87 return d;
88 }
89 }
90 return null;
91 }
92
93
94 @Override
95 public int hashCode()
96 {
97 final int prime = 31;
98 int result = 1;
99 result = prime * result + ((this.demandVector == null) ? 0 : this.demandVector.hashCode());
100 result = prime * result + ((this.interpolation == null) ? 0 : this.interpolation.hashCode());
101 result = prime * result + ((this.timeVector == null) ? 0 : this.timeVector.hashCode());
102 return result;
103 }
104
105
106 @Override
107 public boolean equals(final Object obj)
108 {
109 if (this == obj)
110 {
111 return true;
112 }
113 if (obj == null)
114 {
115 return false;
116 }
117 if (getClass() != obj.getClass())
118 {
119 return false;
120 }
121 DemandPattern other = (DemandPattern) obj;
122 if (this.demandVector == null)
123 {
124 if (other.demandVector != null)
125 {
126 return false;
127 }
128 }
129 else if (!this.demandVector.equals(other.demandVector))
130 {
131 return false;
132 }
133 if (this.interpolation != other.interpolation)
134 {
135 return false;
136 }
137 if (this.timeVector == null)
138 {
139 if (other.timeVector != null)
140 {
141 return false;
142 }
143 }
144 else if (!this.timeVector.equals(other.timeVector))
145 {
146 return false;
147 }
148 return true;
149 }
150
151
152 @Override
153 public String toString()
154 {
155 return "DemandPattern [demandVector=" + this.demandVector + ", timeVector=" + this.timeVector + ", interpolation="
156 + this.interpolation + "]";
157 }
158
159 }