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-19 17:38:20 +02:00
|
|
|
protected synchronized void merge() {
|
2017-07-15 12:29:51 +02:00
|
|
|
boolean needToCut = false;
|
|
|
|
long cutTime = 0;
|
|
|
|
|
2017-08-16 23:56:14 +02:00
|
|
|
for (int index = rawData.size()-1; index >= 0; index--) { //begin with newest
|
2017-07-15 12:29:51 +02:00
|
|
|
Interval cur = rawData.valueAt(index);
|
|
|
|
if (cur.isEndingEvent()){
|
|
|
|
needToCut = true;
|
|
|
|
cutTime = cur.start();
|
|
|
|
} else {
|
|
|
|
//event that is no EndingEvent might need to be stopped by an ending event
|
|
|
|
if(needToCut&&cur.end() > cutTime){
|
|
|
|
cur.cutEndTo(cutTime);
|
|
|
|
}
|
2017-05-10 14:00:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2017-07-19 17:38:20 +02:00
|
|
|
public synchronized T getValueByInterval(long time) {
|
2017-08-15 22:38:48 +02:00
|
|
|
for (int index = rawData.size()-1; index >= 0; index--) { //begin with newest
|
2017-07-15 12:29:51 +02:00
|
|
|
T cur = rawData.valueAt(index);
|
|
|
|
if (cur.match(time)){
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 14:00:46 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-15 11:19:27 +02:00
|
|
|
}
|