[New] Added removing of future and past values on state variables
This commit is contained in:
parent
f1d94bb6f5
commit
a6483704c8
|
@ -37,12 +37,12 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
* @param value
|
* @param value
|
||||||
* the {@link IValue} to set
|
* the {@link IValue} to set
|
||||||
*/
|
*/
|
||||||
void setValueAt(final Long time, final T value);
|
void setValueAt(long time, final T value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the latest {@link ITimeValue} whose time field is less or equal to the time given
|
* get the latest {@link ITimeValue} whose time field is less or equal to the time given
|
||||||
*/
|
*/
|
||||||
ITimeValue<T> getValueAt(final Long time);
|
ITimeValue<T> getValueAt(long time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
|
* Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
|
||||||
|
@ -62,7 +62,17 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
*
|
*
|
||||||
* @return the sequence of {@link ITimeValue} objects in the future
|
* @return the sequence of {@link ITimeValue} objects in the future
|
||||||
*/
|
*/
|
||||||
Collection<ITimeValue<T>> getFutureValues(final Long time);
|
Collection<ITimeValue<T>> getFutureValues(long time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all {@link ITimeValue} objects whose time field is greater or equal to the given time
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
* the time the sequence starts with
|
||||||
|
*
|
||||||
|
* @return the sequence of {@link ITimeValue} objects removed
|
||||||
|
*/
|
||||||
|
Collection<ITimeValue<T>> removeFutureValues(long time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
|
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
|
||||||
|
@ -72,7 +82,17 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
*
|
*
|
||||||
* @return the sequence of {@link ITimeValue} objects in the future
|
* @return the sequence of {@link ITimeValue} objects in the future
|
||||||
*/
|
*/
|
||||||
Collection<ITimeValue<T>> getPastValues(final Long time);
|
Collection<ITimeValue<T>> getPastValues(long time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all {@link ITimeValue} objects whose time field is strictly smaller than the given time
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
* the time the sequence starts with
|
||||||
|
*
|
||||||
|
* @return the sequence of {@link ITimeValue} objects removed
|
||||||
|
*/
|
||||||
|
Collection<ITimeValue<T>> removePastValues(long time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all {@link ITimeValue} objects
|
* Get all {@link ITimeValue} objects
|
||||||
|
|
|
@ -26,7 +26,7 @@ import li.strolch.model.timevalue.IValue;
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable {
|
public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable {
|
||||||
|
|
||||||
protected final Long time;
|
protected final long time;
|
||||||
protected T value;
|
protected T value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,7 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
||||||
* @param value
|
* @param value
|
||||||
* the actual value for this value
|
* the actual value for this value
|
||||||
*/
|
*/
|
||||||
public TimeValue(final Long time, final T value) {
|
public TimeValue(final long time, final T value) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
|
result = prime * result + Long.hashCode(this.time);
|
||||||
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
|
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,7 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
TimeValue<T> other = (TimeValue<T>) obj;
|
TimeValue<T> other = (TimeValue<T>) obj;
|
||||||
if (this.time == null) {
|
if (this.time != other.time) {
|
||||||
if (other.time != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!this.time.equals(other.time)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.value == null) {
|
if (this.value == null) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
private boolean readonly;
|
private boolean readonly;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITimeValue<T> getValueAt(final Long time) {
|
public ITimeValue<T> getValueAt(long time) {
|
||||||
ITimeValue<T> tmp = null;
|
ITimeValue<T> tmp = null;
|
||||||
for (ITimeValue<T> value : this.container) {
|
for (ITimeValue<T> value : this.container) {
|
||||||
if (value.getTime() <= time) {
|
if (value.getTime() <= time) {
|
||||||
|
@ -50,7 +50,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueAt(final Long time, final T targetValue) {
|
public void setValueAt(long time, final T targetValue) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
ITimeValue<T> current = getValueAt(time);
|
ITimeValue<T> current = getValueAt(time);
|
||||||
if (current != null && current.getTime().equals(time)) {
|
if (current != null && current.getTime().equals(time)) {
|
||||||
|
@ -61,15 +61,31 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<ITimeValue<T>> getFutureValues(final Long time) {
|
public SortedSet<ITimeValue<T>> getFutureValues(long time) {
|
||||||
TimeValue<T> picker = new TimeValue<>(time, null);
|
return new TreeSet<>(this.container.tailSet(new TimeValue<>(time, null)));
|
||||||
return new TreeSet<>(this.container.tailSet(picker));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ITimeValue<T>> getPastValues(final Long time) {
|
public Collection<ITimeValue<T>> removeFutureValues(long time) {
|
||||||
TimeValue<T> picker = new TimeValue<>(time, null);
|
assertNotReadonly();
|
||||||
return new TreeSet<>(this.container.headSet(picker));
|
SortedSet<ITimeValue<T>> values = this.container.tailSet(new TimeValue<>(time, null));
|
||||||
|
TreeSet<ITimeValue<T>> result = new TreeSet<>(values);
|
||||||
|
values.clear();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ITimeValue<T>> getPastValues(long time) {
|
||||||
|
return new TreeSet<>(this.container.headSet(new TimeValue<>(time, null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ITimeValue<T>> removePastValues(long time) {
|
||||||
|
assertNotReadonly();
|
||||||
|
SortedSet<ITimeValue<T>> values = this.container.headSet(new TimeValue<>(time, null));
|
||||||
|
TreeSet<ITimeValue<T>> result = new TreeSet<>(values);
|
||||||
|
values.clear();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,6 +119,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void compact() {
|
public void compact() {
|
||||||
|
assertNotReadonly();
|
||||||
|
|
||||||
if (this.container.size() < 2) {
|
if (this.container.size() < 2) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue