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

31 lines
813 B
Java
Raw Normal View History

package info.nightscout.androidaps.data;
import android.support.annotation.Nullable;
import info.nightscout.androidaps.interfaces.Interval;
/**
* Created by adrian on 15/07/17.
*/
public class NonOverlappingIntervals<T extends Interval> extends Intervals<T> {
2017-07-19 17:38:20 +02:00
protected synchronized void merge() {
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) {
int index = binarySearch(time);
if (index >= 0) return rawData.valueAt(index);
return null;
}
}