[New] Now StrolchTimedState compact only if boolean supplied

This commit is contained in:
Robert von Burg 2017-06-08 14:33:59 +02:00
parent ffbbe3c4bb
commit b8b0806e12
17 changed files with 47 additions and 41 deletions

View File

@ -178,48 +178,48 @@ public class ModelGenerator {
// float state
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)), true);
FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange), true);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange), true);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange), true);
resource.addTimedState(floatTimedState);
// integer state
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange), true);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange), true);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange), true);
resource.addTimedState(integerTimedState);
// boolean state
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new BooleanValue(STATE_BOOLEAN_TIME_0)));
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new BooleanValue(STATE_BOOLEAN_TIME_0)), true);
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange), true);
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange), true);
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange), true);
resource.addTimedState(booleanTimedState);
// string state
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change), true);
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_10));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change), true);
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_20));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change), true);
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_30));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change), true);
resource.addTimedState(stringTimedState);
}

View File

@ -17,6 +17,7 @@ package li.strolch.model.timedstate;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE;
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
import li.strolch.model.AbstractStrolchElement;
import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
@ -118,8 +119,8 @@ public abstract class AbstractStrolchTimedState<T extends IValue> extends Abstra
}
@Override
public <U extends IValueChange<T>> void applyChange(U change) {
this.state.applyChange(change);
public <U extends IValueChange<T>> void applyChange(U change, boolean compact) {
this.state.applyChange(change, compact);
}
@Override

View File

@ -45,7 +45,7 @@ public interface ITimedState<T extends IValue> {
* @param change
* the state change to be applied
*/
<U extends IValueChange<T>> void applyChange(final U change);
<U extends IValueChange<T>> void applyChange(final U change, boolean compact);
/**
* @return the state at the given time

View File

@ -104,7 +104,7 @@ public interface StrolchTimedState<T extends IValue> extends StrolchElement {
public ITimeValue<T> getPreviousMatch(Long time, T value);
public <U extends IValueChange<T>> void applyChange(U change);
public <U extends IValueChange<T>> void applyChange(U change, boolean compact);
public ITimeValue<T> getStateAt(Long time);

View File

@ -64,8 +64,8 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
}
@Override
public <U extends IValueChange<T>> void applyChange(U change) {
this.timeVariable.applyChange(change);
public <U extends IValueChange<T>> void applyChange(U change, boolean compact) {
this.timeVariable.applyChange(change, compact);
}
@Override

View File

@ -49,8 +49,10 @@ public interface ITimeVariable<T extends IValue> {
*
* @param change
* the {@link IValueChange} to be applied
* @param compact
* if set to true, then the values are compacted, otherwiss not
*/
void applyChange(final IValueChange<T> change);
void applyChange(final IValueChange<T> change, boolean compact);
/**
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time

View File

@ -77,7 +77,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
}
@Override
public void applyChange(final IValueChange<T> change) {
public void applyChange(final IValueChange<T> change, boolean compact) {
SortedSet<ITimeValue<T>> futureValues = getFutureValues(change.getTime());
for (ITimeValue<T> value : futureValues) {
@ -94,7 +94,8 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
this.container.add(newValue);
}
compact();
if (compact)
compact();
}
@SuppressWarnings("unchecked")

View File

@ -339,7 +339,7 @@ public class ModelTest {
Resource srcRes = createResource("@res01", "Test resource", "MyType");
Resource dstRes = createResource("@res01", "Test resource", "MyType");
BooleanTimedState timedState = dstRes.getTimedState(STATE_BOOLEAN_ID);
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.FALSE)));
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.FALSE)), true);
timedState.setName("Ohla");
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes);
List<Locator> mismatches = dstRes.accept(visitor);

View File

@ -43,7 +43,7 @@ public class TimeStateTest {
public void before() {
final IValueChange<FloatValue> change1 = new ValueChange<>(this.t10, this.expectedValue1);
this.state.applyChange(change1);
this.state.applyChange(change1, true);
final ITimeValue<FloatValue> stateAt9 = this.state.getStateAt(9L);
assertNull(stateAt9);
@ -53,7 +53,7 @@ public class TimeStateTest {
assertEquals(true, stateAt11.getValue().matches(this.expectedValue1));
final IValueChange<FloatValue> change2 = new ValueChange<>(this.t30, this.expectedValue1);
this.state.applyChange(change2);
this.state.applyChange(change2, true);
final ITimeValue<FloatValue> stateAt31 = this.state.getStateAt(31L);
assertNotNull(stateAt31);

View File

@ -100,7 +100,7 @@ public class FloatTimeVariableTest {
FloatValue doubleValue = new FloatValue(STEP.doubleValue());
IValueChange<FloatValue> change = new ValueChange<>(PICK, doubleValue);
this.timeVariable.applyChange(change);
this.timeVariable.applyChange(change, true);
Collection<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK;
@ -126,7 +126,7 @@ public class FloatTimeVariableTest {
FloatValue doubleValue = new FloatValue(STEP.doubleValue());
IValueChange<FloatValue> change = new ValueChange<>(PICK, doubleValue);
this.timeVariable.applyChange(change);
this.timeVariable.applyChange(change, true);
ITimeValue<FloatValue> actual = this.timeVariable.getValueAt(PICK);
assertNotNull(actual);

View File

@ -105,7 +105,7 @@ public class IntegerTimeVariableTest {
IntegerValue integerValue = new IntegerValue(STEP.intValue());
IValueChange<IntegerValue> change = new ValueChange<>(PICK, integerValue);
this.timeVariable.applyChange(change);
this.timeVariable.applyChange(change, false);
Collection<ITimeValue<IntegerValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK;

View File

@ -104,7 +104,7 @@ public class StringTimeVariableTest {
IValue<Set<AString>> inverseTestValue = testValue.getInverse();
IValueChange<IValue<Set<AString>>> change = new ValueChange<>(PICK, inverseTestValue);
this.timeVariable.applyChange(change);
this.timeVariable.applyChange(change, true);
// check the future values
Collection<ITimeValue<IValue<Set<AString>>>> futureValues = this.timeVariable.getFutureValues(0L);

View File

@ -64,7 +64,7 @@ public abstract class AbstractPlanCommand extends Command {
List<IValueChange<? extends IValue<?>>> changes = action.getChanges();
for (IValueChange<?> change : changes) {
StrolchTimedState timedState = resource.getTimedState(change.getStateId());
timedState.applyChange(change);
timedState.applyChange(change, true);
}
action.setState(State.PLANNED);
@ -98,7 +98,7 @@ public abstract class AbstractPlanCommand extends Command {
List<IValueChange<? extends IValue<?>>> changes = action.getChanges();
for (IValueChange<?> change : changes) {
StrolchTimedState timedState = resource.getTimedState(change.getStateId());
timedState.applyChange(change.getInverse());
timedState.applyChange(change.getInverse(), true);
}
action.setState(State.CREATED);

View File

@ -70,13 +70,15 @@ public class AssignActionTest {
this.initialResource = ModelGenerator.createResource("initial", "Test With States", "Stated");
this.initialTimedState = this.initialResource.getTimedState(STATE_INTEGER_ID);
this.initialTimedState.getTimeEvolution().clear();
this.initialTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.initialTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)),
true);
// add target resource with integer state variable
this.targetResource = ModelGenerator.createResource("target", "Test With States", "Stated");
this.targetTimedState = this.targetResource.getTimedState(STATE_INTEGER_ID);
this.targetTimedState.getTimeEvolution().clear();
this.targetTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.targetTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)),
true);
this.action = new Action("action", "Action", "Use");

View File

@ -65,7 +65,7 @@ public class PlanActionTest {
this.resource = ModelGenerator.createResource("@1", "Test With States", "Stated");
IntegerTimedState timedState = this.resource.getTimedState(STATE_INTEGER_ID);
timedState.getTimeEvolution().clear();
timedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
timedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
this.action = new Action("action", "Action", "Use");

View File

@ -82,19 +82,19 @@ public class PlanActivityTest {
this.resource1 = ModelGenerator.createResource("@1", "Test With States 1", "Stated");
this.timedState1 = resource1.getTimedState(STATE_INTEGER_ID);
this.timedState1.getTimeEvolution().clear();
this.timedState1.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.timedState1.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
// create resource with integer state
this.resource2 = ModelGenerator.createResource("@2", "Test With States 2", "Stated");
this.timedState2 = resource2.getTimedState(STATE_INTEGER_ID);
this.timedState2.getTimeEvolution().clear();
this.timedState2.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.timedState2.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
// create resource with integer state
this.resource3 = ModelGenerator.createResource("@3", "Test With States 3", "Stated");
this.timedState3 = resource3.getTimedState(STATE_INTEGER_ID);
this.timedState3.getTimeEvolution().clear();
this.timedState3.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.timedState3.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
// create activity element
this.activity = new Activity("activity", "Activity", "testType", TimeOrdering.SERIES);

View File

@ -69,7 +69,7 @@ public class ShiftActionTest {
this.resource = ModelGenerator.createResource("@1", "Test With States", "Stated");
this.timedState = this.resource.getTimedState(STATE_INTEGER_ID);
this.timedState.getTimeEvolution().clear();
this.timedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
this.timedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)), true);
this.action = new Action("action", "Action", "Use");