2017-06-02 12:27:21 +02:00
|
|
|
package info.nightscout.androidaps.data;
|
2017-05-10 14:00:46 +02:00
|
|
|
|
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2017-05-10 14:00:46 +02:00
|
|
|
|
2017-05-21 22:05:03 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.Interval;
|
|
|
|
|
2017-05-10 14:00:46 +02:00
|
|
|
/**
|
2017-07-15 11:19:27 +02:00
|
|
|
* Created by adrian on 15/07/17.
|
2017-05-10 14:00:46 +02:00
|
|
|
*/
|
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
public class OverlappingIntervals<T extends Interval> extends Intervals<T> {
|
2017-05-10 14:00:46 +02:00
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
protected void merge() {
|
2017-05-10 14:00:46 +02:00
|
|
|
for (int index = 0; index < rawData.size() - 1; index++) {
|
2017-05-22 20:58:05 +02:00
|
|
|
Interval i = rawData.valueAt(index);
|
|
|
|
long startOfNewer = rawData.valueAt(index + 1).start();
|
2017-05-10 14:00:46 +02:00
|
|
|
if (i.originalEnd() > startOfNewer) {
|
|
|
|
i.cutEndTo(startOfNewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2017-07-15 11:19:27 +02:00
|
|
|
public T getValueByInterval(long time) {
|
2017-05-10 14:00:46 +02:00
|
|
|
int index = binarySearch(time);
|
2017-05-22 20:58:05 +02:00
|
|
|
if (index >= 0) return rawData.valueAt(index);
|
2017-05-10 14:00:46 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
}
|