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