[New] TimedStates are now properly incorporated into the Strolch Model
The TimedStates have been added to Resources and can be added, removed and retrieved using the following methods: - addTimedState(StrolchTimedState):void - removeTimedState(String):<T extends StrolchTimedState> - getTimedState(String):<T extends StrolchTimedState> - getTimedStates():List<StrolchTimedState<?>> - hasTimedState(String):boolean Also created a new Boolean StateVariables type The TimedStates are added to Resources using the StrolchTimedState interface and there is a concrete implementation for each type: - BooleanTimedState - IntegerTimedState - FloatTimedState - StringSetTimedState Each timed state is tested in a unit test Each timed state is (de)serializable from/to XML
This commit is contained in:
parent
0dae330e72
commit
7ca7bc7ca7
|
@ -15,10 +15,13 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Set;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
import li.strolch.model.parameter.DateParameter;
|
||||
import li.strolch.model.parameter.FloatParameter;
|
||||
|
@ -27,7 +30,17 @@ import li.strolch.model.parameter.LongParameter;
|
|||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
import li.strolch.model.timedstate.BooleanTimedState;
|
||||
import li.strolch.model.timedstate.FloatTimedState;
|
||||
import li.strolch.model.timedstate.IntegerTimedState;
|
||||
import li.strolch.model.timedstate.StringSetTimedState;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
|
||||
/**
|
||||
* Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then
|
||||
|
@ -59,6 +72,43 @@ public class ModelGenerator {
|
|||
public static final String PARAM_LIST_STRING_ID = "@param7";
|
||||
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
|
||||
|
||||
public static final String STATE_FLOAT_ID = "@state1";
|
||||
public static final String STATE_FLOAT_NAME = "Float State";
|
||||
|
||||
public static final String STATE_INTEGER_ID = "@state2";
|
||||
public static final String STATE_INTEGER_NAME = "Float State";
|
||||
|
||||
public static final String STATE_STRING_ID = "@state3";
|
||||
public static final String STATE_STRING_NAME = "Float State";
|
||||
|
||||
public static final String STATE_BOOLEAN_ID = "@state4";
|
||||
public static final String STATE_BOOLEAN_NAME = "Float State";
|
||||
|
||||
public static final long STATE_TIME_0 = 0L;
|
||||
public static final long STATE_TIME_10 = 10L;
|
||||
public static final long STATE_TIME_20 = 20L;
|
||||
public static final long STATE_TIME_30 = 30L;
|
||||
|
||||
public static final Double STATE_FLOAT_TIME_0 = 0.0D;
|
||||
public static final Double STATE_FLOAT_TIME_10 = 10.0D;
|
||||
public static final Double STATE_FLOAT_TIME_20 = 20.0D;
|
||||
public static final Double STATE_FLOAT_TIME_30 = 30.0D;
|
||||
|
||||
public static final Integer STATE_INTEGER_TIME_0 = 0;
|
||||
public static final Integer STATE_INTEGER_TIME_10 = 10;
|
||||
public static final Integer STATE_INTEGER_TIME_20 = 20;
|
||||
public static final Integer STATE_INTEGER_TIME_30 = 30;
|
||||
|
||||
public static final String STATE_STRING_TIME_0 = "empty";
|
||||
public static final String STATE_STRING_TIME_10 = "a";
|
||||
public static final String STATE_STRING_TIME_20 = "b";
|
||||
public static final String STATE_STRING_TIME_30 = "c";
|
||||
|
||||
public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE;
|
||||
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE;
|
||||
public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE;
|
||||
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
|
||||
|
||||
public static final String BAG_ID = "@bag01";
|
||||
public static final String BAG_NAME = "Test Bag";
|
||||
public static final String BAG_TYPE = "TestBag";
|
||||
|
@ -67,12 +117,9 @@ public class ModelGenerator {
|
|||
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
|
||||
* {@link #createParameterBag(String, String, String)}
|
||||
*
|
||||
* @param id
|
||||
* the id of the {@link Resource}
|
||||
* @param name
|
||||
* the name of the {@link Resource}
|
||||
* @param type
|
||||
* the type of the {@link Resource}
|
||||
* @param id the id of the {@link Resource}
|
||||
* @param name the name of the {@link Resource}
|
||||
* @param type the type of the {@link Resource}
|
||||
*
|
||||
* @return the newly created {@link Resource}
|
||||
*/
|
||||
|
@ -80,24 +127,91 @@ public class ModelGenerator {
|
|||
Resource resource = new Resource(id, name, type);
|
||||
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
||||
resource.addParameterBag(bag);
|
||||
addTimedStates(resource);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link StrolchTimedState} instances and adds them to the {@link Resource}
|
||||
*
|
||||
* @param resource the resource to which to addd the newly created {@link StrolchTimedState}
|
||||
*/
|
||||
public static void addTimedStates(Resource resource) {
|
||||
|
||||
// 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)));
|
||||
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));
|
||||
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)));
|
||||
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));
|
||||
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)));
|
||||
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
|
||||
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
|
||||
booleanValueChange = booleanValueChange.getInverse();
|
||||
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
|
||||
booleanValueChange = booleanValueChange.getInverse();
|
||||
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
|
||||
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));
|
||||
change = change.getInverse();
|
||||
change.add(asSet(STATE_STRING_TIME_10));
|
||||
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
|
||||
removeInverted(change.getValue());
|
||||
change = change.getInverse();
|
||||
change.add(asSet(STATE_STRING_TIME_20));
|
||||
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
|
||||
removeInverted(change.getValue());
|
||||
change = change.getInverse();
|
||||
change.add(asSet(STATE_STRING_TIME_30));
|
||||
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
|
||||
resource.addTimedState(stringTimedState);
|
||||
}
|
||||
|
||||
private static Set<AString> asSet(String value) {
|
||||
HashSet<AString> hashSet = new HashSet<>();
|
||||
hashSet.add(new AString(value));
|
||||
return hashSet;
|
||||
}
|
||||
|
||||
private static void removeInverted(Set<AString> set) {
|
||||
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
|
||||
AString aString = iter.next();
|
||||
if (aString.isInverse()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling
|
||||
* {@link #createParameterBag(String, String, String)}
|
||||
*
|
||||
* @param idStart
|
||||
* id range start
|
||||
* @param count
|
||||
* the number of elements to create
|
||||
* @param idPrefix
|
||||
* the prefix to generate IDs for the {@link Resource Resources}
|
||||
* @param name
|
||||
* the name of the {@link Resource}
|
||||
* @param type
|
||||
* the type of the {@link Resource}
|
||||
* @param idStart id range start
|
||||
* @param count the number of elements to create
|
||||
* @param idPrefix the prefix to generate IDs for the {@link Resource Resources}
|
||||
* @param name the name of the {@link Resource}
|
||||
* @param type the type of the {@link Resource}
|
||||
*
|
||||
* @return the list of newly created {@link Resource Resources}
|
||||
*/
|
||||
|
@ -114,12 +228,9 @@ public class ModelGenerator {
|
|||
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
|
||||
* {@link #createParameterBag(String, String, String)}
|
||||
*
|
||||
* @param id
|
||||
* the id of the {@link Order}
|
||||
* @param name
|
||||
* the name of the {@link Order}
|
||||
* @param type
|
||||
* the type of the {@link Order}
|
||||
* @param id the id of the {@link Order}
|
||||
* @param name the name of the {@link Order}
|
||||
* @param type the type of the {@link Order}
|
||||
*
|
||||
* @return the newly created {@link Order}
|
||||
*/
|
||||
|
@ -131,16 +242,11 @@ public class ModelGenerator {
|
|||
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
|
||||
* {@link #createParameterBag(String, String, String)}
|
||||
*
|
||||
* @param id
|
||||
* the id of the {@link Order}
|
||||
* @param name
|
||||
* the name of the {@link Order}
|
||||
* @param type
|
||||
* the type of the {@link Order}
|
||||
* @param date
|
||||
* the date of the {@link Order}
|
||||
* @param state
|
||||
* the {@link State} of the {@link Order}
|
||||
* @param id the id of the {@link Order}
|
||||
* @param name the name of the {@link Order}
|
||||
* @param type the type of the {@link Order}
|
||||
* @param date the date of the {@link Order}
|
||||
* @param state the {@link State} of the {@link Order}
|
||||
*
|
||||
* @return the newly created {@link Order}
|
||||
*/
|
||||
|
@ -157,16 +263,11 @@ public class ModelGenerator {
|
|||
* Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling
|
||||
* {@link #createParameterBag(String, String, String)}
|
||||
*
|
||||
* @param idStart
|
||||
* id range start
|
||||
* @param count
|
||||
* the number of elements to create
|
||||
* @param idPrefix
|
||||
* the prefix to generate IDs for the {@link Order Orders}
|
||||
* @param name
|
||||
* the name of the {@link Order}
|
||||
* @param type
|
||||
* the type of the {@link Order}
|
||||
* @param idStart id range start
|
||||
* @param count the number of elements to create
|
||||
* @param idPrefix the prefix to generate IDs for the {@link Order Orders}
|
||||
* @param name the name of the {@link Order}
|
||||
* @param type the type of the {@link Order}
|
||||
*
|
||||
* @return the list of newly created {@link Order Orders}
|
||||
*/
|
||||
|
@ -183,12 +284,9 @@ public class ModelGenerator {
|
|||
* Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add
|
||||
* {@link Parameter}s
|
||||
*
|
||||
* @param id
|
||||
* the id of the {@link ParameterBag}
|
||||
* @param name
|
||||
* the name of the {@link ParameterBag}
|
||||
* @param type
|
||||
* the type of the {@link ParameterBag}
|
||||
* @param id the id of the {@link ParameterBag}
|
||||
* @param name the name of the {@link ParameterBag}
|
||||
* @param type the type of the {@link ParameterBag}
|
||||
*
|
||||
* @return the newly created {@link ParameterBag}
|
||||
*/
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import ch.eitchnet.utils.dbc.DBC;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -79,8 +80,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
/**
|
||||
* Sets the type of this {@link ParameterizedElement}
|
||||
*
|
||||
* @param type
|
||||
* the type to set
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(String type) {
|
||||
if (StringHelper.isEmpty(type)) {
|
||||
|
@ -95,27 +95,27 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
/**
|
||||
* Returns the {@link Parameter} with the given id, or null if it does not exist
|
||||
*
|
||||
* @param key
|
||||
* the id of the parameter to return
|
||||
* @param key the id of the parameter to return
|
||||
*
|
||||
* @return the {@link Parameter} with the given id, or null if it does not exist
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getParameter(String key) {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
return null;
|
||||
}
|
||||
return (T) this.parameterMap.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
|
||||
*
|
||||
* @param parameter
|
||||
* the {@link Parameter} to add
|
||||
* @param parameter the {@link Parameter} to add
|
||||
*/
|
||||
public void addParameter(Parameter<?> parameter) {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
this.parameterMap = new HashMap<String, Parameter<?>>();
|
||||
}
|
||||
this.parameterMap.put(parameter.getId(), parameter);
|
||||
parameter.setParent(this);
|
||||
}
|
||||
|
@ -123,15 +123,15 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
/**
|
||||
* Removes the {@link Parameter} with the given key
|
||||
*
|
||||
* @param key
|
||||
* the key of the {@link Parameter} to remove
|
||||
* @param key the key of the {@link Parameter} to remove
|
||||
*
|
||||
* @return the removed {@link Parameter}, or null if it does not exist
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Parameter<T> removeParameter(String key) {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
return null;
|
||||
}
|
||||
return (Parameter<T>) this.parameterMap.remove(key);
|
||||
}
|
||||
|
||||
|
@ -141,8 +141,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
* @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
|
||||
*/
|
||||
public List<Parameter<?>> getParameters() {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ArrayList<Parameter<?>>(this.parameterMap.values());
|
||||
}
|
||||
|
||||
|
@ -158,14 +159,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
/**
|
||||
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
|
||||
*
|
||||
* @param key
|
||||
* the key of the {@link Parameter} to check for
|
||||
* @param key the key of the {@link Parameter} to check for
|
||||
*
|
||||
* @return true, if the {@link Parameter} exists with the given key, false otherwise
|
||||
*/
|
||||
public boolean hasParameter(String key) {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
return false;
|
||||
}
|
||||
return this.parameterMap.containsKey(key);
|
||||
}
|
||||
|
||||
|
@ -175,8 +176,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
* @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
|
||||
*/
|
||||
public Set<String> getParameterKeySet() {
|
||||
if (this.parameterMap == null)
|
||||
if (this.parameterMap == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return new HashSet<String>(this.parameterMap.keySet());
|
||||
}
|
||||
|
||||
|
@ -206,6 +208,8 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
Element paramElement = (Element) parameterElements.item(i);
|
||||
String paramtype = paramElement.getAttribute(Tags.TYPE);
|
||||
|
||||
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype);
|
||||
|
||||
if (paramtype.equals(StringParameter.TYPE)) {
|
||||
StringParameter param = new StringParameter(paramElement);
|
||||
addParameter(param);
|
||||
|
@ -266,8 +270,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
/**
|
||||
* Set the parent for this {@link ParameterizedElement}
|
||||
*
|
||||
* @param parent
|
||||
* the parent to set
|
||||
* @param parent the parent to set
|
||||
*/
|
||||
public void setParent(GroupedParameterizedElement parent) {
|
||||
this.parent = parent;
|
||||
|
|
|
@ -15,11 +15,26 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import ch.eitchnet.utils.dbc.DBC;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import li.strolch.model.timedstate.BooleanTimedState;
|
||||
import li.strolch.model.timedstate.FloatTimedState;
|
||||
import li.strolch.model.timedstate.IntegerTimedState;
|
||||
import li.strolch.model.timedstate.StringSetTimedState;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -28,6 +43,8 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
|||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private Map<String, StrolchTimedState<?>> timedStateMap;
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
|
@ -53,6 +70,79 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
|||
*/
|
||||
public Resource(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
|
||||
for (int i = 0; i < timedStateElems.getLength(); i++) {
|
||||
Element timedStateElem = (Element) timedStateElems.item(i);
|
||||
String typeS = timedStateElem.getAttribute(Tags.TYPE);
|
||||
|
||||
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS);
|
||||
|
||||
if (typeS.equals(FloatTimedState.TYPE)) {
|
||||
StrolchTimedState timedState = new FloatTimedState(timedStateElem);
|
||||
addTimedState(timedState);
|
||||
} else if (typeS.equals(IntegerTimedState.TYPE)) {
|
||||
StrolchTimedState timedState = new IntegerTimedState(timedStateElem);
|
||||
addTimedState(timedState);
|
||||
} else if (typeS.equals(BooleanTimedState.TYPE)) {
|
||||
StrolchTimedState timedState = new BooleanTimedState(timedStateElem);
|
||||
addTimedState(timedState);
|
||||
} else if (typeS.equals(StringSetTimedState.TYPE)) {
|
||||
StrolchTimedState timedState = new StringSetTimedState(timedStateElem);
|
||||
addTimedState(timedState);
|
||||
} else {
|
||||
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, typeS);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
|
||||
if (this.timedStateMap == null) {
|
||||
this.timedStateMap = new HashMap<>();
|
||||
}
|
||||
|
||||
this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState);
|
||||
strolchTimedState.setParent(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public <T extends StrolchTimedState> T getTimedState(String id) {
|
||||
if (this.timedStateMap == null) {
|
||||
return null;
|
||||
}
|
||||
return (T) this.timedStateMap.get(id);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public <T extends StrolchTimedState> T removeTimedState(String id) {
|
||||
if (this.timedStateMap == null) {
|
||||
return null;
|
||||
}
|
||||
return (T) this.timedStateMap.remove(id);
|
||||
}
|
||||
|
||||
public Set<String> getTimedStateKeySet() {
|
||||
if (this.timedStateMap == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return new HashSet<>(this.timedStateMap.keySet());
|
||||
}
|
||||
|
||||
public List<StrolchTimedState<?>> getTimedStates() {
|
||||
if (this.timedStateMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ArrayList<>(this.timedStateMap.values());
|
||||
}
|
||||
|
||||
public boolean hasTimedStates() {
|
||||
return this.timedStateMap != null && !this.timedStateMap.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasTimedState(String id) {
|
||||
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,6 +151,13 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
|||
Element element = doc.createElement(Tags.RESOURCE);
|
||||
fillElement(element);
|
||||
|
||||
if (this.timedStateMap != null) {
|
||||
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
|
||||
Element timedStateElem = state.toDom(element.getOwnerDocument());
|
||||
element.appendChild(timedStateElem);
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@ -74,7 +171,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void fillLocator(LocatorBuilder lb) {
|
||||
public void fillLocator(LocatorBuilder lb) {
|
||||
lb.append(Tags.RESOURCE).append(getType()).append(getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,13 @@ public class Tags {
|
|||
public static final String DATE = "Date";
|
||||
public static final String STATE = "State";
|
||||
public static final String VALUE = "Value";
|
||||
public static final String TIME = "Time";
|
||||
public static final String INTERPRETATION = "Interpretation";
|
||||
public static final String UOM = "Uom";
|
||||
public static final String HIDDEN = "Hidden";
|
||||
public static final String INDEX = "Index";
|
||||
public static final String PARAMETER = "Parameter";
|
||||
public static final String TIMED_STATE = "TimedState";
|
||||
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
|
||||
public static final String RESOURCE = "Resource";
|
||||
public static final String ORDER = "Order";
|
||||
|
|
|
@ -200,7 +200,7 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
|||
public Locator getLocator() {
|
||||
LocatorBuilder lb = new LocatorBuilder();
|
||||
this.parent.fillLocator(lb);
|
||||
this.fillLocator(lb);
|
||||
fillLocator(lb);
|
||||
return lb.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import li.strolch.model.AbstractStrolchElement;
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.ITimeVariable;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract class AbstractStrolchTimedState<T extends IValue> extends AbstractStrolchElement implements
|
||||
StrolchTimedState<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Resource parent;
|
||||
protected ITimedState<T> state;
|
||||
|
||||
public AbstractStrolchTimedState() {
|
||||
this.state = new TimedState<>();
|
||||
}
|
||||
|
||||
public AbstractStrolchTimedState(String id, String name) {
|
||||
super(id, name);
|
||||
this.state = new TimedState<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimeValue<T> getNextMatch(Long time, T value) {
|
||||
return this.state.getNextMatch(time, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimeValue<T> getPreviousMatch(Long time, T value) {
|
||||
return this.state.getPreviousMatch(time, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends IValueChange<T>> void applyChange(U change) {
|
||||
this.state.applyChange(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimeValue<T> getStateAt(Long time) {
|
||||
return this.state.getStateAt(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimeVariable<T> getTimeEvolution() {
|
||||
return this.state.getTimeEvolution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchElement getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(Resource parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchRootElement getRootElement() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillLocator(LocatorBuilder locatorBuilder) {
|
||||
locatorBuilder.append(Tags.TIMED_STATE);
|
||||
locatorBuilder.append(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getLocator() {
|
||||
LocatorBuilder lb = new LocatorBuilder();
|
||||
this.parent.fillLocator(lb);
|
||||
fillLocator(lb);
|
||||
return lb.build();
|
||||
}
|
||||
|
||||
protected void fillClone(AbstractStrolchTimedState<T> clone) {
|
||||
super.fillClone(clone);
|
||||
clone.state = this.state.getCopy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(getClass().getSimpleName());
|
||||
builder.append(" [id=");
|
||||
builder.append(this.id);
|
||||
builder.append(", name=");
|
||||
builder.append(this.name);
|
||||
builder.append(", valueNow=");
|
||||
builder.append(this.state.getStateAt(System.currentTimeMillis()));
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String TYPE = "BooleanState";
|
||||
|
||||
public BooleanTimedState() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BooleanTimedState(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public BooleanTimedState(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
this.state = new TimedState<>();
|
||||
|
||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
||||
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
|
||||
Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
||||
BooleanValue booleanValue = new BooleanValue(value);
|
||||
this.state.getTimeEvolution().setValueAt(time, booleanValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
||||
super.fillElement(stateElement);
|
||||
SortedSet<ITimeValue<BooleanValue>> values = this.state.getTimeEvolution().getValues();
|
||||
for (ITimeValue<BooleanValue> timeValue : values) {
|
||||
Long time = timeValue.getTime();
|
||||
BooleanValue value = timeValue.getValue();
|
||||
Element valueElem = doc.createElement(Tags.VALUE);
|
||||
valueElem.setAttribute(Tags.TIME, time.toString());
|
||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
||||
stateElement.appendChild(valueElem);
|
||||
}
|
||||
|
||||
return stateElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchElement getClone() {
|
||||
BooleanTimedState clone = new BooleanTimedState();
|
||||
fillClone(clone);
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String TYPE = "FloatState";
|
||||
|
||||
public FloatTimedState() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FloatTimedState(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public FloatTimedState(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
this.state = new TimedState<>();
|
||||
|
||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
||||
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
|
||||
Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
||||
FloatValue floatValue = new FloatValue(value);
|
||||
this.state.getTimeEvolution().setValueAt(time, floatValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
||||
super.fillElement(stateElement);
|
||||
SortedSet<ITimeValue<FloatValue>> values = this.state.getTimeEvolution().getValues();
|
||||
for (ITimeValue<FloatValue> timeValue : values) {
|
||||
Long time = timeValue.getTime();
|
||||
FloatValue value = timeValue.getValue();
|
||||
Element valueElem = doc.createElement(Tags.VALUE);
|
||||
valueElem.setAttribute(Tags.TIME, time.toString());
|
||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
||||
stateElement.appendChild(valueElem);
|
||||
}
|
||||
|
||||
return stateElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchElement getClone() {
|
||||
FloatTimedState clone = new FloatTimedState();
|
||||
fillClone(clone);
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ public interface ITimedState<T extends IValue> {
|
|||
* @param change
|
||||
* the state change to be applied
|
||||
*/
|
||||
void applyChange(final IValueChange<T> change);
|
||||
<U extends IValueChange<T>> void applyChange(final U change);
|
||||
|
||||
/**
|
||||
* @return the state at the given time
|
||||
|
@ -57,4 +57,8 @@ public interface ITimedState<T extends IValue> {
|
|||
*/
|
||||
ITimeVariable<T> getTimeEvolution();
|
||||
|
||||
/**
|
||||
* @return a copy of this timed state
|
||||
*/
|
||||
ITimedState<T> getCopy();
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String TYPE = "IntegerState";
|
||||
|
||||
public IntegerTimedState() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IntegerTimedState(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public IntegerTimedState(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
this.state = new TimedState<>();
|
||||
|
||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
||||
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
|
||||
Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE));
|
||||
IntegerValue integerValue = new IntegerValue(value);
|
||||
this.state.getTimeEvolution().setValueAt(time, integerValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
||||
super.fillElement(stateElement);
|
||||
SortedSet<ITimeValue<IntegerValue>> values = this.state.getTimeEvolution().getValues();
|
||||
for (ITimeValue<IntegerValue> timeValue : values) {
|
||||
Long time = timeValue.getTime();
|
||||
IntegerValue value = timeValue.getValue();
|
||||
Element valueElem = doc.createElement(Tags.VALUE);
|
||||
valueElem.setAttribute(Tags.TIME, time.toString());
|
||||
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
|
||||
stateElement.appendChild(valueElem);
|
||||
}
|
||||
|
||||
return stateElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchElement getClone() {
|
||||
IntegerTimedState clone = new IntegerTimedState();
|
||||
fillClone(clone);
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValue> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String TYPE = "StringSetState";
|
||||
|
||||
public StringSetTimedState() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StringSetTimedState(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public StringSetTimedState(Element element) {
|
||||
super.fromDom(element);
|
||||
|
||||
this.state = new TimedState<>();
|
||||
|
||||
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
|
||||
for (int i = 0; i < timeValueElems.getLength(); i++) {
|
||||
Element timeValueElem = (Element) timeValueElems.item(i);
|
||||
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
|
||||
|
||||
String valueAsString = timeValueElem.getAttribute(Tags.VALUE);
|
||||
Set<AString> value = new HashSet<>();
|
||||
String[] values = valueAsString.split(",");
|
||||
for (String s : values) {
|
||||
value.add(new AString(s.trim()));
|
||||
}
|
||||
|
||||
StringSetValue integerValue = new StringSetValue(value);
|
||||
this.state.getTimeEvolution().setValueAt(time, integerValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toDom(Document doc) {
|
||||
|
||||
Element stateElement = doc.createElement(Tags.TIMED_STATE);
|
||||
super.fillElement(stateElement);
|
||||
SortedSet<ITimeValue<StringSetValue>> values = this.state.getTimeEvolution().getValues();
|
||||
for (ITimeValue<StringSetValue> timeValue : values) {
|
||||
Long time = timeValue.getTime();
|
||||
StringSetValue stringSetValue = timeValue.getValue();
|
||||
|
||||
Set<AString> value = stringSetValue.getValue();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Iterator<AString> iter = value.iterator();
|
||||
while (iter.hasNext()) {
|
||||
sb.append(iter.next().getString());
|
||||
if (iter.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
String valueAsString = sb.toString();
|
||||
|
||||
Element valueElem = doc.createElement(Tags.VALUE);
|
||||
valueElem.setAttribute(Tags.TIME, time.toString());
|
||||
valueElem.setAttribute(Tags.VALUE, valueAsString);
|
||||
stateElement.appendChild(valueElem);
|
||||
}
|
||||
|
||||
return stateElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchElement getClone() {
|
||||
StringSetTimedState clone = new StringSetTimedState();
|
||||
fillClone(clone);
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.ITimeVariable;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public interface StrolchTimedState<T extends IValue> extends StrolchElement {
|
||||
|
||||
public ITimeValue<T> getNextMatch(Long time, T value);
|
||||
|
||||
public ITimeValue<T> getPreviousMatch(Long time, T value);
|
||||
|
||||
public <U extends IValueChange<T>> void applyChange(U change);
|
||||
|
||||
public ITimeValue<T> getStateAt(Long time);
|
||||
|
||||
public ITimeVariable<T> getTimeEvolution();
|
||||
|
||||
public void setParent(Resource aThis);
|
||||
}
|
|
@ -64,7 +64,7 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void applyChange(final IValueChange<T> change) {
|
||||
public <U extends IValueChange<T>> void applyChange(U change) {
|
||||
this.timeVariable.applyChange(change);
|
||||
}
|
||||
|
||||
|
@ -78,4 +78,10 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
|
|||
return this.timeVariable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimedState<T> getCopy() {
|
||||
TimedState<T> copy = new TimedState<>();
|
||||
copy.timeVariable = this.timeVariable.getCopy();
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,5 @@ public interface ITimeValue<T extends IValue> extends Comparable<ITimeValue<T>>
|
|||
|
||||
ITimeValue<T> add(final T change);
|
||||
|
||||
ITimeValue<T> getCopy();
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ import java.util.Collection;
|
|||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* A timed variable storing a ordered sequence of {@link ITimeValue} objects
|
||||
* modeling a time evolution of a quantity.
|
||||
* A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity.
|
||||
*
|
||||
* @author Martin Smock <smock.martin@gmail.com>
|
||||
*
|
||||
|
@ -41,14 +40,12 @@ public interface ITimeVariable<T extends IValue> {
|
|||
void setValueAt(final 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);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param change
|
||||
* the {@link IValueChange} to be applied
|
||||
|
@ -56,8 +53,7 @@ public interface ITimeVariable<T extends IValue> {
|
|||
void applyChange(final IValueChange<T> change);
|
||||
|
||||
/**
|
||||
* Get all {@link ITimeValue} objects whose time field is greater or equal
|
||||
* to the given time
|
||||
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time
|
||||
*
|
||||
* @param time
|
||||
* the time the sequence starts with
|
||||
|
@ -66,8 +62,7 @@ public interface ITimeVariable<T extends IValue> {
|
|||
Collection<ITimeValue<T>> getFutureValues(final 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
|
||||
*
|
||||
* @param time
|
||||
* the time the sequence starts with
|
||||
|
@ -83,11 +78,14 @@ public interface ITimeVariable<T extends IValue> {
|
|||
SortedSet<ITimeValue<T>> getValues();
|
||||
|
||||
/**
|
||||
* removes {@link ITimeValue} objects from the sequence, where the successor
|
||||
* matches value. I.e considering a pair of adjacent {@link ITimeValue}
|
||||
* objects in the sequence which have the same {@link IValue}, the later one
|
||||
* is removed, since it contains no additional information.
|
||||
* removes {@link ITimeValue} objects from the sequence, where the successor matches value. I.e considering a pair
|
||||
* of adjacent {@link ITimeValue} objects in the sequence which have the same {@link IValue}, the later one is
|
||||
* removed, since it contains no additional information.
|
||||
*/
|
||||
void compact();
|
||||
|
||||
/**
|
||||
* @return a copy of this time variable
|
||||
*/
|
||||
ITimeVariable<T> getCopy();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ package li.strolch.model.timevalue;
|
|||
*
|
||||
* @param <T>
|
||||
* any object for which a (generalized) add operation can be defined.
|
||||
*
|
||||
*/
|
||||
public interface IValue<T> {
|
||||
|
||||
|
@ -52,5 +51,4 @@ public interface IValue<T> {
|
|||
* @return a copy of this
|
||||
*/
|
||||
IValue<T> getCopy();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timevalue.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
|
||||
/**
|
||||
* {@link IValue} implementation to work with Boolean valued {@link ITimeValue} objects
|
||||
*
|
||||
* @author Martin Smock <smock.martin@gmail.com>
|
||||
*/
|
||||
public class BooleanValue implements IValue<Boolean>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final BooleanValue NEUTRAL = new BooleanValue(false);
|
||||
|
||||
private Boolean value;
|
||||
|
||||
public BooleanValue(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public BooleanValue(boolean value) {
|
||||
this.value = Boolean.valueOf(value);
|
||||
}
|
||||
|
||||
public BooleanValue(String valueAsString) throws NumberFormatException {
|
||||
this.value = Boolean.parseBoolean(valueAsString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanValue add(Boolean o) {
|
||||
this.value = o;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IValue<Boolean> other) {
|
||||
return this.value.equals(other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanValue getInverse() {
|
||||
return new BooleanValue(!getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("BooleanValue [value=");
|
||||
sb.append(this.value);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanValue getCopy() {
|
||||
return new BooleanValue(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BooleanValue other = (BooleanValue) obj;
|
||||
if (this.value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!this.value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -25,36 +25,36 @@ import li.strolch.model.timevalue.IValue;
|
|||
*
|
||||
* @author Martin Smock <smock.martin@gmail.com>
|
||||
*/
|
||||
public class DoubleValue implements IValue<Double>, Serializable {
|
||||
public class FloatValue implements IValue<Double>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final DoubleValue NEUTRAL = new DoubleValue(0.0d);
|
||||
public static final FloatValue NEUTRAL = new FloatValue(0.0d);
|
||||
|
||||
private Double value;
|
||||
|
||||
public DoubleValue(Double value) {
|
||||
public FloatValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public DoubleValue(double value) {
|
||||
public FloatValue(double value) {
|
||||
this.value = Double.valueOf(value);
|
||||
}
|
||||
|
||||
public DoubleValue(Integer value) {
|
||||
public FloatValue(Integer value) {
|
||||
this.value = this.value.doubleValue();
|
||||
}
|
||||
|
||||
public DoubleValue(int value) {
|
||||
public FloatValue(int value) {
|
||||
this.value = Integer.valueOf(value).doubleValue();
|
||||
}
|
||||
|
||||
public DoubleValue(String valueAsString) throws NumberFormatException {
|
||||
public FloatValue(String valueAsString) throws NumberFormatException {
|
||||
this.value = Double.parseDouble(valueAsString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleValue add(Double o) {
|
||||
public FloatValue add(Double o) {
|
||||
this.value += o;
|
||||
return this;
|
||||
}
|
||||
|
@ -80,13 +80,13 @@ public class DoubleValue implements IValue<Double>, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DoubleValue getInverse() {
|
||||
return new DoubleValue(-getValue());
|
||||
public FloatValue getInverse() {
|
||||
return new FloatValue(-getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleValue getCopy(){
|
||||
return new DoubleValue(this.value);
|
||||
public FloatValue getCopy(){
|
||||
return new FloatValue(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,7 +105,7 @@ public class DoubleValue implements IValue<Double>, Serializable {
|
|||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DoubleValue other = (DoubleValue) obj;
|
||||
FloatValue other = (FloatValue) obj;
|
||||
if (this.value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
|
@ -15,12 +15,13 @@
|
|||
*/
|
||||
package li.strolch.model.timevalue.impl;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
|
||||
|
@ -37,12 +38,18 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
private static Set<AString> neu = Collections.emptySet();
|
||||
public static final IValue<Set<AString>> NEUTRAL = new StringSetValue(neu);
|
||||
|
||||
private Set<AString> aStrings = new HashSet<AString>();
|
||||
private Set<AString> aStrings = new HashSet<>();
|
||||
|
||||
public StringSetValue() {
|
||||
}
|
||||
|
||||
public StringSetValue(final Set<AString> aStrings) {
|
||||
// assert no null values in set
|
||||
for (AString aString : aStrings) {
|
||||
if (StringHelper.isEmpty(aString.getString())) {
|
||||
throw new StrolchException("StringSetValue may not contain null values in set!");
|
||||
}
|
||||
}
|
||||
this.aStrings = aStrings;
|
||||
}
|
||||
|
||||
|
@ -54,10 +61,14 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
@Override
|
||||
public IValue<Set<AString>> add(Set<AString> o) {
|
||||
|
||||
Set<AString> toBeAdded = new HashSet<AString>(o);
|
||||
Set<AString> toBeAdded = new HashSet<>(o);
|
||||
|
||||
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
|
||||
AString toAdd = iter1.next();
|
||||
if (StringHelper.isEmpty(toAdd.getString())) {
|
||||
throw new StrolchException("StringSetValue may not contain null values in set!");
|
||||
}
|
||||
|
||||
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
|
||||
AString aString = iter.next();
|
||||
boolean valueMatch = aString.getString().equals(toAdd.getString());
|
||||
|
@ -79,8 +90,8 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IValue<Set<AString>> getInverse() {
|
||||
Set<AString> inverseSet = new HashSet<AString>();
|
||||
public StringSetValue getInverse() {
|
||||
Set<AString> inverseSet = new HashSet<>();
|
||||
for (AString as : this.aStrings) {
|
||||
inverseSet.add(as.getInverse());
|
||||
}
|
||||
|
@ -91,7 +102,7 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
|
||||
@Override
|
||||
public StringSetValue getCopy() {
|
||||
return new StringSetValue(this.aStrings);
|
||||
return new StringSetValue(new HashSet<>(this.aStrings));
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
|
@ -103,5 +114,4 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,12 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
|||
return this.getTime().compareTo(arg0.getTime());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ITimeValue<T> getCopy() {
|
||||
return new TimeValue<T>(time, (T) value.getCopy());
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -112,5 +118,4 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import li.strolch.model.timevalue.ITimeVariable;
|
|||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
|
||||
|
||||
/**
|
||||
* @author Martin Smock <smock.martin@gmail.com>
|
||||
*/
|
||||
|
@ -94,6 +93,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
|||
newValue.add(change.getValue());
|
||||
this.container.add(newValue);
|
||||
}
|
||||
|
||||
compact();
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,15 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
|||
predecessor = successor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimeVariable<T> getCopy() {
|
||||
TimeVariable<T> clone = new TimeVariable<>();
|
||||
for (ITimeValue<T> timeValue : this.container) {
|
||||
clone.container.add(timeValue.getCopy());
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package li.strolch.model.visitor;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Order;
|
||||
|
@ -26,6 +25,8 @@ import li.strolch.model.ParameterBag;
|
|||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.ITimeVariable;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -51,18 +52,22 @@ public class StrolchElementDeepEqualsVisitor {
|
|||
}
|
||||
|
||||
protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) {
|
||||
if (!srcElement.getName().equals(dstElement.getName()))
|
||||
if (!srcElement.getName().equals(dstElement.getName())) {
|
||||
this.mismatchedLocators.add(dstElement.getLocator());
|
||||
if (!srcElement.getType().equals(dstElement.getType()))
|
||||
}
|
||||
if (!srcElement.getType().equals(dstElement.getType())) {
|
||||
this.mismatchedLocators.add(dstElement.getLocator());
|
||||
}
|
||||
}
|
||||
|
||||
protected void deepEquals(Order srcOrder, Order dstOrder) {
|
||||
deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder);
|
||||
if (!srcOrder.getState().equals(dstOrder.getState()))
|
||||
if (!srcOrder.getState().equals(dstOrder.getState())) {
|
||||
this.mismatchedLocators.add(dstOrder.getLocator());
|
||||
if (!srcOrder.getDate().equals(dstOrder.getDate()))
|
||||
}
|
||||
if (!srcOrder.getDate().equals(dstOrder.getDate())) {
|
||||
this.mismatchedLocators.add(dstOrder.getLocator());
|
||||
}
|
||||
|
||||
deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder);
|
||||
}
|
||||
|
@ -70,6 +75,27 @@ public class StrolchElementDeepEqualsVisitor {
|
|||
protected void deepEquals(Resource srcRes, Resource dstRes) {
|
||||
deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes);
|
||||
deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes);
|
||||
|
||||
Set<String> srcTimedStateKeySet = srcRes.getTimedStateKeySet();
|
||||
for (String timedStateKey : srcTimedStateKeySet) {
|
||||
StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey);
|
||||
|
||||
if (!dstRes.hasTimedState(timedStateKey)) {
|
||||
this.mismatchedLocators.add(srcTimedState.getLocator());
|
||||
continue;
|
||||
}
|
||||
|
||||
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
|
||||
deepEquals(srcTimedState, dstTimedState);
|
||||
}
|
||||
|
||||
Set<String> dstTimedStateKeySet = dstRes.getTimedStateKeySet();
|
||||
for (String timedStateKey : dstTimedStateKeySet) {
|
||||
if (!srcRes.hasTimedState(timedStateKey)) {
|
||||
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
|
||||
this.mismatchedLocators.add(dstTimedState.getLocator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) {
|
||||
|
@ -121,28 +147,43 @@ public class StrolchElementDeepEqualsVisitor {
|
|||
|
||||
protected void deepEquals(Parameter<?> srcParam, Parameter<?> dstParam) {
|
||||
deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam);
|
||||
if (!srcParam.getUom().equals(dstParam.getUom()))
|
||||
if (!srcParam.getUom().equals(dstParam.getUom())) {
|
||||
this.mismatchedLocators.add(dstParam.getLocator());
|
||||
if (!srcParam.getInterpretation().equals(dstParam.getInterpretation()))
|
||||
}
|
||||
if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) {
|
||||
this.mismatchedLocators.add(dstParam.getLocator());
|
||||
if (srcParam.isHidden() != dstParam.isHidden())
|
||||
}
|
||||
if (srcParam.isHidden() != dstParam.isHidden()) {
|
||||
this.mismatchedLocators.add(dstParam.getLocator());
|
||||
if (srcParam.getIndex() != dstParam.getIndex())
|
||||
}
|
||||
if (srcParam.getIndex() != dstParam.getIndex()) {
|
||||
this.mismatchedLocators.add(dstParam.getLocator());
|
||||
}
|
||||
|
||||
if (!srcParam.getValue().equals(dstParam.getValue()))
|
||||
if (!srcParam.getValue().equals(dstParam.getValue())) {
|
||||
this.mismatchedLocators.add(dstParam.getLocator());
|
||||
}
|
||||
}
|
||||
|
||||
protected void deepEquals(StrolchTimedState<?> srcState, StrolchTimedState<?> dstState) {
|
||||
deepEquals((StrolchElement) srcState, (StrolchElement) dstState);
|
||||
final ITimeVariable<?> srcTimeEvolution = srcState.getTimeEvolution();
|
||||
final ITimeVariable<?> dstTimeEvolution = dstState.getTimeEvolution();
|
||||
|
||||
if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) {
|
||||
this.mismatchedLocators.add(dstState.getLocator());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEqual(Order srcOrder, Order dstOrder) {
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||
visitor.visit(srcOrder);
|
||||
visitor.visit(dstOrder);
|
||||
return visitor.isEqual();
|
||||
}
|
||||
|
||||
public static boolean isEqual(Resource srcRes, Resource dstRes) {
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
return visitor.isEqual();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ import li.strolch.model.parameter.IntegerParameter;
|
|||
import li.strolch.model.parameter.LongParameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.timedstate.BooleanTimedState;
|
||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
|
||||
|
@ -78,6 +81,19 @@ public class ModelTest {
|
|||
assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailDeepResourceEquals2() {
|
||||
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||
BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
|
||||
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE)));
|
||||
timedState.setName("Ohla");
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
|
||||
assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformDeepOrderEquals() {
|
||||
Date date = new Date();
|
||||
|
@ -128,7 +144,7 @@ public class ModelTest {
|
|||
StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID);
|
||||
assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP);
|
||||
|
||||
ArrayList<String> stringList = new ArrayList<String>();
|
||||
ArrayList<String> stringList = new ArrayList<>();
|
||||
stringList.add("Hello");
|
||||
stringList.add("World");
|
||||
assertEquals(stringList, stringListP.getValue());
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.xml.OrderToDomVisitor;
|
||||
import li.strolch.model.xml.ResourceToDomVisitor;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -43,8 +43,10 @@ public class XmlToDomTest extends ModelTest {
|
|||
Element rootElement = document.getDocumentElement();
|
||||
Order parsedOrder = new Order(rootElement);
|
||||
|
||||
assertTrue("To DOM and back should equal same Order!",
|
||||
StrolchElementDeepEqualsVisitor.isEqual(order, parsedOrder));
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||
visitor.visit(parsedOrder);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,7 +61,9 @@ public class XmlToDomTest extends ModelTest {
|
|||
Element rootElement = document.getDocumentElement();
|
||||
Resource parsedResource = new Resource(rootElement);
|
||||
|
||||
assertTrue("To DOM and back should equal same Resource!",
|
||||
StrolchElementDeepEqualsVisitor.isEqual(resource, parsedResource));
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||
visitor.visit(parsedResource);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.timedstate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class StrolchTimedStateTest {
|
||||
|
||||
@Test
|
||||
public void testFloatState() {
|
||||
|
||||
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
|
||||
|
||||
FloatTimedState floatState = myRes.getTimedState(ModelGenerator.STATE_FLOAT_ID);
|
||||
ITimeValue<FloatValue> valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
|
||||
assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue());
|
||||
|
||||
ITimeValue<FloatValue> valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
|
||||
assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue());
|
||||
|
||||
ITimeValue<FloatValue> valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
|
||||
assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue());
|
||||
|
||||
ITimeValue<FloatValue> valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
|
||||
assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerState() {
|
||||
|
||||
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
|
||||
|
||||
IntegerTimedState integerState = myRes.getTimedState(ModelGenerator.STATE_INTEGER_ID);
|
||||
ITimeValue<IntegerValue> valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
|
||||
assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue());
|
||||
|
||||
ITimeValue<IntegerValue> valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
|
||||
assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue());
|
||||
|
||||
ITimeValue<IntegerValue> valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
|
||||
assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue());
|
||||
|
||||
ITimeValue<IntegerValue> valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
|
||||
assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanState() {
|
||||
|
||||
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
|
||||
|
||||
BooleanTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
|
||||
ITimeValue<BooleanValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
|
||||
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue());
|
||||
|
||||
ITimeValue<BooleanValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
|
||||
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue());
|
||||
|
||||
ITimeValue<BooleanValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
|
||||
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue());
|
||||
|
||||
ITimeValue<BooleanValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
|
||||
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringSetState() {
|
||||
|
||||
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
|
||||
|
||||
StringSetTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_STRING_ID);
|
||||
ITimeValue<StringSetValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
|
||||
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue());
|
||||
|
||||
ITimeValue<StringSetValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
|
||||
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue());
|
||||
|
||||
ITimeValue<StringSetValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
|
||||
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue());
|
||||
|
||||
ITimeValue<StringSetValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
|
||||
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue());
|
||||
}
|
||||
|
||||
private static Set<AString> asSet(String value) {
|
||||
HashSet<AString> hashSet = new HashSet<>();
|
||||
hashSet.add(new AString(value));
|
||||
return hashSet;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -28,10 +28,10 @@ import org.junit.Test;
|
|||
|
||||
public class TimeStateTest {
|
||||
|
||||
private ITimedState<DoubleValue> state = new TimedState<DoubleValue>();
|
||||
private ITimedState<FloatValue> state = new TimedState<FloatValue>();
|
||||
|
||||
final DoubleValue expectedValue1 = new DoubleValue(Double.valueOf(100D));
|
||||
final DoubleValue expectedValue2 = new DoubleValue(Double.valueOf(200D));
|
||||
final FloatValue expectedValue1 = new FloatValue(Double.valueOf(100D));
|
||||
final FloatValue expectedValue2 = new FloatValue(Double.valueOf(200D));
|
||||
|
||||
final Long t0 = Long.valueOf(0);
|
||||
final Long t10 = Long.valueOf(10);
|
||||
|
@ -42,20 +42,20 @@ public class TimeStateTest {
|
|||
@Before
|
||||
public void before() {
|
||||
|
||||
final IValueChange<DoubleValue> change1 = new ValueChange<DoubleValue>(this.t10, this.expectedValue1);
|
||||
final IValueChange<FloatValue> change1 = new ValueChange<FloatValue>(this.t10, this.expectedValue1);
|
||||
this.state.applyChange(change1);
|
||||
|
||||
final ITimeValue<DoubleValue> stateAt9 = this.state.getStateAt(9L);
|
||||
final ITimeValue<FloatValue> stateAt9 = this.state.getStateAt(9L);
|
||||
assertNull(stateAt9);
|
||||
|
||||
final ITimeValue<DoubleValue> stateAt11 = this.state.getStateAt(11L);
|
||||
final ITimeValue<FloatValue> stateAt11 = this.state.getStateAt(11L);
|
||||
assertNotNull(stateAt11);
|
||||
assertEquals(true, stateAt11.getValue().matches(this.expectedValue1));
|
||||
|
||||
final IValueChange<DoubleValue> change2 = new ValueChange<DoubleValue>(this.t30, this.expectedValue1);
|
||||
final IValueChange<FloatValue> change2 = new ValueChange<FloatValue>(this.t30, this.expectedValue1);
|
||||
this.state.applyChange(change2);
|
||||
|
||||
final ITimeValue<DoubleValue> stateAt31 = this.state.getStateAt(31L);
|
||||
final ITimeValue<FloatValue> stateAt31 = this.state.getStateAt(31L);
|
||||
assertNotNull(stateAt31);
|
||||
assertEquals(true, stateAt31.getValue().matches(this.expectedValue2));
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class TimeStateTest {
|
|||
@Test
|
||||
public void testGetNextMatch() {
|
||||
|
||||
ITimeValue<DoubleValue> nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1);
|
||||
ITimeValue<FloatValue> nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1);
|
||||
assertNotNull(nextMatch);
|
||||
assertEquals(this.t10, nextMatch.getTime());
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class TimeStateTest {
|
|||
@Test
|
||||
public void testGetPreviousMatch() {
|
||||
|
||||
ITimeValue<DoubleValue> previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2);
|
||||
ITimeValue<FloatValue> previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2);
|
||||
assertNotNull(previousMatch);
|
||||
assertEquals(this.t30, previousMatch.getTime());
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.util.Collection;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import li.strolch.model.timevalue.impl.TimeVariable;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
|
||||
|
@ -35,22 +35,22 @@ public class FloatTimeVariableTest {
|
|||
private static final Long STEP = 10L;
|
||||
private static final Long PICK = 50L;
|
||||
|
||||
private TimeVariable<DoubleValue> timeVariable;
|
||||
private TimeVariable<FloatValue> timeVariable;
|
||||
|
||||
/**
|
||||
* set the values ascending with a difference of STEP
|
||||
*/
|
||||
@Before
|
||||
public void init() {
|
||||
this.timeVariable = new TimeVariable<DoubleValue>();
|
||||
this.timeVariable = new TimeVariable<FloatValue>();
|
||||
for (long i = 0; i < MAX; i += STEP) {
|
||||
this.timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i));
|
||||
this.timeVariable.setValueAt(Long.valueOf(i), new FloatValue(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueAt() {
|
||||
ITimeValue<DoubleValue> valueAt = this.timeVariable.getValueAt(PICK);
|
||||
ITimeValue<FloatValue> valueAt = this.timeVariable.getValueAt(PICK);
|
||||
assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001);
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,12 @@ public class FloatTimeVariableTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetFutureValues() {
|
||||
Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||
Collection<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||
Long expectedTime = PICK;
|
||||
Double expectedValue = PICK.doubleValue();
|
||||
for (ITimeValue<DoubleValue> value : futureValues) {
|
||||
for (ITimeValue<FloatValue> value : futureValues) {
|
||||
assertEquals(expectedTime, value.getTime());
|
||||
assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
|
||||
assertTrue(value.getValue().matches(new FloatValue(expectedValue)));
|
||||
expectedTime += STEP;
|
||||
expectedValue += STEP.doubleValue();
|
||||
}
|
||||
|
@ -76,12 +76,12 @@ public class FloatTimeVariableTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetPastValues() {
|
||||
Collection<ITimeValue<DoubleValue>> pastValues = this.timeVariable.getPastValues(MAX);
|
||||
Collection<ITimeValue<FloatValue>> pastValues = this.timeVariable.getPastValues(MAX);
|
||||
Long expectedTime = 0L;
|
||||
Double expectedValue = expectedTime.doubleValue();
|
||||
for (ITimeValue<DoubleValue> value : pastValues) {
|
||||
for (ITimeValue<FloatValue> value : pastValues) {
|
||||
assertEquals(expectedTime, value.getTime());
|
||||
assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
|
||||
assertTrue(value.getValue().matches(new FloatValue(expectedValue)));
|
||||
expectedTime += STEP;
|
||||
expectedValue += STEP.doubleValue();
|
||||
}
|
||||
|
@ -93,17 +93,17 @@ public class FloatTimeVariableTest {
|
|||
@Test
|
||||
public void testApplyChange() {
|
||||
|
||||
DoubleValue doubleValue = new DoubleValue(STEP.doubleValue());
|
||||
FloatValue doubleValue = new FloatValue(STEP.doubleValue());
|
||||
|
||||
IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue);
|
||||
IValueChange<FloatValue> change = new ValueChange<FloatValue>(PICK, doubleValue);
|
||||
this.timeVariable.applyChange(change);
|
||||
|
||||
Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||
Collection<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||
Long expectedTime = PICK;
|
||||
|
||||
IValue<Double> expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue());
|
||||
IValue<Double> expectedValue = new FloatValue(PICK.doubleValue() + change.getValue().getValue());
|
||||
|
||||
for (ITimeValue<DoubleValue> value : futureValues) {
|
||||
for (ITimeValue<FloatValue> value : futureValues) {
|
||||
assertEquals(expectedTime, value.getTime());
|
||||
assertTrue(expectedValue.matches(value.getValue()));
|
||||
expectedTime += STEP;
|
||||
|
@ -117,17 +117,17 @@ public class FloatTimeVariableTest {
|
|||
@Test
|
||||
public void testApply2Change() {
|
||||
|
||||
this.timeVariable = new TimeVariable<DoubleValue>();
|
||||
this.timeVariable = new TimeVariable<FloatValue>();
|
||||
|
||||
DoubleValue doubleValue = new DoubleValue(STEP.doubleValue());
|
||||
FloatValue doubleValue = new FloatValue(STEP.doubleValue());
|
||||
|
||||
IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue);
|
||||
IValueChange<FloatValue> change = new ValueChange<FloatValue>(PICK, doubleValue);
|
||||
this.timeVariable.applyChange(change);
|
||||
|
||||
ITimeValue<DoubleValue> actual = this.timeVariable.getValueAt(PICK);
|
||||
ITimeValue<FloatValue> actual = this.timeVariable.getValueAt(PICK);
|
||||
assertNotNull(actual);
|
||||
|
||||
IValue<Double> expectedValue = new DoubleValue(STEP.doubleValue());
|
||||
IValue<Double> expectedValue = new FloatValue(STEP.doubleValue());
|
||||
assertEquals(true, actual.getValue().matches(expectedValue));
|
||||
}
|
||||
|
||||
|
@ -138,14 +138,14 @@ public class FloatTimeVariableTest {
|
|||
@Test
|
||||
public void testCompact() {
|
||||
|
||||
this.timeVariable = new TimeVariable<DoubleValue>();
|
||||
this.timeVariable = new TimeVariable<FloatValue>();
|
||||
for (Long i = 0L; i < MAX; i += STEP) {
|
||||
this.timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue()));
|
||||
this.timeVariable.setValueAt(i, new FloatValue(STEP.doubleValue()));
|
||||
}
|
||||
// call
|
||||
this.timeVariable.compact();
|
||||
// check
|
||||
SortedSet<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(0L);
|
||||
SortedSet<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(0L);
|
||||
assertEquals(1, futureValues.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.timevalue.impl.AString;
|
||||
import li.strolch.model.timevalue.impl.DoubleValue;
|
||||
import li.strolch.model.timevalue.impl.FloatValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||
|
||||
|
@ -34,8 +34,8 @@ public class ValueTests {
|
|||
*/
|
||||
@Test
|
||||
public void testDoubleInverse() {
|
||||
DoubleValue value = new DoubleValue(10.0d);
|
||||
DoubleValue inverse = value.getInverse();
|
||||
FloatValue value = new FloatValue(10.0d);
|
||||
FloatValue inverse = value.getInverse();
|
||||
assertEquals(Double.valueOf(-10.0d), inverse.getValue());
|
||||
assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue