1 package org.matsim.counts;
3 import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap;
4 import it.unimi.dsi.fastutil.ints.Int2DoubleMap;
5 import it.unimi.dsi.fastutil.ints.Int2DoubleSortedMap;
7 import java.util.Iterator;
8 import java.util.Objects;
9 import java.util.OptionalDouble;
21 public static final String
ANY_MODE =
"any_vehicle";
22 static final String ELEMENT_NAME =
"measurements";
30 public static int DAILY = 24 * 60 * 60;
43 private final Int2DoubleSortedMap
values;
50 Measurable(String mode, String type,
int interval) {
53 this.values =
new Int2DoubleAVLTreeMap();
57 Int2DoubleMap getValues() {
78 throw new IllegalArgumentException(
"Time value starts at 0.");
80 if (seconds % this.interval != 0)
81 throw new IllegalArgumentException(
"Time value doesn't match the interval!");
83 this.values.put(seconds, value);
90 if (interval != DAILY)
91 throw new IllegalArgumentException(
"Does not contain daily values!");
97 if (interval != DAILY)
98 throw new IllegalArgumentException(
"Does not contain daily values!");
107 if (interval == DAILY)
108 return values.get(0);
110 return values.values().doubleStream().sum();
124 return (interval <= HOURLY) && (HOURLY %
interval) == 0;
132 throw new IllegalArgumentException(
"Can not aggregate hourly values.");
134 if (interval == HOURLY)
137 Int2DoubleSortedMap values = this.values.subMap(hour * HOURLY, (hour + 1) * HOURLY);
138 if (values.isEmpty())
139 return OptionalDouble.empty();
141 return OptionalDouble.of(values.values().doubleStream().sum());
145 if (values.containsKey(second))
146 return OptionalDouble.of(values.get(second));
148 return OptionalDouble.empty();
181 return values.int2DoubleEntrySet().iterator();
188 return values.size();
193 if (
this == o)
return true;
194 if (o == null || getClass() != o.getClass())
return false;
196 return interval == entries.
interval && Objects.equals(type, entries.
type) && Objects.equals(mode, entries.
mode) && Objects.equals(values, entries.
values);
201 return Objects.hash(type, mode, values, interval);
Iterator< Int2DoubleMap.Entry > iterator()
void setAtMinute(int minute, double value)
static final String ANY_MODE
static int QUARTER_HOURLY
OptionalDouble getAtSecond(int second)
String getMeasurableType()
OptionalDouble getDailyValue()
final Int2DoubleSortedMap values
void setAtSecond(int seconds, double value)
OptionalDouble getAtHour(int hour)
void setDailyValue(double value)
OptionalDouble getAtMinute(int minutes)
boolean supportsHourlyAggregate()
void setAtHour(int hour, double value)
OptionalDouble aggregateAtHour(int hour)