2017-07-15 11:19:27 +02:00
|
|
|
package info.nightscout.androidaps.data;
|
|
|
|
|
|
|
|
|
2019-05-16 13:57:37 +02:00
|
|
|
import androidx.annotation.Nullable;
|
2017-07-15 11:19:27 +02:00
|
|
|
|
|
|
|
import info.nightscout.androidaps.interfaces.Interval;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by adrian on 15/07/17.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class NonOverlappingIntervals<T extends Interval> extends Intervals<T> {
|
|
|
|
|
2018-03-25 17:33:03 +02:00
|
|
|
public NonOverlappingIntervals() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public NonOverlappingIntervals (Intervals<T> other) {
|
|
|
|
rawData = other.rawData.clone();
|
|
|
|
}
|
|
|
|
|
2019-06-09 15:17:16 +02:00
|
|
|
public synchronized void merge() {
|
2017-07-15 11:19:27 +02:00
|
|
|
for (int index = 0; index < rawData.size() - 1; index++) {
|
|
|
|
Interval i = rawData.valueAt(index);
|
|
|
|
long startOfNewer = rawData.valueAt(index + 1).start();
|
|
|
|
if (i.originalEnd() > startOfNewer) {
|
|
|
|
i.cutEndTo(startOfNewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2017-07-19 17:38:20 +02:00
|
|
|
public synchronized T getValueByInterval(long time) {
|
2017-07-15 11:19:27 +02:00
|
|
|
int index = binarySearch(time);
|
|
|
|
if (index >= 0) return rawData.valueAt(index);
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-25 17:33:03 +02:00
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
}
|