20 package org.matsim.core.network;
22 import java.util.Arrays;
23 import java.util.TreeMap;
27 import com.google.common.base.Preconditions;
29 final class VariableIntervalTimeVariantAttribute
30 implements TimeVariantAttribute
32 private int aEvents = 1;
33 private double[] aValues;
34 private double[] aTimes;
38 public boolean isRecalcRequired()
40 return (this.aTimes == null) || (this.aTimes.length != this.aEvents);
54 public void recalc(TreeMap<Double, NetworkChangeEvent> changeEvents,
55 ChangeValueGetter valueGetter,
double baseValue)
57 this.aTimes =
new double[this.aEvents];
58 this.aValues =
new double[this.aEvents];
59 this.aTimes[0] = Double.NEGATIVE_INFINITY;
60 this.aValues[0] = baseValue;
63 if (changeEvents != null) {
65 for (NetworkChangeEvent event : changeEvents.values()) {
66 ChangeValue value = valueGetter.getChangeValue(event);
68 switch( value.getType() ) {
69 case ABSOLUTE_IN_SI_UNITS:
71 this.aValues[++numEvent] = value.
getValue();
72 this.aTimes[numEvent] =
event.getStartTime();
76 double currentValue = this.aValues[numEvent];
77 this.aValues[++numEvent] = currentValue * value.getValue();
78 this.aTimes[numEvent] =
event.getStartTime();
80 case OFFSET_IN_SI_UNITS: {
81 double currentValue = this.aValues[numEvent];
82 this.aValues[++numEvent] = currentValue + value.getValue();
83 this.aTimes[numEvent] =
event.getStartTime();
92 if (numEvent != this.aEvents - 1) {
93 throw new RuntimeException(
"Expected number of change events (" + (this.aEvents - 1)
94 +
") differs from the number of events found (" + numEvent +
")!");
100 public double getValue(
final double time)
102 Preconditions.checkArgument(!Double.isNaN(time),
"NaN time is not supported");
104 int key = Arrays.binarySearch(this.aTimes, time);
105 key = key >= 0 ? key : -key - 2;
106 return this.aValues[key];
111 public void incChangeEvents()
118 public void clearEvents()