[Fix] Simplified TimeVariable.getValueAt() and removed value from TimeValue.compareTo()

This commit is contained in:
Robert von Burg 2022-07-26 15:16:47 +02:00
parent 07767c9c70
commit 271b0577f3
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 7 additions and 21 deletions

View File

@ -67,16 +67,7 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public int compareTo(final ITimeValue<T> arg0) { public int compareTo(final ITimeValue<T> arg0) {
int i = getTime().compareTo(arg0.getTime()); return getTime().compareTo(arg0.getTime());
if (i != 0)
return i;
if (this.value == null && arg0.getValue() == null)
return 0;
if (this.value == null)
return -1;
if (arg0.getValue() == null)
return 1;
return getValue().compareTo(arg0.getValue());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -15,10 +15,13 @@
*/ */
package li.strolch.model.timevalue.impl; package li.strolch.model.timevalue.impl;
import static java.util.Collections.*; import static java.util.Collections.unmodifiableNavigableSet;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.Iterator;
import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Stream; import java.util.stream.Stream;
import li.strolch.exception.StrolchModelException; import li.strolch.exception.StrolchModelException;
@ -38,15 +41,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
@Override @Override
public ITimeValue<T> getValueAt(long time) { public ITimeValue<T> getValueAt(long time) {
ITimeValue<T> tmp = null; return this.container.floor(new TimeValue<>(time, null));
for (ITimeValue<T> value : this.container) {
if (value.getTime() <= time) {
tmp = value;
} else {
break;
}
}
return tmp;
} }
@Override @Override