[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;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import li.strolch.model.parameter.BooleanParameter;
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
import li.strolch.model.parameter.DateParameter;
|
import li.strolch.model.parameter.DateParameter;
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
@ -27,224 +30,319 @@ import li.strolch.model.parameter.LongParameter;
|
||||||
import li.strolch.model.parameter.Parameter;
|
import li.strolch.model.parameter.Parameter;
|
||||||
import li.strolch.model.parameter.StringListParameter;
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
import li.strolch.model.parameter.StringParameter;
|
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
|
* Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then
|
||||||
* be used in test classes etc.
|
* be used in test classes etc.
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class ModelGenerator {
|
public class ModelGenerator {
|
||||||
|
|
||||||
public static final String PARAM_BOOLEAN_ID = "@param1";
|
public static final String PARAM_BOOLEAN_ID = "@param1";
|
||||||
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
|
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
|
||||||
|
|
||||||
public static final String PARAM_FLOAT_ID = "@param2";
|
public static final String PARAM_FLOAT_ID = "@param2";
|
||||||
public static final String PARAM_FLOAT_NAME = "Float Param";
|
public static final String PARAM_FLOAT_NAME = "Float Param";
|
||||||
|
|
||||||
public static final String PARAM_INTEGER_ID = "@param3";
|
public static final String PARAM_INTEGER_ID = "@param3";
|
||||||
public static final String PARAM_INTEGER_NAME = "Integer Param";
|
public static final String PARAM_INTEGER_NAME = "Integer Param";
|
||||||
|
|
||||||
public static final String PARAM_LONG_ID = "@param4";
|
public static final String PARAM_LONG_ID = "@param4";
|
||||||
public static final String PARAM_LONG_NAME = "Long Param";
|
public static final String PARAM_LONG_NAME = "Long Param";
|
||||||
|
|
||||||
public static final String PARAM_STRING_ID = "@param5";
|
public static final String PARAM_STRING_ID = "@param5";
|
||||||
public static final String PARAM_STRING_NAME = "String Param";
|
public static final String PARAM_STRING_NAME = "String Param";
|
||||||
|
|
||||||
public static final String PARAM_DATE_ID = "@param6";
|
public static final String PARAM_DATE_ID = "@param6";
|
||||||
public static final String PARAM_DATE_NAME = "Date Param";
|
public static final String PARAM_DATE_NAME = "Date Param";
|
||||||
|
|
||||||
public static final String PARAM_LIST_STRING_ID = "@param7";
|
public static final String PARAM_LIST_STRING_ID = "@param7";
|
||||||
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
|
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
|
||||||
|
|
||||||
public static final String BAG_ID = "@bag01";
|
public static final String STATE_FLOAT_ID = "@state1";
|
||||||
public static final String BAG_NAME = "Test Bag";
|
public static final String STATE_FLOAT_NAME = "Float State";
|
||||||
public static final String BAG_TYPE = "TestBag";
|
|
||||||
|
|
||||||
/**
|
public static final String STATE_INTEGER_ID = "@state2";
|
||||||
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
|
public static final String STATE_INTEGER_NAME = "Float State";
|
||||||
* {@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}
|
|
||||||
*
|
|
||||||
* @return the newly created {@link Resource}
|
|
||||||
*/
|
|
||||||
public static Resource createResource(String id, String name, String type) {
|
|
||||||
Resource resource = new Resource(id, name, type);
|
|
||||||
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
|
||||||
resource.addParameterBag(bag);
|
|
||||||
|
|
||||||
return resource;
|
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";
|
||||||
* Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling
|
public static final String STATE_BOOLEAN_NAME = "Float State";
|
||||||
* {@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}
|
|
||||||
*
|
|
||||||
* @return the list of newly created {@link Resource Resources}
|
|
||||||
*/
|
|
||||||
public static List<Resource> createResources(int idStart, int count, String idPrefix, String name, String type) {
|
|
||||||
List<Resource> resources = new ArrayList<>();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
|
|
||||||
resources.add(createResource(idPrefix + "_" + id, name + " " + i, type));
|
|
||||||
}
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public static final long STATE_TIME_0 = 0L;
|
||||||
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
|
public static final long STATE_TIME_10 = 10L;
|
||||||
* {@link #createParameterBag(String, String, String)}
|
public static final long STATE_TIME_20 = 20L;
|
||||||
*
|
public static final long STATE_TIME_30 = 30L;
|
||||||
* @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}
|
|
||||||
*/
|
|
||||||
public static Order createOrder(String id, String name, String type) {
|
|
||||||
return createOrder(id, name, type, new Date(), State.CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public static final Double STATE_FLOAT_TIME_0 = 0.0D;
|
||||||
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
|
public static final Double STATE_FLOAT_TIME_10 = 10.0D;
|
||||||
* {@link #createParameterBag(String, String, String)}
|
public static final Double STATE_FLOAT_TIME_20 = 20.0D;
|
||||||
*
|
public static final Double STATE_FLOAT_TIME_30 = 30.0D;
|
||||||
* @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}
|
|
||||||
*/
|
|
||||||
public static Order createOrder(String id, String name, String type, Date date, State state) {
|
|
||||||
|
|
||||||
Order order = new Order(id, name, type, date, state);
|
public static final Integer STATE_INTEGER_TIME_0 = 0;
|
||||||
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
public static final Integer STATE_INTEGER_TIME_10 = 10;
|
||||||
order.addParameterBag(bag);
|
public static final Integer STATE_INTEGER_TIME_20 = 20;
|
||||||
|
public static final Integer STATE_INTEGER_TIME_30 = 30;
|
||||||
|
|
||||||
return order;
|
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;
|
||||||
* Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling
|
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE;
|
||||||
* {@link #createParameterBag(String, String, String)}
|
public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE;
|
||||||
*
|
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
|
||||||
* @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}
|
|
||||||
*/
|
|
||||||
public static List<Order> createOrders(int idStart, int count, String idPrefix, String name, String type) {
|
|
||||||
List<Order> orders = new ArrayList<>();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
|
|
||||||
orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type));
|
|
||||||
}
|
|
||||||
return orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public static final String BAG_ID = "@bag01";
|
||||||
* Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add
|
public static final String BAG_NAME = "Test Bag";
|
||||||
* {@link Parameter}s
|
public static final String BAG_TYPE = "TestBag";
|
||||||
*
|
|
||||||
* @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}
|
|
||||||
*/
|
|
||||||
public static ParameterBag createParameterBag(String id, String name, String type) {
|
|
||||||
|
|
||||||
ParameterBag bag = new ParameterBag(id, name, type);
|
/**
|
||||||
addAllParameters(bag);
|
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
|
||||||
return bag;
|
* {@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}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link Resource}
|
||||||
|
*/
|
||||||
|
public static Resource createResource(String id, String name, String type) {
|
||||||
|
Resource resource = new Resource(id, name, type);
|
||||||
|
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
||||||
|
resource.addParameterBag(bag);
|
||||||
|
addTimedStates(resource);
|
||||||
|
|
||||||
/**
|
return resource;
|
||||||
* Adds the following {@link Parameter}s to the given {@link ParameterBag}:
|
}
|
||||||
* <ul>
|
|
||||||
* <li>BooleanParameter - true</li>
|
|
||||||
* <li>FloatParameter - 44.3</li>
|
|
||||||
* <li>IntegerParameter - 77</li>
|
|
||||||
* <li>LongParameter - 4453234566L</li>
|
|
||||||
* <li>StringParameter - "Strolch"</li>
|
|
||||||
* <li>DateParameter - 1354295525628L</li>
|
|
||||||
* <li>StringListParameter - Hello, World</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param bag
|
|
||||||
*/
|
|
||||||
public static void addAllParameters(ParameterBag bag) {
|
|
||||||
|
|
||||||
BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true);
|
/**
|
||||||
boolParam.setIndex(1);
|
* Creates {@link StrolchTimedState} instances and adds them to the {@link Resource}
|
||||||
bag.addParameter(boolParam);
|
*
|
||||||
|
* @param resource the resource to which to addd the newly created {@link StrolchTimedState}
|
||||||
|
*/
|
||||||
|
public static void addTimedStates(Resource resource) {
|
||||||
|
|
||||||
FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3);
|
// float state
|
||||||
floatParam.setIndex(2);
|
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
|
||||||
bag.addParameter(floatParam);
|
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);
|
||||||
|
|
||||||
IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77);
|
// integer state
|
||||||
integerParam.setIndex(3);
|
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
|
||||||
bag.addParameter(integerParam);
|
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);
|
||||||
|
|
||||||
LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L);
|
// boolean state
|
||||||
longParam.setIndex(4);
|
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
|
||||||
bag.addParameter(longParam);
|
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);
|
||||||
|
|
||||||
StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch");
|
// string state
|
||||||
stringParam.setIndex(5);
|
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
|
||||||
bag.addParameter(stringParam);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L));
|
private static Set<AString> asSet(String value) {
|
||||||
dateParam.setIndex(6);
|
HashSet<AString> hashSet = new HashSet<>();
|
||||||
bag.addParameter(dateParam);
|
hashSet.add(new AString(value));
|
||||||
|
return hashSet;
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<String> stringList = new ArrayList<String>();
|
private static void removeInverted(Set<AString> set) {
|
||||||
stringList.add("Hello");
|
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
|
||||||
stringList.add("World");
|
AString aString = iter.next();
|
||||||
StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME,
|
if (aString.isInverse()) {
|
||||||
stringList);
|
iter.remove();
|
||||||
stringListP.setIndex(7);
|
}
|
||||||
bag.addParameter(stringListP);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}
|
||||||
|
*
|
||||||
|
* @return the list of newly created {@link Resource Resources}
|
||||||
|
*/
|
||||||
|
public static List<Resource> createResources(int idStart, int count, String idPrefix, String name, String type) {
|
||||||
|
List<Resource> resources = new ArrayList<>();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
|
||||||
|
resources.add(createResource(idPrefix + "_" + id, name + " " + i, type));
|
||||||
|
}
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link Order}
|
||||||
|
*/
|
||||||
|
public static Order createOrder(String id, String name, String type) {
|
||||||
|
return createOrder(id, name, type, new Date(), State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link Order}
|
||||||
|
*/
|
||||||
|
public static Order createOrder(String id, String name, String type, Date date, State state) {
|
||||||
|
|
||||||
|
Order order = new Order(id, name, type, date, state);
|
||||||
|
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
||||||
|
order.addParameterBag(bag);
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}
|
||||||
|
*
|
||||||
|
* @return the list of newly created {@link Order Orders}
|
||||||
|
*/
|
||||||
|
public static List<Order> createOrders(int idStart, int count, String idPrefix, String name, String type) {
|
||||||
|
List<Order> orders = new ArrayList<>();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
|
||||||
|
orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type));
|
||||||
|
}
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link ParameterBag}
|
||||||
|
*/
|
||||||
|
public static ParameterBag createParameterBag(String id, String name, String type) {
|
||||||
|
|
||||||
|
ParameterBag bag = new ParameterBag(id, name, type);
|
||||||
|
addAllParameters(bag);
|
||||||
|
return bag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the following {@link Parameter}s to the given {@link ParameterBag}:
|
||||||
|
* <ul>
|
||||||
|
* <li>BooleanParameter - true</li>
|
||||||
|
* <li>FloatParameter - 44.3</li>
|
||||||
|
* <li>IntegerParameter - 77</li>
|
||||||
|
* <li>LongParameter - 4453234566L</li>
|
||||||
|
* <li>StringParameter - "Strolch"</li>
|
||||||
|
* <li>DateParameter - 1354295525628L</li>
|
||||||
|
* <li>StringListParameter - Hello, World</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param bag
|
||||||
|
*/
|
||||||
|
public static void addAllParameters(ParameterBag bag) {
|
||||||
|
|
||||||
|
BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true);
|
||||||
|
boolParam.setIndex(1);
|
||||||
|
bag.addParameter(boolParam);
|
||||||
|
|
||||||
|
FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3);
|
||||||
|
floatParam.setIndex(2);
|
||||||
|
bag.addParameter(floatParam);
|
||||||
|
|
||||||
|
IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77);
|
||||||
|
integerParam.setIndex(3);
|
||||||
|
bag.addParameter(integerParam);
|
||||||
|
|
||||||
|
LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L);
|
||||||
|
longParam.setIndex(4);
|
||||||
|
bag.addParameter(longParam);
|
||||||
|
|
||||||
|
StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch");
|
||||||
|
stringParam.setIndex(5);
|
||||||
|
bag.addParameter(stringParam);
|
||||||
|
|
||||||
|
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L));
|
||||||
|
dateParam.setIndex(6);
|
||||||
|
bag.addParameter(dateParam);
|
||||||
|
|
||||||
|
ArrayList<String> stringList = new ArrayList<String>();
|
||||||
|
stringList.add("Hello");
|
||||||
|
stringList.add("World");
|
||||||
|
StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME,
|
||||||
|
stringList);
|
||||||
|
stringListP.setIndex(7);
|
||||||
|
bag.addParameter(stringListP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -45,253 +46,255 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
*/
|
*/
|
||||||
public abstract class ParameterizedElement extends AbstractStrolchElement {
|
public abstract class ParameterizedElement extends AbstractStrolchElement {
|
||||||
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
protected GroupedParameterizedElement parent;
|
protected GroupedParameterizedElement parent;
|
||||||
protected Map<String, Parameter<?>> parameterMap;
|
protected Map<String, Parameter<?>> parameterMap;
|
||||||
protected String type;
|
protected String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty Constructor
|
* Empty Constructor
|
||||||
*/
|
*/
|
||||||
protected ParameterizedElement() {
|
protected ParameterizedElement() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public ParameterizedElement(String id, String name, String type) {
|
public ParameterizedElement(String id, String name, String type) {
|
||||||
setId(id);
|
setId(id);
|
||||||
setName(name);
|
setName(name);
|
||||||
setType(type);
|
setType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the type of this {@link ParameterizedElement}
|
* Sets the type of this {@link ParameterizedElement}
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type the type to set
|
||||||
* the type to set
|
*/
|
||||||
*/
|
public void setType(String type) {
|
||||||
public void setType(String type) {
|
if (StringHelper.isEmpty(type)) {
|
||||||
if (StringHelper.isEmpty(type)) {
|
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
|
||||||
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
|
msg = MessageFormat.format(msg, getLocator());
|
||||||
msg = MessageFormat.format(msg, getLocator());
|
throw new StrolchException(msg);
|
||||||
throw new StrolchException(msg);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Parameter} with the given id, or null if it does not exist
|
* Returns the {@link Parameter} with the given id, or null if it does not exist
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key the id of the parameter to return
|
||||||
* the id of the parameter to return
|
*
|
||||||
*
|
* @return the {@link Parameter} with the given id, or null if it does not exist
|
||||||
* @return the {@link Parameter} with the given id, or null if it does not exist
|
*/
|
||||||
*/
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
public <T> T getParameter(String key) {
|
||||||
public <T> T getParameter(String key) {
|
if (this.parameterMap == null) {
|
||||||
if (this.parameterMap == null)
|
return null;
|
||||||
return null;
|
}
|
||||||
return (T) this.parameterMap.get(key);
|
return (T) this.parameterMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
|
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
|
||||||
*
|
*
|
||||||
* @param parameter
|
* @param parameter the {@link Parameter} to add
|
||||||
* the {@link Parameter} to add
|
*/
|
||||||
*/
|
public void addParameter(Parameter<?> parameter) {
|
||||||
public void addParameter(Parameter<?> parameter) {
|
if (this.parameterMap == null) {
|
||||||
if (this.parameterMap == null)
|
this.parameterMap = new HashMap<String, Parameter<?>>();
|
||||||
this.parameterMap = new HashMap<String, Parameter<?>>();
|
}
|
||||||
this.parameterMap.put(parameter.getId(), parameter);
|
this.parameterMap.put(parameter.getId(), parameter);
|
||||||
parameter.setParent(this);
|
parameter.setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the {@link Parameter} with the given key
|
* Removes the {@link Parameter} with the given key
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key the key of the {@link Parameter} to remove
|
||||||
* the key of the {@link Parameter} to remove
|
*
|
||||||
*
|
* @return the removed {@link Parameter}, or null if it does not exist
|
||||||
* @return the removed {@link Parameter}, or null if it does not exist
|
*/
|
||||||
*/
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
public <T> Parameter<T> removeParameter(String key) {
|
||||||
public <T> Parameter<T> removeParameter(String key) {
|
if (this.parameterMap == null) {
|
||||||
if (this.parameterMap == null)
|
return null;
|
||||||
return null;
|
}
|
||||||
return (Parameter<T>) this.parameterMap.remove(key);
|
return (Parameter<T>) this.parameterMap.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement}
|
* Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement}
|
||||||
*
|
*
|
||||||
* @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
|
* @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
|
||||||
*/
|
*/
|
||||||
public List<Parameter<?>> getParameters() {
|
public List<Parameter<?>> getParameters() {
|
||||||
if (this.parameterMap == null)
|
if (this.parameterMap == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
return new ArrayList<Parameter<?>>(this.parameterMap.values());
|
}
|
||||||
}
|
return new ArrayList<Parameter<?>>(this.parameterMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
|
* Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
|
||||||
*
|
*
|
||||||
* @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
|
* @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasParameters() {
|
public boolean hasParameters() {
|
||||||
return this.parameterMap != null && !this.parameterMap.isEmpty();
|
return this.parameterMap != null && !this.parameterMap.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
|
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key the key of the {@link Parameter} to check for
|
||||||
* the key of the {@link Parameter} to check for
|
*
|
||||||
*
|
* @return true, if the {@link Parameter} exists with the given key, false otherwise
|
||||||
* @return true, if the {@link Parameter} exists with the given key, false otherwise
|
*/
|
||||||
*/
|
public boolean hasParameter(String key) {
|
||||||
public boolean hasParameter(String key) {
|
if (this.parameterMap == null) {
|
||||||
if (this.parameterMap == null)
|
return false;
|
||||||
return false;
|
}
|
||||||
return this.parameterMap.containsKey(key);
|
return this.parameterMap.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
|
* Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
|
||||||
*
|
*
|
||||||
* @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
|
* @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
|
||||||
*/
|
*/
|
||||||
public Set<String> getParameterKeySet() {
|
public Set<String> getParameterKeySet() {
|
||||||
if (this.parameterMap == null)
|
if (this.parameterMap == null) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
return new HashSet<String>(this.parameterMap.keySet());
|
}
|
||||||
}
|
return new HashSet<String>(this.parameterMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillLocator(LocatorBuilder lb) {
|
public void fillLocator(LocatorBuilder lb) {
|
||||||
this.parent.fillLocator(lb);
|
this.parent.fillLocator(lb);
|
||||||
lb.append(this.id);
|
lb.append(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Locator getLocator() {
|
public Locator getLocator() {
|
||||||
LocatorBuilder lb = new LocatorBuilder();
|
LocatorBuilder lb = new LocatorBuilder();
|
||||||
fillLocator(lb);
|
fillLocator(lb);
|
||||||
return lb.build();
|
return lb.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fromDom(Element element) {
|
protected void fromDom(Element element) {
|
||||||
super.fromDom(element);
|
super.fromDom(element);
|
||||||
|
|
||||||
String type = element.getAttribute(Tags.TYPE);
|
String type = element.getAttribute(Tags.TYPE);
|
||||||
setType(type);
|
setType(type);
|
||||||
|
|
||||||
// add all the parameters
|
// add all the parameters
|
||||||
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
|
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
|
||||||
for (int i = 0; i < parameterElements.getLength(); i++) {
|
for (int i = 0; i < parameterElements.getLength(); i++) {
|
||||||
Element paramElement = (Element) parameterElements.item(i);
|
Element paramElement = (Element) parameterElements.item(i);
|
||||||
String paramtype = paramElement.getAttribute(Tags.TYPE);
|
String paramtype = paramElement.getAttribute(Tags.TYPE);
|
||||||
|
|
||||||
if (paramtype.equals(StringParameter.TYPE)) {
|
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype);
|
||||||
StringParameter param = new StringParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(IntegerParameter.TYPE)) {
|
|
||||||
IntegerParameter param = new IntegerParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(FloatParameter.TYPE)) {
|
|
||||||
FloatParameter param = new FloatParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(LongParameter.TYPE)) {
|
|
||||||
LongParameter param = new LongParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(DateParameter.TYPE)) {
|
|
||||||
DateParameter param = new DateParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(BooleanParameter.TYPE)) {
|
|
||||||
BooleanParameter param = new BooleanParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else if (paramtype.equals(StringListParameter.TYPE)) {
|
|
||||||
StringListParameter param = new StringListParameter(paramElement);
|
|
||||||
addParameter(param);
|
|
||||||
} else {
|
|
||||||
String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, paramtype);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (paramtype.equals(StringParameter.TYPE)) {
|
||||||
protected void fillElement(Element element) {
|
StringParameter param = new StringParameter(paramElement);
|
||||||
super.fillElement(element);
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(IntegerParameter.TYPE)) {
|
||||||
|
IntegerParameter param = new IntegerParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(FloatParameter.TYPE)) {
|
||||||
|
FloatParameter param = new FloatParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(LongParameter.TYPE)) {
|
||||||
|
LongParameter param = new LongParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(DateParameter.TYPE)) {
|
||||||
|
DateParameter param = new DateParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(BooleanParameter.TYPE)) {
|
||||||
|
BooleanParameter param = new BooleanParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else if (paramtype.equals(StringListParameter.TYPE)) {
|
||||||
|
StringListParameter param = new StringListParameter(paramElement);
|
||||||
|
addParameter(param);
|
||||||
|
} else {
|
||||||
|
String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, paramtype);
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.parameterMap != null) {
|
@Override
|
||||||
for (Parameter<?> parameter : this.parameterMap.values()) {
|
protected void fillElement(Element element) {
|
||||||
element.appendChild(parameter.toDom(element.getOwnerDocument()));
|
super.fillElement(element);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (this.parameterMap != null) {
|
||||||
protected void fillClone(StrolchElement clone) {
|
for (Parameter<?> parameter : this.parameterMap.values()) {
|
||||||
super.fillClone(clone);
|
element.appendChild(parameter.toDom(element.getOwnerDocument()));
|
||||||
ParameterizedElement peClone = (ParameterizedElement) clone;
|
}
|
||||||
peClone.setType(this.type);
|
}
|
||||||
if (this.parameterMap != null) {
|
}
|
||||||
for (Parameter<?> param : this.parameterMap.values()) {
|
|
||||||
peClone.addParameter(param.getClone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupedParameterizedElement getParent() {
|
protected void fillClone(StrolchElement clone) {
|
||||||
return this.parent;
|
super.fillClone(clone);
|
||||||
}
|
ParameterizedElement peClone = (ParameterizedElement) clone;
|
||||||
|
peClone.setType(this.type);
|
||||||
|
if (this.parameterMap != null) {
|
||||||
|
for (Parameter<?> param : this.parameterMap.values()) {
|
||||||
|
peClone.addParameter(param.getClone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Set the parent for this {@link ParameterizedElement}
|
public GroupedParameterizedElement getParent() {
|
||||||
*
|
return this.parent;
|
||||||
* @param parent
|
}
|
||||||
* the parent to set
|
|
||||||
*/
|
|
||||||
public void setParent(GroupedParameterizedElement parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public StrolchRootElement getRootElement() {
|
* Set the parent for this {@link ParameterizedElement}
|
||||||
return this.parent.getRootElement();
|
*
|
||||||
}
|
* @param parent the parent to set
|
||||||
|
*/
|
||||||
|
public void setParent(GroupedParameterizedElement parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@Override
|
||||||
@Override
|
public StrolchRootElement getRootElement() {
|
||||||
public String toString() {
|
return this.parent.getRootElement();
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
@SuppressWarnings("nls")
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
builder.append("ParameterizedElement [id=");
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(this.id);
|
|
||||||
builder.append(", name=");
|
|
||||||
builder.append(this.name);
|
|
||||||
builder.append(", type=");
|
|
||||||
builder.append(this.type);
|
|
||||||
builder.append("]");
|
|
||||||
|
|
||||||
return builder.toString();
|
builder.append("ParameterizedElement [id=");
|
||||||
}
|
builder.append(this.id);
|
||||||
|
builder.append(", name=");
|
||||||
|
builder.append(this.name);
|
||||||
|
builder.append(", type=");
|
||||||
|
builder.append(this.type);
|
||||||
|
builder.append("]");
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,105 +15,202 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
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.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 li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class Resource extends GroupedParameterizedElement implements StrolchRootElement {
|
public class Resource extends GroupedParameterizedElement implements StrolchRootElement {
|
||||||
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
/**
|
private Map<String, StrolchTimedState<?>> timedStateMap;
|
||||||
* Empty constructor
|
|
||||||
*/
|
|
||||||
public Resource() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Empty constructor
|
||||||
*
|
*/
|
||||||
* @param id
|
public Resource() {
|
||||||
* @param name
|
//
|
||||||
* @param type
|
}
|
||||||
*/
|
|
||||||
public Resource(String id, String name, String type) {
|
|
||||||
super(id, name, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DOM Constructor
|
* Default constructor
|
||||||
*
|
*
|
||||||
* @param element
|
* @param id
|
||||||
*/
|
* @param name
|
||||||
public Resource(Element element) {
|
* @param type
|
||||||
super.fromDom(element);
|
*/
|
||||||
}
|
public Resource(String id, String name, String type) {
|
||||||
|
super(id, name, type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public Element toDom(Document doc) {
|
* DOM Constructor
|
||||||
|
*
|
||||||
|
* @param element
|
||||||
|
*/
|
||||||
|
public Resource(Element element) {
|
||||||
|
super.fromDom(element);
|
||||||
|
|
||||||
Element element = doc.createElement(Tags.RESOURCE);
|
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
|
||||||
fillElement(element);
|
for (int i = 0; i < timedStateElems.getLength(); i++) {
|
||||||
|
Element timedStateElem = (Element) timedStateElems.item(i);
|
||||||
|
String typeS = timedStateElem.getAttribute(Tags.TYPE);
|
||||||
|
|
||||||
return element;
|
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (typeS.equals(FloatTimedState.TYPE)) {
|
||||||
public Resource getClone() {
|
StrolchTimedState timedState = new FloatTimedState(timedStateElem);
|
||||||
Resource clone = new Resource();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.fillClone(clone);
|
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
|
||||||
|
if (this.timedStateMap == null) {
|
||||||
|
this.timedStateMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
return clone;
|
this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState);
|
||||||
}
|
strolchTimedState.setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
protected void fillLocator(LocatorBuilder lb) {
|
public <T extends StrolchTimedState> T getTimedState(String id) {
|
||||||
lb.append(Tags.RESOURCE).append(getType()).append(getId());
|
if (this.timedStateMap == null) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
return (T) this.timedStateMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public Locator getLocator() {
|
public <T extends StrolchTimedState> T removeTimedState(String id) {
|
||||||
LocatorBuilder lb = new LocatorBuilder();
|
if (this.timedStateMap == null) {
|
||||||
fillLocator(lb);
|
return null;
|
||||||
return lb.build();
|
}
|
||||||
}
|
return (T) this.timedStateMap.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public Set<String> getTimedStateKeySet() {
|
||||||
public StrolchElement getParent() {
|
if (this.timedStateMap == null) {
|
||||||
return null;
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
return new HashSet<>(this.timedStateMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public List<StrolchTimedState<?>> getTimedStates() {
|
||||||
public Resource getRootElement() {
|
if (this.timedStateMap == null) {
|
||||||
return this;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
return new ArrayList<>(this.timedStateMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public boolean hasTimedStates() {
|
||||||
public <T> T accept(StrolchRootElementVisitor visitor) {
|
return this.timedStateMap != null && !this.timedStateMap.isEmpty();
|
||||||
return visitor.visitResource(this);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
public boolean hasTimedState(String id) {
|
||||||
@Override
|
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
|
||||||
public String toString() {
|
}
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
@Override
|
||||||
|
public Element toDom(Document doc) {
|
||||||
|
|
||||||
builder.append("Resource [id=");
|
Element element = doc.createElement(Tags.RESOURCE);
|
||||||
builder.append(this.id);
|
fillElement(element);
|
||||||
builder.append(", name=");
|
|
||||||
builder.append(this.name);
|
|
||||||
builder.append(", type=");
|
|
||||||
builder.append(this.type);
|
|
||||||
builder.append("]");
|
|
||||||
|
|
||||||
return builder.toString();
|
if (this.timedStateMap != null) {
|
||||||
}
|
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
|
||||||
|
Element timedStateElem = state.toDom(element.getOwnerDocument());
|
||||||
|
element.appendChild(timedStateElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource getClone() {
|
||||||
|
Resource clone = new Resource();
|
||||||
|
|
||||||
|
super.fillClone(clone);
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillLocator(LocatorBuilder lb) {
|
||||||
|
lb.append(Tags.RESOURCE).append(getType()).append(getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locator getLocator() {
|
||||||
|
LocatorBuilder lb = new LocatorBuilder();
|
||||||
|
fillLocator(lb);
|
||||||
|
return lb.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchElement getParent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource getRootElement() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(StrolchRootElementVisitor visitor) {
|
||||||
|
return visitor.visitResource(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder.append("Resource [id=");
|
||||||
|
builder.append(this.id);
|
||||||
|
builder.append(", name=");
|
||||||
|
builder.append(this.name);
|
||||||
|
builder.append(", type=");
|
||||||
|
builder.append(this.type);
|
||||||
|
builder.append("]");
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,13 @@ public class Tags {
|
||||||
public static final String DATE = "Date";
|
public static final String DATE = "Date";
|
||||||
public static final String STATE = "State";
|
public static final String STATE = "State";
|
||||||
public static final String VALUE = "Value";
|
public static final String VALUE = "Value";
|
||||||
|
public static final String TIME = "Time";
|
||||||
public static final String INTERPRETATION = "Interpretation";
|
public static final String INTERPRETATION = "Interpretation";
|
||||||
public static final String UOM = "Uom";
|
public static final String UOM = "Uom";
|
||||||
public static final String HIDDEN = "Hidden";
|
public static final String HIDDEN = "Hidden";
|
||||||
public static final String INDEX = "Index";
|
public static final String INDEX = "Index";
|
||||||
public static final String PARAMETER = "Parameter";
|
public static final String PARAMETER = "Parameter";
|
||||||
|
public static final String TIMED_STATE = "TimedState";
|
||||||
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
|
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
|
||||||
public static final String RESOURCE = "Resource";
|
public static final String RESOURCE = "Resource";
|
||||||
public static final String ORDER = "Order";
|
public static final String ORDER = "Order";
|
||||||
|
|
|
@ -200,7 +200,7 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
||||||
public Locator getLocator() {
|
public Locator getLocator() {
|
||||||
LocatorBuilder lb = new LocatorBuilder();
|
LocatorBuilder lb = new LocatorBuilder();
|
||||||
this.parent.fillLocator(lb);
|
this.parent.fillLocator(lb);
|
||||||
this.fillLocator(lb);
|
fillLocator(lb);
|
||||||
return lb.build();
|
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
|
* @param change
|
||||||
* the state change to be applied
|
* 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
|
* @return the state at the given time
|
||||||
|
@ -57,4 +57,8 @@ public interface ITimedState<T extends IValue> {
|
||||||
*/
|
*/
|
||||||
ITimeVariable<T> getTimeEvolution();
|
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);
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ import li.strolch.model.timevalue.impl.TimeVariable;
|
||||||
public class TimedState<T extends IValue> implements ITimedState<T>, Serializable {
|
public class TimedState<T extends IValue> implements ITimedState<T>, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private ITimeVariable<T> timeVariable = new TimeVariable<T>();
|
private ITimeVariable<T> timeVariable = new TimeVariable<T>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +64,7 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyChange(final IValueChange<T> change) {
|
public <U extends IValueChange<T>> void applyChange(U change) {
|
||||||
this.timeVariable.applyChange(change);
|
this.timeVariable.applyChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +78,10 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
|
||||||
return this.timeVariable;
|
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> add(final T change);
|
||||||
|
|
||||||
|
ITimeValue<T> getCopy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ import java.util.Collection;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A timed variable storing a ordered sequence of {@link ITimeValue} objects
|
* A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity.
|
||||||
* modeling a time evolution of a quantity.
|
|
||||||
*
|
*
|
||||||
* @author Martin Smock <smock.martin@gmail.com>
|
* @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);
|
void setValueAt(final Long time, final T value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the latest {@link ITimeValue} whose time field is less or equal to
|
* get the latest {@link ITimeValue} whose time field is less or equal to the time given
|
||||||
* the time given
|
|
||||||
*/
|
*/
|
||||||
ITimeValue<T> getValueAt(final Long time);
|
ITimeValue<T> getValueAt(final Long time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a {@link IValueChange} propagating the change to all future
|
* Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
|
||||||
* values starting from the time of the change.
|
|
||||||
*
|
*
|
||||||
* @param change
|
* @param change
|
||||||
* the {@link IValueChange} to be applied
|
* the {@link IValueChange} to be applied
|
||||||
|
@ -56,8 +53,7 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
void applyChange(final IValueChange<T> change);
|
void applyChange(final IValueChange<T> change);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all {@link ITimeValue} objects whose time field is greater or equal
|
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time
|
||||||
* to the given time
|
|
||||||
*
|
*
|
||||||
* @param time
|
* @param time
|
||||||
* the time the sequence starts with
|
* the time the sequence starts with
|
||||||
|
@ -66,8 +62,7 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
Collection<ITimeValue<T>> getFutureValues(final Long time);
|
Collection<ITimeValue<T>> getFutureValues(final Long time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all {@link ITimeValue} objects whose time field is strictly smaller
|
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
|
||||||
* than the given time
|
|
||||||
*
|
*
|
||||||
* @param time
|
* @param time
|
||||||
* the time the sequence starts with
|
* the time the sequence starts with
|
||||||
|
@ -81,13 +76,16 @@ public interface ITimeVariable<T extends IValue> {
|
||||||
* @return a defensive copy of the {@link ITimeValue}s
|
* @return a defensive copy of the {@link ITimeValue}s
|
||||||
*/
|
*/
|
||||||
SortedSet<ITimeValue<T>> getValues();
|
SortedSet<ITimeValue<T>> getValues();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removes {@link ITimeValue} objects from the sequence, where the successor
|
* removes {@link ITimeValue} objects from the sequence, where the successor matches value. I.e considering a pair
|
||||||
* matches value. I.e considering a pair of adjacent {@link ITimeValue}
|
* of adjacent {@link ITimeValue} objects in the sequence which have the same {@link IValue}, the later one is
|
||||||
* objects in the sequence which have the same {@link IValue}, the later one
|
* removed, since it contains no additional information.
|
||||||
* is removed, since it contains no additional information.
|
|
||||||
*/
|
*/
|
||||||
void compact();
|
void compact();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a copy of this time variable
|
||||||
|
*/
|
||||||
|
ITimeVariable<T> getCopy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ package li.strolch.model.timevalue;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* any object for which a (generalized) add operation can be defined.
|
* any object for which a (generalized) add operation can be defined.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface IValue<T> {
|
public interface IValue<T> {
|
||||||
|
|
||||||
|
@ -52,5 +51,4 @@ public interface IValue<T> {
|
||||||
* @return a copy of this
|
* @return a copy of this
|
||||||
*/
|
*/
|
||||||
IValue<T> getCopy();
|
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>
|
* @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;
|
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;
|
private Double value;
|
||||||
|
|
||||||
public DoubleValue(Double value) {
|
public FloatValue(Double value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleValue(double value) {
|
public FloatValue(double value) {
|
||||||
this.value = Double.valueOf(value);
|
this.value = Double.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleValue(Integer value) {
|
public FloatValue(Integer value) {
|
||||||
this.value = this.value.doubleValue();
|
this.value = this.value.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleValue(int value) {
|
public FloatValue(int value) {
|
||||||
this.value = Integer.valueOf(value).doubleValue();
|
this.value = Integer.valueOf(value).doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleValue(String valueAsString) throws NumberFormatException {
|
public FloatValue(String valueAsString) throws NumberFormatException {
|
||||||
this.value = Double.parseDouble(valueAsString);
|
this.value = Double.parseDouble(valueAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DoubleValue add(Double o) {
|
public FloatValue add(Double o) {
|
||||||
this.value += o;
|
this.value += o;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ public class DoubleValue implements IValue<Double>, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DoubleValue getInverse() {
|
public FloatValue getInverse() {
|
||||||
return new DoubleValue(-getValue());
|
return new FloatValue(-getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DoubleValue getCopy(){
|
public FloatValue getCopy(){
|
||||||
return new DoubleValue(this.value);
|
return new FloatValue(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,7 +105,7 @@ public class DoubleValue implements IValue<Double>, Serializable {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
DoubleValue other = (DoubleValue) obj;
|
FloatValue other = (FloatValue) obj;
|
||||||
if (this.value == null) {
|
if (this.value == null) {
|
||||||
if (other.value != null)
|
if (other.value != null)
|
||||||
return false;
|
return false;
|
|
@ -15,93 +15,103 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.timevalue.impl;
|
package li.strolch.model.timevalue.impl;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object
|
* {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object
|
||||||
* does not define a inverse, a algebraic {@link AString} wrapper is used.
|
* does not define a inverse, a algebraic {@link AString} wrapper is used.
|
||||||
*
|
*
|
||||||
* @author Martin Smock <smock.martin@gmail.com>
|
* @author Martin Smock <smock.martin@gmail.com>
|
||||||
*/
|
*/
|
||||||
public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static Set<AString> neu = Collections.emptySet();
|
private static Set<AString> neu = Collections.emptySet();
|
||||||
public static final IValue<Set<AString>> NEUTRAL = new StringSetValue(neu);
|
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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringSetValue(final Set<AString> aStrings) {
|
public StringSetValue(final Set<AString> aStrings) {
|
||||||
this.aStrings = 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;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<AString> getValue() {
|
public Set<AString> getValue() {
|
||||||
return this.aStrings;
|
return this.aStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IValue<Set<AString>> add(Set<AString> o) {
|
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();) {
|
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
|
||||||
AString toAdd = iter1.next();
|
AString toAdd = iter1.next();
|
||||||
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
|
if (StringHelper.isEmpty(toAdd.getString())) {
|
||||||
AString aString = iter.next();
|
throw new StrolchException("StringSetValue may not contain null values in set!");
|
||||||
boolean valueMatch = aString.getString().equals(toAdd.getString());
|
}
|
||||||
boolean compensate = (toAdd.isInverse() && !aString.isInverse())
|
|
||||||
|| (!toAdd.isInverse() && aString.isInverse());
|
|
||||||
if (valueMatch && compensate) {
|
|
||||||
iter.remove();
|
|
||||||
iter1.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.aStrings.addAll(toBeAdded);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
|
||||||
public boolean matches(IValue<Set<AString>> other) {
|
AString aString = iter.next();
|
||||||
return getValue().equals(other.getValue());
|
boolean valueMatch = aString.getString().equals(toAdd.getString());
|
||||||
}
|
boolean compensate = (toAdd.isInverse() && !aString.isInverse())
|
||||||
|
|| (!toAdd.isInverse() && aString.isInverse());
|
||||||
|
if (valueMatch && compensate) {
|
||||||
|
iter.remove();
|
||||||
|
iter1.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.aStrings.addAll(toBeAdded);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IValue<Set<AString>> getInverse() {
|
public boolean matches(IValue<Set<AString>> other) {
|
||||||
Set<AString> inverseSet = new HashSet<AString>();
|
return getValue().equals(other.getValue());
|
||||||
for (AString as : this.aStrings) {
|
}
|
||||||
inverseSet.add(as.getInverse());
|
|
||||||
}
|
|
||||||
StringSetValue inverse = new StringSetValue();
|
|
||||||
inverse.aStrings = inverseSet;
|
|
||||||
return inverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringSetValue getCopy() {
|
public StringSetValue getInverse() {
|
||||||
return new StringSetValue(this.aStrings);
|
Set<AString> inverseSet = new HashSet<>();
|
||||||
}
|
for (AString as : this.aStrings) {
|
||||||
|
inverseSet.add(as.getInverse());
|
||||||
|
}
|
||||||
|
StringSetValue inverse = new StringSetValue();
|
||||||
|
inverse.aStrings = inverseSet;
|
||||||
|
return inverse;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@Override
|
||||||
@Override
|
public StringSetValue getCopy() {
|
||||||
public String toString() {
|
return new StringSetValue(new HashSet<>(this.aStrings));
|
||||||
StringBuilder sb = new StringBuilder();
|
}
|
||||||
sb.append("StringSetValue [aStrings=");
|
|
||||||
sb.append(this.aStrings);
|
|
||||||
sb.append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("StringSetValue [aStrings=");
|
||||||
|
sb.append(this.aStrings);
|
||||||
|
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());
|
return this.getTime().compareTo(arg0.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public ITimeValue<T> getCopy() {
|
||||||
|
return new TimeValue<T>(time, (T) value.getCopy());
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -112,5 +118,4 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import li.strolch.model.timevalue.ITimeVariable;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
import li.strolch.model.timevalue.IValueChange;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Martin Smock <smock.martin@gmail.com>
|
* @author Martin Smock <smock.martin@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +33,7 @@ import li.strolch.model.timevalue.IValueChange;
|
||||||
public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Serializable {
|
public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public SortedSet<ITimeValue<T>> container = new TreeSet<ITimeValue<T>>();
|
public SortedSet<ITimeValue<T>> container = new TreeSet<ITimeValue<T>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,7 +70,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
TimeValue<T> picker = new TimeValue<T>(time, null);
|
TimeValue<T> picker = new TimeValue<T>(time, null);
|
||||||
return new TreeSet<ITimeValue<T>>(this.container.headSet(picker));
|
return new TreeSet<ITimeValue<T>>(this.container.headSet(picker));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<ITimeValue<T>> getValues() {
|
public SortedSet<ITimeValue<T>> getValues() {
|
||||||
return new TreeSet<ITimeValue<T>>(this.container);
|
return new TreeSet<ITimeValue<T>>(this.container);
|
||||||
|
@ -91,9 +90,10 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
this.container.add(newValue);
|
this.container.add(newValue);
|
||||||
} else if (initialValue.getTime().longValue() < change.getTime().longValue()) {
|
} else if (initialValue.getTime().longValue() < change.getTime().longValue()) {
|
||||||
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), initialValue.getValue());
|
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), initialValue.getValue());
|
||||||
newValue.add(change.getValue());
|
newValue.add(change.getValue());
|
||||||
this.container.add(newValue);
|
this.container.add(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
compact();
|
compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,15 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
|
||||||
predecessor = successor;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.model.GroupedParameterizedElement;
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
@ -26,123 +25,165 @@ import li.strolch.model.ParameterBag;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.model.parameter.Parameter;
|
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>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StrolchElementDeepEqualsVisitor {
|
public class StrolchElementDeepEqualsVisitor {
|
||||||
|
|
||||||
private List<Locator> mismatchedLocators;
|
private List<Locator> mismatchedLocators;
|
||||||
|
|
||||||
public StrolchElementDeepEqualsVisitor() {
|
public StrolchElementDeepEqualsVisitor() {
|
||||||
this.mismatchedLocators = new ArrayList<>();
|
this.mismatchedLocators = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the mismatchedLocators
|
* @return the mismatchedLocators
|
||||||
*/
|
*/
|
||||||
public List<Locator> getMismatchedLocators() {
|
public List<Locator> getMismatchedLocators() {
|
||||||
return this.mismatchedLocators;
|
return this.mismatchedLocators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEqual() {
|
public boolean isEqual() {
|
||||||
return this.mismatchedLocators.isEmpty();
|
return this.mismatchedLocators.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) {
|
protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) {
|
||||||
if (!srcElement.getName().equals(dstElement.getName()))
|
if (!srcElement.getName().equals(dstElement.getName())) {
|
||||||
this.mismatchedLocators.add(dstElement.getLocator());
|
this.mismatchedLocators.add(dstElement.getLocator());
|
||||||
if (!srcElement.getType().equals(dstElement.getType()))
|
}
|
||||||
this.mismatchedLocators.add(dstElement.getLocator());
|
if (!srcElement.getType().equals(dstElement.getType())) {
|
||||||
}
|
this.mismatchedLocators.add(dstElement.getLocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void deepEquals(Order srcOrder, Order dstOrder) {
|
protected void deepEquals(Order srcOrder, Order dstOrder) {
|
||||||
deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder);
|
deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder);
|
||||||
if (!srcOrder.getState().equals(dstOrder.getState()))
|
if (!srcOrder.getState().equals(dstOrder.getState())) {
|
||||||
this.mismatchedLocators.add(dstOrder.getLocator());
|
this.mismatchedLocators.add(dstOrder.getLocator());
|
||||||
if (!srcOrder.getDate().equals(dstOrder.getDate()))
|
}
|
||||||
this.mismatchedLocators.add(dstOrder.getLocator());
|
if (!srcOrder.getDate().equals(dstOrder.getDate())) {
|
||||||
|
this.mismatchedLocators.add(dstOrder.getLocator());
|
||||||
|
}
|
||||||
|
|
||||||
deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder);
|
deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deepEquals(Resource srcRes, Resource dstRes) {
|
protected void deepEquals(Resource srcRes, Resource dstRes) {
|
||||||
deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes);
|
deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes);
|
||||||
deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes);
|
deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes);
|
||||||
}
|
|
||||||
|
Set<String> srcTimedStateKeySet = srcRes.getTimedStateKeySet();
|
||||||
|
for (String timedStateKey : srcTimedStateKeySet) {
|
||||||
|
StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey);
|
||||||
|
|
||||||
protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) {
|
if (!dstRes.hasTimedState(timedStateKey)) {
|
||||||
Set<String> srcBagKeySet = srcElement.getParameterBagKeySet();
|
this.mismatchedLocators.add(srcTimedState.getLocator());
|
||||||
for (String bagKey : srcBagKeySet) {
|
continue;
|
||||||
ParameterBag srcBag = srcElement.getParameterBag(bagKey);
|
}
|
||||||
|
|
||||||
if (!dstElement.hasParameterBag(bagKey)) {
|
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
|
||||||
this.mismatchedLocators.add(srcBag.getLocator());
|
deepEquals(srcTimedState, dstTimedState);
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
|
Set<String> dstTimedStateKeySet = dstRes.getTimedStateKeySet();
|
||||||
deepEquals(srcBag, dstBag);
|
for (String timedStateKey : dstTimedStateKeySet) {
|
||||||
}
|
if (!srcRes.hasTimedState(timedStateKey)) {
|
||||||
|
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
|
||||||
|
this.mismatchedLocators.add(dstTimedState.getLocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> dstBagKeySet = dstElement.getParameterBagKeySet();
|
protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) {
|
||||||
for (String bagKey : dstBagKeySet) {
|
Set<String> srcBagKeySet = srcElement.getParameterBagKeySet();
|
||||||
if (!srcElement.hasParameterBag(bagKey)) {
|
for (String bagKey : srcBagKeySet) {
|
||||||
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
|
ParameterBag srcBag = srcElement.getParameterBag(bagKey);
|
||||||
this.mismatchedLocators.add(dstBag.getLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) {
|
if (!dstElement.hasParameterBag(bagKey)) {
|
||||||
deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag);
|
this.mismatchedLocators.add(srcBag.getLocator());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> srcParamKeySet = srcBag.getParameterKeySet();
|
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
|
||||||
for (String paramKey : srcParamKeySet) {
|
deepEquals(srcBag, dstBag);
|
||||||
Parameter<?> srcParam = srcBag.getParameter(paramKey);
|
}
|
||||||
if (!dstBag.hasParameter(paramKey)) {
|
|
||||||
this.mismatchedLocators.add(srcParam.getLocator());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Parameter<?> dstParam = dstBag.getParameter(paramKey);
|
Set<String> dstBagKeySet = dstElement.getParameterBagKeySet();
|
||||||
deepEquals(srcParam, dstParam);
|
for (String bagKey : dstBagKeySet) {
|
||||||
}
|
if (!srcElement.hasParameterBag(bagKey)) {
|
||||||
|
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
|
||||||
|
this.mismatchedLocators.add(dstBag.getLocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> dstParamKeySet = dstBag.getParameterKeySet();
|
protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) {
|
||||||
for (String paramKey : dstParamKeySet) {
|
deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag);
|
||||||
if (!srcBag.hasParameter(paramKey)) {
|
|
||||||
Parameter<?> dstParam = dstBag.getParameter(paramKey);
|
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void deepEquals(Parameter<?> srcParam, Parameter<?> dstParam) {
|
Set<String> srcParamKeySet = srcBag.getParameterKeySet();
|
||||||
deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam);
|
for (String paramKey : srcParamKeySet) {
|
||||||
if (!srcParam.getUom().equals(dstParam.getUom()))
|
Parameter<?> srcParam = srcBag.getParameter(paramKey);
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
if (!dstBag.hasParameter(paramKey)) {
|
||||||
if (!srcParam.getInterpretation().equals(dstParam.getInterpretation()))
|
this.mismatchedLocators.add(srcParam.getLocator());
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
continue;
|
||||||
if (srcParam.isHidden() != dstParam.isHidden())
|
}
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
|
||||||
if (srcParam.getIndex() != dstParam.getIndex())
|
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
|
||||||
|
|
||||||
if (!srcParam.getValue().equals(dstParam.getValue()))
|
Parameter<?> dstParam = dstBag.getParameter(paramKey);
|
||||||
this.mismatchedLocators.add(dstParam.getLocator());
|
deepEquals(srcParam, dstParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEqual(Order srcOrder, Order dstOrder) {
|
Set<String> dstParamKeySet = dstBag.getParameterKeySet();
|
||||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
for (String paramKey : dstParamKeySet) {
|
||||||
visitor.visit(srcOrder);
|
if (!srcBag.hasParameter(paramKey)) {
|
||||||
return visitor.isEqual();
|
Parameter<?> dstParam = dstBag.getParameter(paramKey);
|
||||||
}
|
this.mismatchedLocators.add(dstParam.getLocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isEqual(Resource srcRes, Resource dstRes) {
|
protected void deepEquals(Parameter<?> srcParam, Parameter<?> dstParam) {
|
||||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam);
|
||||||
visitor.visit(srcRes);
|
if (!srcParam.getUom().equals(dstParam.getUom())) {
|
||||||
return visitor.isEqual();
|
this.mismatchedLocators.add(dstParam.getLocator());
|
||||||
}
|
}
|
||||||
|
if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) {
|
||||||
|
this.mismatchedLocators.add(dstParam.getLocator());
|
||||||
|
}
|
||||||
|
if (srcParam.isHidden() != dstParam.isHidden()) {
|
||||||
|
this.mismatchedLocators.add(dstParam.getLocator());
|
||||||
|
}
|
||||||
|
if (srcParam.getIndex() != dstParam.getIndex()) {
|
||||||
|
this.mismatchedLocators.add(dstParam.getLocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
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(dstOrder);
|
||||||
|
return visitor.isEqual();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEqual(Resource srcRes, Resource dstRes) {
|
||||||
|
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(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.LongParameter;
|
||||||
import li.strolch.model.parameter.StringListParameter;
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
import li.strolch.model.parameter.StringParameter;
|
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.OrderDeepEqualsVisitor;
|
||||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||||
|
|
||||||
|
@ -38,99 +41,112 @@ import org.junit.Test;
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class ModelTest {
|
public class ModelTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateResource() {
|
public void shouldCreateResource() {
|
||||||
|
|
||||||
Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID);
|
ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID);
|
||||||
validateBag(bag);
|
validateBag(bag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateOrder() {
|
public void shouldCreateOrder() {
|
||||||
|
|
||||||
Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN);
|
Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN);
|
||||||
ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID);
|
ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID);
|
||||||
validateBag(bag);
|
validateBag(bag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldPerformDeepResourceEquals() {
|
public void shouldPerformDeepResourceEquals() {
|
||||||
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||||
visitor.visit(dstRes);
|
visitor.visit(dstRes);
|
||||||
assertTrue("Same Resource should be deep equal!", visitor.isEqual());
|
assertTrue("Same Resource should be deep equal!", visitor.isEqual());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailDeepResourceEquals1() {
|
public void shouldFailDeepResourceEquals1() {
|
||||||
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID);
|
ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID);
|
||||||
bag.setName("Bla bla");
|
bag.setName("Bla bla");
|
||||||
FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
|
FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
|
||||||
fParam.setValue(23434234.234);
|
fParam.setValue(23434234.234);
|
||||||
fParam.setName("Ohla");
|
fParam.setName("Ohla");
|
||||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||||
visitor.visit(dstRes);
|
visitor.visit(dstRes);
|
||||||
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
|
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
|
||||||
assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size());
|
assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldPerformDeepOrderEquals() {
|
public void shouldFailDeepResourceEquals2() {
|
||||||
Date date = new Date();
|
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN);
|
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
|
||||||
Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN);
|
BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
|
||||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE)));
|
||||||
visitor.visit(dstOrder);
|
timedState.setName("Ohla");
|
||||||
assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
public static void validateBag(ParameterBag bag) {
|
@Test
|
||||||
|
public void shouldPerformDeepOrderEquals() {
|
||||||
|
Date date = new Date();
|
||||||
|
Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN);
|
||||||
|
Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN);
|
||||||
|
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||||
|
visitor.visit(dstOrder);
|
||||||
|
assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull(bag);
|
public static void validateBag(ParameterBag bag) {
|
||||||
|
|
||||||
assertEquals(ModelGenerator.BAG_ID, bag.getId());
|
assertNotNull(bag);
|
||||||
assertEquals(ModelGenerator.BAG_NAME, bag.getName());
|
|
||||||
assertEquals(ModelGenerator.BAG_TYPE, bag.getType());
|
|
||||||
|
|
||||||
validateParams(bag);
|
assertEquals(ModelGenerator.BAG_ID, bag.getId());
|
||||||
}
|
assertEquals(ModelGenerator.BAG_NAME, bag.getName());
|
||||||
|
assertEquals(ModelGenerator.BAG_TYPE, bag.getType());
|
||||||
|
|
||||||
public static void validateParams(ParameterBag bag) {
|
validateParams(bag);
|
||||||
|
}
|
||||||
|
|
||||||
BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID);
|
public static void validateParams(ParameterBag bag) {
|
||||||
assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam);
|
|
||||||
assertEquals(true, boolParam.getValue().booleanValue());
|
|
||||||
|
|
||||||
FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
|
BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID);
|
||||||
assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam);
|
assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam);
|
||||||
assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001);
|
assertEquals(true, boolParam.getValue().booleanValue());
|
||||||
|
|
||||||
IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID);
|
FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
|
||||||
assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam);
|
assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam);
|
||||||
assertEquals(77, integerParam.getValue().intValue());
|
assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001);
|
||||||
|
|
||||||
LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID);
|
IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID);
|
||||||
assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam);
|
assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam);
|
||||||
assertEquals(4453234566L, longParam.getValue().longValue());
|
assertEquals(77, integerParam.getValue().intValue());
|
||||||
|
|
||||||
StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID);
|
LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID);
|
||||||
assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam);
|
assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam);
|
||||||
assertEquals("Strolch", stringParam.getValue());
|
assertEquals(4453234566L, longParam.getValue().longValue());
|
||||||
|
|
||||||
DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID);
|
StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID);
|
||||||
assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam);
|
assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam);
|
||||||
assertEquals(1354295525628L, dateParam.getValue().getTime());
|
assertEquals("Strolch", stringParam.getValue());
|
||||||
|
|
||||||
StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID);
|
DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID);
|
||||||
assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP);
|
assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam);
|
||||||
|
assertEquals(1354295525628L, dateParam.getValue().getTime());
|
||||||
|
|
||||||
ArrayList<String> stringList = new ArrayList<String>();
|
StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID);
|
||||||
stringList.add("Hello");
|
assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP);
|
||||||
stringList.add("World");
|
|
||||||
assertEquals(stringList, stringListP.getValue());
|
ArrayList<String> stringList = new ArrayList<>();
|
||||||
}
|
stringList.add("Hello");
|
||||||
|
stringList.add("World");
|
||||||
|
assertEquals(stringList, stringListP.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,51 +15,55 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||||
import li.strolch.model.xml.OrderToDomVisitor;
|
import li.strolch.model.xml.OrderToDomVisitor;
|
||||||
import li.strolch.model.xml.ResourceToDomVisitor;
|
import li.strolch.model.xml.ResourceToDomVisitor;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class XmlToDomTest extends ModelTest {
|
public class XmlToDomTest extends ModelTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFormatAndParseOrder() {
|
public void shouldFormatAndParseOrder() {
|
||||||
|
|
||||||
Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder");
|
Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder");
|
||||||
|
|
||||||
OrderToDomVisitor domVisitor = new OrderToDomVisitor();
|
OrderToDomVisitor domVisitor = new OrderToDomVisitor();
|
||||||
domVisitor.visit(order);
|
domVisitor.visit(order);
|
||||||
Document document = domVisitor.getDocument();
|
Document document = domVisitor.getDocument();
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Element rootElement = document.getDocumentElement();
|
||||||
Order parsedOrder = new Order(rootElement);
|
Order parsedOrder = new Order(rootElement);
|
||||||
|
|
||||||
assertTrue("To DOM and back should equal same Order!",
|
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||||
StrolchElementDeepEqualsVisitor.isEqual(order, parsedOrder));
|
visitor.visit(parsedOrder);
|
||||||
}
|
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(),
|
||||||
|
visitor.isEqual());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFormatAndParseResource() {
|
public void shouldFormatAndParseResource() {
|
||||||
|
|
||||||
Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource");
|
Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource");
|
||||||
|
|
||||||
ResourceToDomVisitor domVisitor = new ResourceToDomVisitor();
|
ResourceToDomVisitor domVisitor = new ResourceToDomVisitor();
|
||||||
domVisitor.visit(resource);
|
domVisitor.visit(resource);
|
||||||
Document document = domVisitor.getDocument();
|
Document document = domVisitor.getDocument();
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Element rootElement = document.getDocumentElement();
|
||||||
Resource parsedResource = new Resource(rootElement);
|
Resource parsedResource = new Resource(rootElement);
|
||||||
|
|
||||||
assertTrue("To DOM and back should equal same Resource!",
|
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||||
StrolchElementDeepEqualsVisitor.isEqual(resource, parsedResource));
|
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 static org.junit.Assert.assertNull;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValueChange;
|
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 li.strolch.model.timevalue.impl.ValueChange;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -28,10 +28,10 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class TimeStateTest {
|
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 FloatValue expectedValue1 = new FloatValue(Double.valueOf(100D));
|
||||||
final DoubleValue expectedValue2 = new DoubleValue(Double.valueOf(200D));
|
final FloatValue expectedValue2 = new FloatValue(Double.valueOf(200D));
|
||||||
|
|
||||||
final Long t0 = Long.valueOf(0);
|
final Long t0 = Long.valueOf(0);
|
||||||
final Long t10 = Long.valueOf(10);
|
final Long t10 = Long.valueOf(10);
|
||||||
|
@ -42,20 +42,20 @@ public class TimeStateTest {
|
||||||
@Before
|
@Before
|
||||||
public void 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);
|
this.state.applyChange(change1);
|
||||||
|
|
||||||
final ITimeValue<DoubleValue> stateAt9 = this.state.getStateAt(9L);
|
final ITimeValue<FloatValue> stateAt9 = this.state.getStateAt(9L);
|
||||||
assertNull(stateAt9);
|
assertNull(stateAt9);
|
||||||
|
|
||||||
final ITimeValue<DoubleValue> stateAt11 = this.state.getStateAt(11L);
|
final ITimeValue<FloatValue> stateAt11 = this.state.getStateAt(11L);
|
||||||
assertNotNull(stateAt11);
|
assertNotNull(stateAt11);
|
||||||
assertEquals(true, stateAt11.getValue().matches(this.expectedValue1));
|
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);
|
this.state.applyChange(change2);
|
||||||
|
|
||||||
final ITimeValue<DoubleValue> stateAt31 = this.state.getStateAt(31L);
|
final ITimeValue<FloatValue> stateAt31 = this.state.getStateAt(31L);
|
||||||
assertNotNull(stateAt31);
|
assertNotNull(stateAt31);
|
||||||
assertEquals(true, stateAt31.getValue().matches(this.expectedValue2));
|
assertEquals(true, stateAt31.getValue().matches(this.expectedValue2));
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class TimeStateTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextMatch() {
|
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);
|
assertNotNull(nextMatch);
|
||||||
assertEquals(this.t10, nextMatch.getTime());
|
assertEquals(this.t10, nextMatch.getTime());
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public class TimeStateTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetPreviousMatch() {
|
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);
|
assertNotNull(previousMatch);
|
||||||
assertEquals(this.t30, previousMatch.getTime());
|
assertEquals(this.t30, previousMatch.getTime());
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.SortedSet;
|
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.TimeVariable;
|
||||||
import li.strolch.model.timevalue.impl.ValueChange;
|
import li.strolch.model.timevalue.impl.ValueChange;
|
||||||
|
|
||||||
|
@ -35,22 +35,22 @@ public class FloatTimeVariableTest {
|
||||||
private static final Long STEP = 10L;
|
private static final Long STEP = 10L;
|
||||||
private static final Long PICK = 50L;
|
private static final Long PICK = 50L;
|
||||||
|
|
||||||
private TimeVariable<DoubleValue> timeVariable;
|
private TimeVariable<FloatValue> timeVariable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the values ascending with a difference of STEP
|
* set the values ascending with a difference of STEP
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
this.timeVariable = new TimeVariable<DoubleValue>();
|
this.timeVariable = new TimeVariable<FloatValue>();
|
||||||
for (long i = 0; i < MAX; i += STEP) {
|
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
|
@Test
|
||||||
public void testGetValueAt() {
|
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);
|
assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ public class FloatTimeVariableTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetFutureValues() {
|
public void testGetFutureValues() {
|
||||||
Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
Collection<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||||
Long expectedTime = PICK;
|
Long expectedTime = PICK;
|
||||||
Double expectedValue = PICK.doubleValue();
|
Double expectedValue = PICK.doubleValue();
|
||||||
for (ITimeValue<DoubleValue> value : futureValues) {
|
for (ITimeValue<FloatValue> value : futureValues) {
|
||||||
assertEquals(expectedTime, value.getTime());
|
assertEquals(expectedTime, value.getTime());
|
||||||
assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
|
assertTrue(value.getValue().matches(new FloatValue(expectedValue)));
|
||||||
expectedTime += STEP;
|
expectedTime += STEP;
|
||||||
expectedValue += STEP.doubleValue();
|
expectedValue += STEP.doubleValue();
|
||||||
}
|
}
|
||||||
|
@ -76,12 +76,12 @@ public class FloatTimeVariableTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetPastValues() {
|
public void testGetPastValues() {
|
||||||
Collection<ITimeValue<DoubleValue>> pastValues = this.timeVariable.getPastValues(MAX);
|
Collection<ITimeValue<FloatValue>> pastValues = this.timeVariable.getPastValues(MAX);
|
||||||
Long expectedTime = 0L;
|
Long expectedTime = 0L;
|
||||||
Double expectedValue = expectedTime.doubleValue();
|
Double expectedValue = expectedTime.doubleValue();
|
||||||
for (ITimeValue<DoubleValue> value : pastValues) {
|
for (ITimeValue<FloatValue> value : pastValues) {
|
||||||
assertEquals(expectedTime, value.getTime());
|
assertEquals(expectedTime, value.getTime());
|
||||||
assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
|
assertTrue(value.getValue().matches(new FloatValue(expectedValue)));
|
||||||
expectedTime += STEP;
|
expectedTime += STEP;
|
||||||
expectedValue += STEP.doubleValue();
|
expectedValue += STEP.doubleValue();
|
||||||
}
|
}
|
||||||
|
@ -93,17 +93,17 @@ public class FloatTimeVariableTest {
|
||||||
@Test
|
@Test
|
||||||
public void testApplyChange() {
|
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);
|
this.timeVariable.applyChange(change);
|
||||||
|
|
||||||
Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
Collection<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(PICK);
|
||||||
Long expectedTime = 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());
|
assertEquals(expectedTime, value.getTime());
|
||||||
assertTrue(expectedValue.matches(value.getValue()));
|
assertTrue(expectedValue.matches(value.getValue()));
|
||||||
expectedTime += STEP;
|
expectedTime += STEP;
|
||||||
|
@ -117,17 +117,17 @@ public class FloatTimeVariableTest {
|
||||||
@Test
|
@Test
|
||||||
public void testApply2Change() {
|
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);
|
this.timeVariable.applyChange(change);
|
||||||
|
|
||||||
ITimeValue<DoubleValue> actual = this.timeVariable.getValueAt(PICK);
|
ITimeValue<FloatValue> actual = this.timeVariable.getValueAt(PICK);
|
||||||
assertNotNull(actual);
|
assertNotNull(actual);
|
||||||
|
|
||||||
IValue<Double> expectedValue = new DoubleValue(STEP.doubleValue());
|
IValue<Double> expectedValue = new FloatValue(STEP.doubleValue());
|
||||||
assertEquals(true, actual.getValue().matches(expectedValue));
|
assertEquals(true, actual.getValue().matches(expectedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ public class FloatTimeVariableTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCompact() {
|
public void testCompact() {
|
||||||
|
|
||||||
this.timeVariable = new TimeVariable<DoubleValue>();
|
this.timeVariable = new TimeVariable<FloatValue>();
|
||||||
for (Long i = 0L; i < MAX; i += STEP) {
|
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
|
// call
|
||||||
this.timeVariable.compact();
|
this.timeVariable.compact();
|
||||||
// check
|
// check
|
||||||
SortedSet<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(0L);
|
SortedSet<ITimeValue<FloatValue>> futureValues = this.timeVariable.getFutureValues(0L);
|
||||||
assertEquals(1, futureValues.size());
|
assertEquals(1, futureValues.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.model.timevalue.impl.AString;
|
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.IntegerValue;
|
||||||
import li.strolch.model.timevalue.impl.StringSetValue;
|
import li.strolch.model.timevalue.impl.StringSetValue;
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ public class ValueTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleInverse() {
|
public void testDoubleInverse() {
|
||||||
DoubleValue value = new DoubleValue(10.0d);
|
FloatValue value = new FloatValue(10.0d);
|
||||||
DoubleValue inverse = value.getInverse();
|
FloatValue inverse = value.getInverse();
|
||||||
assertEquals(Double.valueOf(-10.0d), inverse.getValue());
|
assertEquals(Double.valueOf(-10.0d), inverse.getValue());
|
||||||
assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue());
|
assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue