[Fix] Fixed NPE in StrolchTimedState.trim()
This commit is contained in:
parent
0993fd22c5
commit
1ad10c8ced
|
@ -207,8 +207,12 @@ public interface StrolchTimedState<T extends IValue> extends StrolchElement {
|
||||||
ITimeVariable<T> timeEvolution = getTimeEvolution();
|
ITimeVariable<T> timeEvolution = getTimeEvolution();
|
||||||
|
|
||||||
long time = timeStamp.toInstant().toEpochMilli();
|
long time = timeStamp.toInstant().toEpochMilli();
|
||||||
if (keepLastValue && timeEvolution.getFutureValues(time).isEmpty())
|
if (keepLastValue && timeEvolution.getFutureValues(time).isEmpty()) {
|
||||||
time = timeEvolution.getValueAt(time).getTime();
|
ITimeValue<T> valueAt = timeEvolution.getValueAt(time);
|
||||||
|
if (valueAt == null)
|
||||||
|
return false;
|
||||||
|
time = valueAt.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
return !timeEvolution.removePastValues(time).isEmpty();
|
return !timeEvolution.removePastValues(time).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,14 @@ public class StrolchTimedStateTest {
|
||||||
assertEquals(2, floatState.getTimeEvolution().getValues().size());
|
assertEquals(2, floatState.getTimeEvolution().getValues().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTrimTimedState4() {
|
||||||
|
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(20);
|
||||||
|
FloatTimedState floatState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_ID);
|
||||||
|
assertFalse(floatState.trim(now, true));
|
||||||
|
assertFalse(floatState.trim(20));
|
||||||
|
}
|
||||||
|
|
||||||
private static Set<AString> asSet(String value) {
|
private static Set<AString> asSet(String value) {
|
||||||
HashSet<AString> hashSet = new HashSet<>();
|
HashSet<AString> hashSet = new HashSet<>();
|
||||||
hashSet.add(new AString(value));
|
hashSet.add(new AString(value));
|
||||||
|
|
Loading…
Reference in New Issue