AndroidAPS/app/src/main/java/info/nightscout/androidaps/data/OverlappingIntervals.java

32 lines
785 B
Java
Raw Normal View History

2017-06-02 12:27:21 +02:00
package info.nightscout.androidaps.data;
2017-05-10 14:00:46 +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
/**
* Created by adrian on 15/07/17.
2017-05-10 14:00:46 +02:00
*/
public class OverlappingIntervals<T extends Interval> extends Intervals<T> {
2017-05-10 14:00:46 +02:00
protected void merge() {
2017-05-10 14:00:46 +02:00
for (int index = 0; index < rawData.size() - 1; index++) {
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
public T getValueByInterval(long time) {
2017-05-10 14:00:46 +02:00
int index = binarySearch(time);
if (index >= 0) return rawData.valueAt(index);
2017-05-10 14:00:46 +02:00
return null;
}
}