[Minor] NetBeans didn't play nice... now using tabs, instead of spaces

This commit is contained in:
Robert von Burg 2014-03-24 15:35:13 +01:00
parent 396d458112
commit 95117bdf88
69 changed files with 1770 additions and 1745 deletions

View File

@ -17,7 +17,7 @@ package li.strolch.exception;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class StrolchException extends RuntimeException {

View File

@ -44,11 +44,9 @@ public abstract class AbstractStrolchElement implements StrolchElement {
/**
* Default constructor
*
* @param id
* id of this {@link StrolchElement}
* @param name
* name of this {@link StrolchElement}
*
* @param id id of this {@link StrolchElement}
* @param name name of this {@link StrolchElement}
*/
public AbstractStrolchElement(String id, String name) {
setId(id);
@ -98,15 +96,15 @@ public abstract class AbstractStrolchElement implements StrolchElement {
/**
* Used to build a {@link Locator} for this {@link StrolchElement}. It must be implemented by the concrete
* implemented as parents must first add their {@link Locator} information
*
* @param locatorBuilder
* the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator information
*
* @param locatorBuilder the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator
* information
*/
protected abstract void fillLocator(LocatorBuilder locatorBuilder);
/**
* fills the {@link StrolchElement} clone with the id, name and type
*
*
* @param clone
*/
protected void fillClone(StrolchElement clone) {
@ -122,7 +120,7 @@ public abstract class AbstractStrolchElement implements StrolchElement {
/**
* Builds the fields of this {@link StrolchElement} from a {@link Element}
*
*
* @param element
*/
protected void fromDom(Element element) {
@ -149,18 +147,23 @@ public abstract class AbstractStrolchElement implements StrolchElement {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
AbstractStrolchElement other = (AbstractStrolchElement) obj;
if (this.id == null) {
if (other.id != null)
if (other.id != null) {
return false;
} else if (!this.id.equals(other.id))
}
} else if (!this.id.equals(other.id)) {
return false;
}
return true;
}

View File

@ -49,7 +49,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Default Constructor
*
*
* @param id
* @param name
* @param type
@ -66,9 +66,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Sets the type of this {@link GroupedParameterizedElement}
*
* @param type
* the type to set
*
* @param type the type to set
*/
public void setType(String type) {
if (StringHelper.isEmpty(type)) {
@ -83,38 +82,36 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
* the {@link Parameter} or the {@link ParameterBag} does not exist
*
* @param bagKey
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
* @param paramKey
* the key of the {@link Parameter} which is to be returned
*
*
* @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
* @param paramKey the key of the {@link Parameter} which is to be returned
*
* @return the found {@link Parameter} or null if it was not found
*/
public <T> T getParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null)
if (bag == null) {
return null;
}
return bag.getParameter(paramKey);
}
/**
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
*
* @param bagKey
* the key of the {@link ParameterBag} to which the {@link Parameter} should be added
* @param parameter
* the {@link Parameter} to be added to the {@link ParameterBag}
*
* @throws StrolchException
* if the {@link ParameterBag} does not exist
*
* @param bagKey the key of the {@link ParameterBag} to which the {@link Parameter} should be added
* @param parameter the {@link Parameter} to be added to the {@link ParameterBag}
*
* @throws StrolchException if the {@link ParameterBag} does not exist
*/
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>();
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) {
String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$
@ -127,68 +124,68 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
*
* @param bagKey
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
* @param paramKey
* the key of the {@link Parameter} which is to be removed
*
*
* @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
* @param paramKey the key of the {@link Parameter} which is to be removed
*
* @return the removed {@link Parameter} or null if it did not exist
*/
public <T> Parameter<T> removeParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null)
if (bag == null) {
return null;
}
return bag.removeParameter(paramKey);
}
/**
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
*
* @param key
* the key of the {@link ParameterBag} to return
*
*
* @param key the key of the {@link ParameterBag} to return
*
* @return the {@link ParameterBag} with the given key, or null if it does not exist
*/
public ParameterBag getParameterBag(String key) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return null;
}
return this.parameterBagMap.get(key);
}
/**
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
*
* @param bag
* the {@link ParameterBag} to add
*
* @param bag the {@link ParameterBag} to add
*/
public void addParameterBag(ParameterBag bag) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>();
}
this.parameterBagMap.put(bag.getId(), bag);
bag.setParent(this);
}
/**
* Removes the {@link ParameterBag} with the given key
*
* @param key
* the key of the {@link ParameterBag} to remove
*
*
* @param key the key of the {@link ParameterBag} to remove
*
* @return the removed {@link ParameterBag}, or null if it does not exist
*/
public ParameterBag removeParameterBag(String key) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return null;
}
return this.parameterBagMap.remove(key);
}
/**
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
*
*
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
*/
public boolean hasParameterBags() {
@ -197,9 +194,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
*
* @param bagKey
* the key of the {@link ParameterBag} which is to be checked for existence
*
* @param bagKey the key of the {@link ParameterBag} which is to be checked for existence
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
*/
public boolean hasParameterBag(String bagKey) {
@ -209,34 +205,35 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
* bagKey
*
* @param bagKey
* the key of the {@link ParameterBag} on which to find the {@link Parameter}
* @param paramKey
* the key of the {@link Parameter} to be found
*
*
* @param bagKey the key of the {@link ParameterBag} on which to find the {@link Parameter}
* @param paramKey the key of the {@link Parameter} to be found
*
* @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not
* exist on the {@link ParameterBag}
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
* the {@link ParameterBag}
*/
public boolean hasParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return false;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null)
if (bag == null) {
return false;
}
return bag.hasParameter(paramKey);
}
/**
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
*
*
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
*/
public Set<String> getParameterBagKeySet() {
if (this.parameterBagMap == null)
if (this.parameterBagMap == null) {
return Collections.emptySet();
}
return new HashSet<String>(this.parameterBagMap.keySet());
}
@ -268,7 +265,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/**
* Fills {@link GroupedParameterizedElement} properties of this clone
*
*
* @param clone
*/
protected void fillClone(GroupedParameterizedElement clone) {

View File

@ -30,16 +30,16 @@ import ch.eitchnet.utils.helper.StringHelper;
* consists of a {@link List} of Strings which starting from the first value, defining the root, with the last item
* defining the objects id.
* </p>
*
*
* <p>
* When the {@link Locator} is formatted to a String, it resembles the same format as is used in Unix based files
* systems, with slashes (/), separating the different list values
* </p>
*
*
* <p>
* A {@link Locator} is always immutable, modifications return a new instance
* </p>
*
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Locator {
@ -56,27 +56,24 @@ public class Locator {
/**
* Constructs a new {@link Locator} with the given list of path elements
*
* @param pathElements
* the elements making up the {@link Locator}
*
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*
* @param pathElements the elements making up the {@link Locator}
*
* @throws StrolchException if the path is invalid, meaning has less than two elements in it
*/
public Locator(List<String> pathElements) throws StrolchException {
if (pathElements == null || pathElements.isEmpty())
if (pathElements == null || pathElements.isEmpty()) {
throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$
}
this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
}
/**
* Constructs a new {@link Locator} by parsing the given string path.
*
* @param path
* the path to parse for instantiate this {@link Locator} with elements
*
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*
* @param path the path to parse for instantiate this {@link Locator} with elements
*
* @throws StrolchException if the path is invalid, meaning has less than two elements in it
*/
public Locator(String path) throws StrolchException {
this.pathElements = Collections.unmodifiableList(parsePath(path));
@ -84,11 +81,9 @@ public class Locator {
/**
* Internal constructor to append a sub path to a constructor
*
* @param path
* the base path of the locator
* @param subPath
* the additional path
*
* @param path the base path of the locator
* @param subPath the additional path
*/
private Locator(List<String> path, List<String> subPath) {
List<String> fullPath = new ArrayList<String>();
@ -99,11 +94,9 @@ public class Locator {
/**
* Internal constructor to append a element to a constructor
*
* @param path
* the base path of the locator
* @param element
* the additional element
*
* @param path the base path of the locator
* @param element the additional element
*/
private Locator(List<String> path, String element) {
List<String> fullPath = new ArrayList<String>();
@ -114,7 +107,7 @@ public class Locator {
/**
* Returns the immutable list of path elements making up this locator
*
*
* @return the pathElements
*/
public List<String> getPathElements() {
@ -123,7 +116,7 @@ public class Locator {
/**
* Returns the number of elements which this {@link Locator} contains
*
*
* @return the number of elements which this {@link Locator} contains
*/
public int getSize() {
@ -132,10 +125,9 @@ public class Locator {
/**
* Returns a new {@link Locator} where the given sub path is appended to the locator
*
* @param subPathElements
* the sub path to append
*
*
* @param subPathElements the sub path to append
*
* @return the new locator
*/
public Locator append(List<String> subPathElements) {
@ -144,10 +136,9 @@ public class Locator {
/**
* Returns a new {@link Locator} where the given element is appended to the locator
*
* @param element
* the element to append
*
*
* @param element the element to append
*
* @return the new locator
*/
public Locator append(String element) {
@ -165,33 +156,30 @@ public class Locator {
/**
* Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR}
*
* @param path
* the path to parse
*
*
* @param path the path to parse
*
* @return the list of path elements for the list
*
* @throws StrolchException
* if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR}
*
* @throws StrolchException if the path is empty, or does not contain at least 2 elements separated by
* {@link #PATH_SEPARATOR}
*/
private List<String> parsePath(String path) throws StrolchException {
if (StringHelper.isEmpty(path))
if (StringHelper.isEmpty(path)) {
throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$
}
String[] elements = path.split(Locator.PATH_SEPARATOR);
return Arrays.asList(elements);
}
/**
* Formats the given list of path elements to a String representation of the {@link Locator}
*
* @param pathElements
* the locator elements
*
*
* @param pathElements the locator elements
*
* @return a string representation of the path elements
*
* @throws StrolchException
* if the path elements does not contain at least two items
*
* @throws StrolchException if the path elements does not contain at least two items
*/
private String formatPath(List<String> pathElements) throws StrolchException {
StringBuilder sb = new StringBuilder();
@ -200,8 +188,9 @@ public class Locator {
while (iter.hasNext()) {
String element = iter.next();
sb.append(element);
if (iter.hasNext())
if (iter.hasNext()) {
sb.append(Locator.PATH_SEPARATOR);
}
}
return sb.toString();
@ -217,26 +206,30 @@ public class Locator {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
Locator other = (Locator) obj;
if (this.pathElements == null) {
if (other.pathElements != null)
if (other.pathElements != null) {
return false;
} else if (!this.pathElements.equals(other.pathElements))
}
} else if (!this.pathElements.equals(other.pathElements)) {
return false;
}
return true;
}
/**
* Instantiates a new immutable {@link Locator} instance from the given string
*
* @param locatorPath
* the path from which to instantiate the locator
*
* @param locatorPath the path from which to instantiate the locator
* @return the immutable {@link Locator} instance
*/
public static Locator valueOf(String locatorPath) {
@ -245,10 +238,9 @@ public class Locator {
/**
* Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it
*
* @param rootElement
* the first element on the {@link Locator}
*
*
* @param rootElement the first element on the {@link Locator}
*
* @return a new {@link LocatorBuilder} instance with the given root element tag as the first element
*/
public static LocatorBuilder newBuilder(String rootElement) {
@ -258,7 +250,7 @@ public class Locator {
/**
* {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The
* {@link #append(String)} method returns itself for chain building
*
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public static class LocatorBuilder {
@ -274,10 +266,9 @@ public class Locator {
/**
* Append an element to the path
*
* @param element
* the element to add
*
*
* @param element the element to add
*
* @return this instance for chaining
*/
public LocatorBuilder append(String element) {
@ -287,7 +278,7 @@ public class Locator {
/**
* Remove the last element from the path
*
*
* @return this instance for chaining
*/
public LocatorBuilder removeLast() {
@ -297,12 +288,13 @@ public class Locator {
/**
* Creates an immutable {@link Locator} instance with the current elements
*
*
* @return a new {@link Locator} instance
*/
public Locator build() {
if (this.pathElements.isEmpty())
if (this.pathElements.isEmpty()) {
throw new StrolchException("The path elements must contain at least 1 item"); //$NON-NLS-1$
}
return new Locator(this.pathElements);
}
}

View File

@ -51,298 +51,298 @@ import li.strolch.model.timevalue.impl.ValueChange;
@SuppressWarnings("nls")
public class ModelGenerator {
public static final String PARAM_BOOLEAN_ID = "@param1";
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
public static final String PARAM_BOOLEAN_ID = "@param1";
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
public static final String PARAM_FLOAT_ID = "@param2";
public static final String PARAM_FLOAT_NAME = "Float Param";
public static final String PARAM_FLOAT_ID = "@param2";
public static final String PARAM_FLOAT_NAME = "Float Param";
public static final String PARAM_INTEGER_ID = "@param3";
public static final String PARAM_INTEGER_NAME = "Integer Param";
public static final String PARAM_INTEGER_ID = "@param3";
public static final String PARAM_INTEGER_NAME = "Integer Param";
public static final String PARAM_LONG_ID = "@param4";
public static final String PARAM_LONG_NAME = "Long Param";
public static final String PARAM_LONG_ID = "@param4";
public static final String PARAM_LONG_NAME = "Long Param";
public static final String PARAM_STRING_ID = "@param5";
public static final String PARAM_STRING_NAME = "String Param";
public static final String PARAM_STRING_ID = "@param5";
public static final String PARAM_STRING_NAME = "String Param";
public static final String PARAM_DATE_ID = "@param6";
public static final String PARAM_DATE_NAME = "Date Param";
public static final String PARAM_DATE_ID = "@param6";
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_NAME = "StringList Param";
public static final String PARAM_LIST_STRING_ID = "@param7";
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
public static final String STATE_FLOAT_ID = "@state1";
public static final String STATE_FLOAT_NAME = "Float State";
public static final String STATE_FLOAT_ID = "@state1";
public static final String STATE_FLOAT_NAME = "Float State";
public static final String STATE_INTEGER_ID = "@state2";
public static final String STATE_INTEGER_NAME = "Float State";
public static final String STATE_INTEGER_ID = "@state2";
public static final String STATE_INTEGER_NAME = "Float State";
public static final String STATE_STRING_ID = "@state3";
public static final String STATE_STRING_NAME = "Float State";
public static final String STATE_STRING_ID = "@state3";
public static final String STATE_STRING_NAME = "Float State";
public static final String STATE_BOOLEAN_ID = "@state4";
public static final String STATE_BOOLEAN_NAME = "Float State";
public static final String STATE_BOOLEAN_ID = "@state4";
public static final String STATE_BOOLEAN_NAME = "Float State";
public static final long STATE_TIME_0 = 0L;
public static final long STATE_TIME_10 = 10L;
public static final long STATE_TIME_20 = 20L;
public static final long STATE_TIME_30 = 30L;
public static final long STATE_TIME_0 = 0L;
public static final long STATE_TIME_10 = 10L;
public static final long STATE_TIME_20 = 20L;
public static final long STATE_TIME_30 = 30L;
public static final Double STATE_FLOAT_TIME_0 = 0.0D;
public static final Double STATE_FLOAT_TIME_10 = 10.0D;
public static final Double STATE_FLOAT_TIME_20 = 20.0D;
public static final Double STATE_FLOAT_TIME_30 = 30.0D;
public static final Double STATE_FLOAT_TIME_0 = 0.0D;
public static final Double STATE_FLOAT_TIME_10 = 10.0D;
public static final Double STATE_FLOAT_TIME_20 = 20.0D;
public static final Double STATE_FLOAT_TIME_30 = 30.0D;
public static final Integer STATE_INTEGER_TIME_0 = 0;
public static final Integer STATE_INTEGER_TIME_10 = 10;
public static final Integer STATE_INTEGER_TIME_20 = 20;
public static final Integer STATE_INTEGER_TIME_30 = 30;
public static final Integer STATE_INTEGER_TIME_0 = 0;
public static final Integer STATE_INTEGER_TIME_10 = 10;
public static final Integer STATE_INTEGER_TIME_20 = 20;
public static final Integer STATE_INTEGER_TIME_30 = 30;
public static final String STATE_STRING_TIME_0 = "empty";
public static final String STATE_STRING_TIME_10 = "a";
public static final String STATE_STRING_TIME_20 = "b";
public static final String STATE_STRING_TIME_30 = "c";
public static final String STATE_STRING_TIME_0 = "empty";
public static final String STATE_STRING_TIME_10 = "a";
public static final String STATE_STRING_TIME_20 = "b";
public static final String STATE_STRING_TIME_30 = "c";
public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE;
public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE;
public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
public static final String BAG_ID = "@bag01";
public static final String BAG_NAME = "Test Bag";
public static final String BAG_TYPE = "TestBag";
public static final String BAG_ID = "@bag01";
public static final String BAG_NAME = "Test Bag";
public static final String BAG_TYPE = "TestBag";
/**
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param id the id of the {@link Resource}
* @param name the name of the {@link Resource}
* @param type the type of the {@link Resource}
*
* @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);
/**
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param id the id of the {@link Resource}
* @param name the name of the {@link Resource}
* @param type the type of the {@link Resource}
*
* @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;
}
return resource;
}
/**
* Creates {@link StrolchTimedState} instances and adds them to the {@link Resource}
*
* @param resource the resource to which to addd the newly created {@link StrolchTimedState}
*/
public static void addTimedStates(Resource resource) {
/**
* Creates {@link StrolchTimedState} instances and adds them to the {@link Resource}
*
* @param resource the resource to which to addd the newly created {@link StrolchTimedState}
*/
public static void addTimedStates(Resource resource) {
// float state
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)));
FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange));
resource.addTimedState(floatTimedState);
// float state
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)));
FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange));
resource.addTimedState(floatTimedState);
// integer state
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new IntegerValue(STATE_INTEGER_TIME_0)));
IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange));
resource.addTimedState(integerTimedState);
// integer state
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new IntegerValue(STATE_INTEGER_TIME_0)));
IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange));
resource.addTimedState(integerTimedState);
// boolean state
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new BooleanValue(STATE_BOOLEAN_TIME_0)));
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
resource.addTimedState(booleanTimedState);
// boolean state
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new BooleanValue(STATE_BOOLEAN_TIME_0)));
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
resource.addTimedState(booleanTimedState);
// string state
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change));
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_10));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_20));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_30));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
resource.addTimedState(stringTimedState);
}
// string state
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change));
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_10));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_20));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_30));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
resource.addTimedState(stringTimedState);
}
private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value));
return hashSet;
}
private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value));
return hashSet;
}
private static void removeInverted(Set<AString> set) {
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
AString aString = iter.next();
if (aString.isInverse()) {
iter.remove();
}
}
}
private static void removeInverted(Set<AString> set) {
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
AString aString = iter.next();
if (aString.isInverse()) {
iter.remove();
}
}
}
/**
* Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param idStart id range start
* @param count the number of elements to create
* @param idPrefix the prefix to generate IDs for the {@link Resource Resources}
* @param name the name of the {@link Resource}
* @param type the type of the {@link Resource}
*
* @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 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}
*
* @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) {
/**
* 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);
Order order = new Order(id, name, type, date, state);
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
order.addParameterBag(bag);
return order;
}
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 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) {
/**
* 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;
}
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) {
/**
* 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);
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);
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);
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);
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);
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);
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);
}
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);
}
}

View File

@ -30,10 +30,10 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
* The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as
* Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is
* to be thought of as an object for doing something.
*
*
* In this sense, orders do not need to be verified, so all verifier chracteristics are disabled and the
* getVerifier()-method will return the null reference
*
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Order extends GroupedParameterizedElement implements StrolchRootElement {
@ -52,7 +52,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/**
* Default Constructor
*
*
* @param id
* @param name
* @param type
@ -66,7 +66,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/**
* Extended Constructor for date and {@link State}
*
*
* @param id
* @param name
* @param type
@ -82,7 +82,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/**
* DOM Constructor
*
*
* @param element
*/
public Order(Element element) {
@ -112,8 +112,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
}
/**
* @param date
* the date to set
* @param date the date to set
*/
public void setDate(Date date) {
this.date = date;
@ -127,8 +126,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
}
/**
* @param state
* the state to set
* @param state the state to set
*/
public void setState(State state) {
this.state = state;

View File

@ -22,6 +22,7 @@ import org.w3c.dom.Element;
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ParameterBag extends ParameterizedElement {
private static final long serialVersionUID = 1L;
/**
@ -33,7 +34,7 @@ public class ParameterBag extends ParameterizedElement {
/**
* Default constructor
*
*
* @param id
* @param name
* @param type
@ -44,7 +45,7 @@ public class ParameterBag extends ParameterizedElement {
/**
* DOM Constructor
*
*
* @param bagElement
*/
public ParameterBag(Element bagElement) {

View File

@ -46,255 +46,255 @@ import ch.eitchnet.utils.helper.StringHelper;
*/
public abstract class ParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
private static final long serialVersionUID = 0L;
protected GroupedParameterizedElement parent;
protected Map<String, Parameter<?>> parameterMap;
protected String type;
protected GroupedParameterizedElement parent;
protected Map<String, Parameter<?>> parameterMap;
protected String type;
/**
* Empty Constructor
*/
protected ParameterizedElement() {
//
}
/**
* Empty Constructor
*/
protected ParameterizedElement() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param type
*/
public ParameterizedElement(String id, String name, String type) {
setId(id);
setName(name);
setType(type);
}
/**
* Default Constructor
*
* @param id
* @param name
* @param type
*/
public ParameterizedElement(String id, String name, String type) {
setId(id);
setName(name);
setType(type);
}
@Override
public String getType() {
return this.type;
}
@Override
public String getType() {
return this.type;
}
/**
* Sets the type of this {@link ParameterizedElement}
*
* @param type the type to set
*/
public void setType(String type) {
if (StringHelper.isEmpty(type)) {
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg);
}
/**
* Sets the type of this {@link ParameterizedElement}
*
* @param type the type to set
*/
public void setType(String type) {
if (StringHelper.isEmpty(type)) {
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
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
*
* @param key the id of the parameter to return
*
* @return the {@link Parameter} with the given id, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> T getParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (T) this.parameterMap.get(key);
}
/**
* Returns the {@link Parameter} with the given id, or null if it does not exist
*
* @param key the id of the parameter to return
*
* @return the {@link Parameter} with the given id, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> T getParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (T) this.parameterMap.get(key);
}
/**
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
*
* @param parameter the {@link Parameter} to add
*/
public void addParameter(Parameter<?> parameter) {
if (this.parameterMap == null) {
this.parameterMap = new HashMap<String, Parameter<?>>();
}
this.parameterMap.put(parameter.getId(), parameter);
parameter.setParent(this);
}
/**
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
*
* @param parameter the {@link Parameter} to add
*/
public void addParameter(Parameter<?> parameter) {
if (this.parameterMap == null) {
this.parameterMap = new HashMap<String, Parameter<?>>();
}
this.parameterMap.put(parameter.getId(), parameter);
parameter.setParent(this);
}
/**
* Removes the {@link Parameter} with the given key
*
* @param key the key of the {@link Parameter} to remove
*
* @return the removed {@link Parameter}, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> Parameter<T> removeParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (Parameter<T>) this.parameterMap.remove(key);
}
/**
* Removes the {@link Parameter} with the given key
*
* @param key the key of the {@link Parameter} to remove
*
* @return the removed {@link Parameter}, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> Parameter<T> removeParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (Parameter<T>) this.parameterMap.remove(key);
}
/**
* 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}
*/
public List<Parameter<?>> getParameters() {
if (this.parameterMap == null) {
return Collections.emptyList();
}
return new ArrayList<Parameter<?>>(this.parameterMap.values());
}
/**
* 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}
*/
public List<Parameter<?>> getParameters() {
if (this.parameterMap == null) {
return Collections.emptyList();
}
return new ArrayList<Parameter<?>>(this.parameterMap.values());
}
/**
* 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
*/
public boolean hasParameters() {
return this.parameterMap != null && !this.parameterMap.isEmpty();
}
/**
* 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
*/
public boolean hasParameters() {
return this.parameterMap != null && !this.parameterMap.isEmpty();
}
/**
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
*
* @param key the key of the {@link Parameter} to check for
*
* @return true, if the {@link Parameter} exists with the given key, false otherwise
*/
public boolean hasParameter(String key) {
if (this.parameterMap == null) {
return false;
}
return this.parameterMap.containsKey(key);
}
/**
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
*
* @param key the key of the {@link Parameter} to check for
*
* @return true, if the {@link Parameter} exists with the given key, false otherwise
*/
public boolean hasParameter(String key) {
if (this.parameterMap == null) {
return false;
}
return this.parameterMap.containsKey(key);
}
/**
* 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}
*/
public Set<String> getParameterKeySet() {
if (this.parameterMap == null) {
return Collections.emptySet();
}
return new HashSet<String>(this.parameterMap.keySet());
}
/**
* 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}
*/
public Set<String> getParameterKeySet() {
if (this.parameterMap == null) {
return Collections.emptySet();
}
return new HashSet<String>(this.parameterMap.keySet());
}
@Override
public void fillLocator(LocatorBuilder lb) {
this.parent.fillLocator(lb);
lb.append(this.id);
}
@Override
public void fillLocator(LocatorBuilder lb) {
this.parent.fillLocator(lb);
lb.append(this.id);
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
protected void fromDom(Element element) {
super.fromDom(element);
@Override
protected void fromDom(Element element) {
super.fromDom(element);
String type = element.getAttribute(Tags.TYPE);
setType(type);
String type = element.getAttribute(Tags.TYPE);
setType(type);
// add all the parameters
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
for (int i = 0; i < parameterElements.getLength(); i++) {
Element paramElement = (Element) parameterElements.item(i);
String paramtype = paramElement.getAttribute(Tags.TYPE);
// add all the parameters
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
for (int i = 0; i < parameterElements.getLength(); i++) {
Element paramElement = (Element) parameterElements.item(i);
String paramtype = paramElement.getAttribute(Tags.TYPE);
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype);
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype);
if (paramtype.equals(StringParameter.TYPE)) {
StringParameter param = new StringParameter(paramElement);
addParameter(param);
} 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 (paramtype.equals(StringParameter.TYPE)) {
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
protected void fillElement(Element element) {
super.fillElement(element);
@Override
protected void fillElement(Element element) {
super.fillElement(element);
if (this.parameterMap != null) {
for (Parameter<?> parameter : this.parameterMap.values()) {
element.appendChild(parameter.toDom(element.getOwnerDocument()));
}
}
}
if (this.parameterMap != null) {
for (Parameter<?> parameter : this.parameterMap.values()) {
element.appendChild(parameter.toDom(element.getOwnerDocument()));
}
}
}
@Override
protected void fillClone(StrolchElement clone) {
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
protected void fillClone(StrolchElement clone) {
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
public GroupedParameterizedElement getParent() {
return this.parent;
}
@Override
public GroupedParameterizedElement getParent() {
return this.parent;
}
/**
* Set the parent for this {@link ParameterizedElement}
*
* @param parent the parent to set
*/
public void setParent(GroupedParameterizedElement parent) {
this.parent = parent;
}
/**
* Set the parent for this {@link ParameterizedElement}
*
* @param parent the parent to set
*/
public void setParent(GroupedParameterizedElement parent) {
this.parent = parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent.getRootElement();
}
@Override
public StrolchRootElement getRootElement() {
return this.parent.getRootElement();
}
@SuppressWarnings("nls")
@Override
public String toString() {
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
StringBuilder builder = new StringBuilder();
builder.append("ParameterizedElement [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", type=");
builder.append(this.type);
builder.append("]");
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();
}
return builder.toString();
}
}

View File

@ -41,176 +41,176 @@ import org.w3c.dom.NodeList;
*/
public class Resource extends GroupedParameterizedElement implements StrolchRootElement {
private static final long serialVersionUID = 0L;
private static final long serialVersionUID = 0L;
private Map<String, StrolchTimedState<?>> timedStateMap;
private Map<String, StrolchTimedState<?>> timedStateMap;
/**
* Empty constructor
*/
public Resource() {
//
}
/**
* Empty constructor
*/
public Resource() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param type
*/
public Resource(String id, String name, String type) {
super(id, name, type);
}
/**
* Default constructor
*
* @param id
* @param name
* @param type
*/
public Resource(String id, String name, String type) {
super(id, name, type);
}
/**
* DOM Constructor
*
* @param element
*/
public Resource(Element element) {
super.fromDom(element);
/**
* DOM Constructor
*
* @param element
*/
public Resource(Element element) {
super.fromDom(element);
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
for (int i = 0; i < timedStateElems.getLength(); i++) {
Element timedStateElem = (Element) timedStateElems.item(i);
String typeS = timedStateElem.getAttribute(Tags.TYPE);
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
for (int i = 0; i < timedStateElems.getLength(); i++) {
Element timedStateElem = (Element) timedStateElems.item(i);
String typeS = timedStateElem.getAttribute(Tags.TYPE);
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS);
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS);
if (typeS.equals(FloatTimedState.TYPE)) {
StrolchTimedState timedState = new FloatTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(IntegerTimedState.TYPE)) {
StrolchTimedState timedState = new IntegerTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(BooleanTimedState.TYPE)) {
StrolchTimedState timedState = new BooleanTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(StringSetTimedState.TYPE)) {
StrolchTimedState timedState = new StringSetTimedState(timedStateElem);
addTimedState(timedState);
} else {
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, typeS);
throw new StrolchException(msg);
}
}
}
if (typeS.equals(FloatTimedState.TYPE)) {
StrolchTimedState timedState = new FloatTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(IntegerTimedState.TYPE)) {
StrolchTimedState timedState = new IntegerTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(BooleanTimedState.TYPE)) {
StrolchTimedState timedState = new BooleanTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(StringSetTimedState.TYPE)) {
StrolchTimedState timedState = new StringSetTimedState(timedStateElem);
addTimedState(timedState);
} else {
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, typeS);
throw new StrolchException(msg);
}
}
}
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
if (this.timedStateMap == null) {
this.timedStateMap = new HashMap<>();
}
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
if (this.timedStateMap == null) {
this.timedStateMap = new HashMap<>();
}
this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState);
strolchTimedState.setParent(this);
}
this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState);
strolchTimedState.setParent(this);
}
@SuppressWarnings({"rawtypes", "unchecked"})
public <T extends StrolchTimedState> T getTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.get(id);
}
@SuppressWarnings({"rawtypes", "unchecked"})
public <T extends StrolchTimedState> T getTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.get(id);
}
@SuppressWarnings({"unchecked", "rawtypes"})
public <T extends StrolchTimedState> T removeTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.remove(id);
}
@SuppressWarnings({"unchecked", "rawtypes"})
public <T extends StrolchTimedState> T removeTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.remove(id);
}
public Set<String> getTimedStateKeySet() {
if (this.timedStateMap == null) {
return Collections.emptySet();
}
return new HashSet<>(this.timedStateMap.keySet());
}
public Set<String> getTimedStateKeySet() {
if (this.timedStateMap == null) {
return Collections.emptySet();
}
return new HashSet<>(this.timedStateMap.keySet());
}
public List<StrolchTimedState<?>> getTimedStates() {
if (this.timedStateMap == null) {
return Collections.emptyList();
}
return new ArrayList<>(this.timedStateMap.values());
}
public List<StrolchTimedState<?>> getTimedStates() {
if (this.timedStateMap == null) {
return Collections.emptyList();
}
return new ArrayList<>(this.timedStateMap.values());
}
public boolean hasTimedStates() {
return this.timedStateMap != null && !this.timedStateMap.isEmpty();
}
public boolean hasTimedStates() {
return this.timedStateMap != null && !this.timedStateMap.isEmpty();
}
public boolean hasTimedState(String id) {
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
}
public boolean hasTimedState(String id) {
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
}
@Override
public Element toDom(Document doc) {
@Override
public Element toDom(Document doc) {
Element element = doc.createElement(Tags.RESOURCE);
fillElement(element);
Element element = doc.createElement(Tags.RESOURCE);
fillElement(element);
if (this.timedStateMap != null) {
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
Element timedStateElem = state.toDom(element.getOwnerDocument());
element.appendChild(timedStateElem);
}
}
if (this.timedStateMap != null) {
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
Element timedStateElem = state.toDom(element.getOwnerDocument());
element.appendChild(timedStateElem);
}
}
return element;
}
return element;
}
@Override
public Resource getClone() {
Resource clone = new Resource();
@Override
public Resource getClone() {
Resource clone = new Resource();
super.fillClone(clone);
super.fillClone(clone);
return clone;
}
return clone;
}
@Override
public void fillLocator(LocatorBuilder lb) {
lb.append(Tags.RESOURCE).append(getType()).append(getId());
}
@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 Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
public StrolchElement getParent() {
return null;
}
@Override
public StrolchElement getParent() {
return null;
}
@Override
public Resource getRootElement() {
return this;
}
@Override
public Resource getRootElement() {
return this;
}
@Override
public <T> T accept(StrolchRootElementVisitor visitor) {
return visitor.visitResource(this);
}
@Override
public <T> T accept(StrolchRootElementVisitor visitor) {
return visitor.visitResource(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
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("]");
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();
}
return builder.toString();
}
}

View File

@ -20,7 +20,7 @@ import li.strolch.model.visitor.StrolchElementVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ResourceVisitor extends StrolchElementVisitor<Resource>{
public interface ResourceVisitor extends StrolchElementVisitor<Resource> {
@Override
public void visit(Resource element);

View File

@ -27,7 +27,7 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
/**
* Return the {@link Locator} for this element
*
*
* @return the {@link Locator} for this element
*/
public Locator getLocator();
@ -35,7 +35,7 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
/**
* Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface
*
*
* @param id
*/
public void setId(String id);
@ -43,53 +43,52 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
/**
* Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface
*
*
* @return
*/
public String getId();
/**
* Set the name of this {@link StrolchElement}
*
*
* @param name
*/
public void setName(String name);
/**
* Returns the name of this {@link StrolchElement}
*
*
* @return
*/
public String getName();
/**
* Set the currently set long value which defines the primary key for use in RDBM-Systems
*
*
* @param dbid
*/
public void setDbid(long dbid);
/**
* Returns the currently set long value which defines the primary key for use in RDBM-Systems
*
*
* @return
*/
public long getDbid();
/**
* Returns an {@link Element} object which is an XML representation of this object
*
* @param doc
* the document to which this element is being written. The client must not append to the document, the
* caller will perform this as needed
*
*
* @param doc the document to which this element is being written. The client must not append to the document, the
* caller will perform this as needed
*
* @return
*/
public Element toDom(Document doc);
/**
* Returns the type of this {@link StrolchElement}
*
*
* @return
*/
public String getType();
@ -100,7 +99,7 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
/**
* Return a clone of this {@link StrolchElement}
*
*
* @return
*/
public StrolchElement getClone();

View File

@ -20,7 +20,7 @@ import li.strolch.model.visitor.StrolchRootElementVisitor;
/**
* Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
* Resources} and {@link Order Orders}
*
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchRootElement extends StrolchElement {

View File

@ -25,7 +25,7 @@ public class Tags {
public static final String DATE = "Date";
public static final String STATE = "State";
public static final String VALUE = "Value";
public static final String TIME = "Time";
public static final String TIME = "Time";
public static final String INTERPRETATION = "Interpretation";
public static final String UOM = "Uom";
public static final String HIDDEN = "Hidden";

View File

@ -33,7 +33,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
* @param <T>
*/
public abstract class AbstractParameter<T> extends AbstractStrolchElement implements Parameter<T> {
@ -56,7 +56,7 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
/**
* Default constructor
*
*
* @param id
* @param name
*/
@ -134,14 +134,18 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
element.setAttribute(Tags.VALUE, getValueAsString());
if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE))
if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) {
element.setAttribute(Tags.INTERPRETATION, this.interpretation);
if (!this.uom.equals(Parameter.UOM_NONE))
}
if (!this.uom.equals(Parameter.UOM_NONE)) {
element.setAttribute(Tags.UOM, this.uom);
if (this.hidden)
}
if (this.hidden) {
element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
if (this.index != 0)
}
if (this.index != 0) {
element.setAttribute(Tags.INDEX, Integer.toString(this.index));
}
return element;
}
@ -206,12 +210,10 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
/**
* Validates that the value is legal. This is the case when it is not null in this implementation
*
* @param value
* the value to check for this parameter instance
*
* @throws StrolchException
* if the value is null
*
* @param value the value to check for this parameter instance
*
* @throws StrolchException if the value is null
*/
protected void validateValue(T value) throws StrolchException {
if (value == null) {
@ -223,7 +225,7 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
/**
* Fills the {@link Parameter} clone with the id, name, hidden, interpretation and uom
*
*
* @param clone
*/
protected void fillClone(Parameter<?> clone) {

View File

@ -44,7 +44,7 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
/**
* Default constructors
*
*
* @param id
* @param name
* @param value
@ -56,7 +56,7 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
/**
* DOM Constructor
*
*
* @param element
*/
public BooleanParameter(Element element) {

View File

@ -46,7 +46,7 @@ public class DateParameter extends AbstractParameter<Date> {
/**
* Default Constructor
*
*
* @param id
* @param name
* @param value
@ -58,7 +58,7 @@ public class DateParameter extends AbstractParameter<Date> {
/**
* DOM Constructor
*
*
* @param element
*/
public DateParameter(Element element) {

View File

@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class FloatParameter extends AbstractParameter<Double> {
@ -45,7 +45,7 @@ public class FloatParameter extends AbstractParameter<Double> {
/**
* Default constructor
*
*
* @param id
* @param name
* @param value
@ -58,7 +58,7 @@ public class FloatParameter extends AbstractParameter<Double> {
/**
* DOM Constructor
*
*
* @param element
*/
public FloatParameter(Element element) {

View File

@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class IntegerParameter extends AbstractParameter<Integer> {
@ -45,7 +45,7 @@ public class IntegerParameter extends AbstractParameter<Integer> {
/**
* Default constructor
*
*
* @param id
* @param name
* @param value
@ -57,7 +57,7 @@ public class IntegerParameter extends AbstractParameter<Integer> {
/**
* DOM Constructor
*
*
* @param element
*/
public IntegerParameter(Element element) {

View File

@ -19,7 +19,7 @@ import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface ListParameter<E> extends Parameter<List<E>> {
@ -27,18 +27,16 @@ public interface ListParameter<E> extends Parameter<List<E>> {
/**
* Adds a single value to the {@link List} of values
*
* @param value
* the value to add
*
* @param value the value to add
*/
public void addValue(E value);
/**
* Removes a single value from the {@link List} of values
*
* @param value
* the value to remove
*
*
* @param value the value to remove
*
* @return true if the value was removed, false if it did not exist
*/
public boolean removeValue(E value);

View File

@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class LongParameter extends AbstractParameter<Long> {
@ -45,7 +45,7 @@ public class LongParameter extends AbstractParameter<Long> {
/**
* Default constructor
*
*
* @param id
* @param name
* @param value
@ -57,7 +57,7 @@ public class LongParameter extends AbstractParameter<Long> {
/**
* DOM Constructor
*
*
* @param element
*/
public LongParameter(Element element) {

View File

@ -23,7 +23,7 @@ import li.strolch.model.visitor.ParameterVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface Parameter<T> extends StrolchElement {
@ -51,71 +51,70 @@ public interface Parameter<T> extends StrolchElement {
/**
* the value of the parameter as string
*
*
* @return String
*/
public String getValueAsString();
/**
* the value of the parameter
*
*
* @return
*/
public T getValue();
/**
* the value of the parameter
*
*
* @param value
*/
public void setValue(T value);
/**
* get the hidden attribute
*
*
* @return
*/
public boolean isHidden();
/**
* set the hidden attribute
*
*
* @param hidden
*/
public void setHidden(boolean hidden);
/**
* Get the UOM of this {@link Parameter}
*
*
* @return
*/
public String getUom();
/**
* Set the UOM of this {@link Parameter}
*
*
* @param uom
*/
public void setUom(String uom);
/**
* Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
*
* @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*/
public int getIndex();
/**
* Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
* @param index
* the index to set
*
* @param index the index to set
*/
public void setIndex(int index);
/**
* The {@link ParameterizedElement} parent to which this {@link Parameter} belongs
*
*
* @return
*/
public ParameterizedElement getParent();
@ -133,7 +132,7 @@ public interface Parameter<T> extends StrolchElement {
* <li>{@link Parameter#INTERPRETATION_ORDER_REF}</li>
* <li>{@link Parameter#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
*
* @return string value
*/
public String getInterpretation();
@ -146,7 +145,7 @@ public interface Parameter<T> extends StrolchElement {
* <li>{@link Parameter#INTERPRETATION_ORDER_REF}</li>
* <li>{@link Parameter#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
*
* @param interpretation
*/
public void setInterpretation(String interpretation);

View File

@ -49,7 +49,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
/**
* Default constructor
*
*
* @param id
* @param name
* @param value
@ -62,7 +62,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
/**
* DOM Constructor
*
*
* @param element
*/
public StringListParameter(Element element) {
@ -79,8 +79,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
@Override
public String getValueAsString() {
if (this.value.isEmpty())
if (this.value.isEmpty()) {
return StringHelper.EMPTY;
}
StringBuilder sb = new StringBuilder();
Iterator<String> iter = this.value.iterator();
@ -88,8 +89,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
sb.append(iter.next());
if (iter.hasNext())
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
}
}
return sb.toString();
@ -103,8 +105,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
@Override
public void setValue(List<String> value) {
validateValue(value);
if (this.value == null)
if (this.value == null) {
this.value = new ArrayList<String>(value.size());
}
this.value.clear();
this.value.addAll(value);
}
@ -141,8 +144,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
}
public static List<String> parseFromString(String value) {
if (value.isEmpty())
if (value.isEmpty()) {
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
return Arrays.asList(valueArr);

View File

@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class StringParameter extends AbstractParameter<String> {
@ -39,7 +39,7 @@ public class StringParameter extends AbstractParameter<String> {
/**
* Empty constructor
*
*
*/
public StringParameter() {
//
@ -47,7 +47,7 @@ public class StringParameter extends AbstractParameter<String> {
/**
* Default constructor
*
*
* @param id
* @param name
* @param value
@ -59,7 +59,7 @@ public class StringParameter extends AbstractParameter<String> {
/**
* DOM Constructor
*
*
* @param element
*/
public StringParameter(Element element) {

View File

@ -15,14 +15,12 @@
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface Navigation {
// marker interface
public void accept(QueryVisitor visitor);
}

View File

@ -28,8 +28,7 @@ public class NotSelection extends BooleanSelection {
}
/**
* @throws UnsupportedOperationException
* because a {@link NotSelection} can only work on a single {@link Selection}
* @throws UnsupportedOperationException because a {@link NotSelection} can only work on a single {@link Selection}
*/
@Override
public NotSelection with(Selection selection) {

View File

@ -17,7 +17,7 @@ package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor {

View File

@ -17,7 +17,7 @@ package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public abstract class OrderSelection implements Selection {
@ -25,6 +25,6 @@ public abstract class OrderSelection implements Selection {
public void accept(QueryVisitor visitor) {
accept((OrderSelectionVisitor) visitor);
}
public abstract void accept(OrderSelectionVisitor visitor);
}

View File

@ -17,7 +17,7 @@ package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor {

View File

@ -139,6 +139,7 @@ public abstract class ParameterSelection implements Selection {
}
public static class BooleanParameterSelection extends ParameterSelection {
private Boolean value;
public BooleanParameterSelection(String bagKey, String paramKey, Boolean value) {
@ -157,6 +158,7 @@ public abstract class ParameterSelection implements Selection {
}
public static class LongParameterSelection extends ParameterSelection {
private Long value;
public LongParameterSelection(String bagKey, String paramKey, Long value) {
@ -175,6 +177,7 @@ public abstract class ParameterSelection implements Selection {
}
public static class FloatParameterSelection extends ParameterSelection {
private Double value;
public FloatParameterSelection(String bagKey, String paramKey, Double value) {
@ -193,6 +196,7 @@ public abstract class ParameterSelection implements Selection {
}
public static class DateParameterSelection extends ParameterSelection {
private Date value;
public DateParameterSelection(String bagKey, String paramKey, Date value) {
@ -211,6 +215,7 @@ public abstract class ParameterSelection implements Selection {
}
public static class StringListParameterSelection extends ParameterSelection {
private List<String> value;
public StringListParameterSelection(String bagKey, String paramKey, List<String> value) {

View File

@ -25,7 +25,7 @@ import li.strolch.model.query.ParameterSelection.StringParameterSelection;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface ParameterSelectionVisitor extends QueryVisitor {

View File

@ -15,10 +15,9 @@
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface Query<T extends QueryVisitor> {

View File

@ -23,6 +23,6 @@ public interface QueryVisitor {
public void visitAnd(AndSelection andSelection);
public void visitOr(OrSelection orSelection);
public void visitNot(NotSelection notSelection);
}

View File

@ -17,7 +17,7 @@ package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor {

View File

@ -21,6 +21,5 @@ package li.strolch.model.query;
public interface Selection {
// marker interface
public void accept(QueryVisitor visitor);
}

View File

@ -19,7 +19,7 @@ import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class StateSelection {

View File

@ -17,7 +17,7 @@ package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class StrolchTypeNavigation implements Navigation {

View File

@ -32,96 +32,96 @@ import li.strolch.model.timevalue.IValueChange;
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractStrolchTimedState<T extends IValue> extends AbstractStrolchElement implements
StrolchTimedState<T> {
StrolchTimedState<T> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
protected Resource parent;
protected ITimedState<T> state;
protected Resource parent;
protected ITimedState<T> state;
public AbstractStrolchTimedState() {
this.state = new TimedState<>();
}
public AbstractStrolchTimedState() {
this.state = new TimedState<>();
}
public AbstractStrolchTimedState(String id, String name) {
super(id, name);
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> 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 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 <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 ITimeValue<T> getStateAt(Long time) {
return this.state.getStateAt(time);
}
@Override
public ITimeVariable<T> getTimeEvolution() {
return this.state.getTimeEvolution();
}
@Override
public ITimeVariable<T> getTimeEvolution() {
return this.state.getTimeEvolution();
}
@Override
public StrolchElement getParent() {
return this.parent;
}
@Override
public StrolchElement getParent() {
return this.parent;
}
@Override
public void setParent(Resource parent) {
this.parent = parent;
}
@Override
public void setParent(Resource parent) {
this.parent = parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent;
}
@Override
protected void fillLocator(LocatorBuilder locatorBuilder) {
locatorBuilder.append(Tags.TIMED_STATE);
locatorBuilder.append(getId());
}
@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();
}
@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();
}
protected void fillClone(AbstractStrolchTimedState<T> clone) {
super.fillClone(clone);
clone.state = this.state.getCopy();
}
@SuppressWarnings("nls")
@Override
public String toString() {
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
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("]");
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();
}
return builder.toString();
}
}

View File

@ -29,60 +29,60 @@ import org.w3c.dom.NodeList;
*/
public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public static final String TYPE = "BooleanState";
public static final String TYPE = "BooleanState";
public BooleanTimedState() {
super();
}
public BooleanTimedState() {
super();
}
public BooleanTimedState(String id, String name) {
super(id, name);
}
public BooleanTimedState(String id, String name) {
super(id, name);
}
public BooleanTimedState(Element element) {
super.fromDom(element);
public BooleanTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
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);
}
}
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) {
@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);
}
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;
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
BooleanTimedState clone = new BooleanTimedState();
fillClone(clone);
return clone;
}
@Override
public StrolchElement getClone() {
BooleanTimedState clone = new BooleanTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -29,60 +29,60 @@ import org.w3c.dom.NodeList;
*/
public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public static final String TYPE = "FloatState";
public static final String TYPE = "FloatState";
public FloatTimedState() {
super();
}
public FloatTimedState() {
super();
}
public FloatTimedState(String id, String name) {
super(id, name);
}
public FloatTimedState(String id, String name) {
super(id, name);
}
public FloatTimedState(Element element) {
super.fromDom(element);
public FloatTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
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);
}
}
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) {
@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);
}
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;
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
FloatTimedState clone = new FloatTimedState();
fillClone(clone);
return clone;
}
@Override
public StrolchElement getClone() {
FloatTimedState clone = new FloatTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -22,11 +22,10 @@ import li.strolch.model.timevalue.IValueChange;
/**
* A time based state characterized by a {@link IValue} object implementation.
*
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* IValue implementation representing the state at a given time
*
* @param <T> IValue implementation representing the state at a given time
*/
@SuppressWarnings("rawtypes")
public interface ITimedState<T extends IValue> {
@ -42,8 +41,7 @@ public interface ITimedState<T extends IValue> {
ITimeValue<T> getPreviousMatch(final Long time, T value);
/**
* @param change
* the state change to be applied
* @param change the state change to be applied
*/
<U extends IValueChange<T>> void applyChange(final U change);
@ -61,4 +59,4 @@ public interface ITimedState<T extends IValue> {
* @return a copy of this timed state
*/
ITimedState<T> getCopy();
}
}

View File

@ -29,60 +29,60 @@ import org.w3c.dom.NodeList;
*/
public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public static final String TYPE = "IntegerState";
public static final String TYPE = "IntegerState";
public IntegerTimedState() {
super();
}
public IntegerTimedState() {
super();
}
public IntegerTimedState(String id, String name) {
super(id, name);
}
public IntegerTimedState(String id, String name) {
super(id, name);
}
public IntegerTimedState(Element element) {
super.fromDom(element);
public IntegerTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
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);
}
}
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) {
@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);
}
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;
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
IntegerTimedState clone = new IntegerTimedState();
fillClone(clone);
return clone;
}
@Override
public StrolchElement getClone() {
IntegerTimedState clone = new IntegerTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -33,79 +33,79 @@ import org.w3c.dom.NodeList;
*/
public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValue> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public static final String TYPE = "StringSetState";
public static final String TYPE = "StringSetState";
public StringSetTimedState() {
super();
}
public StringSetTimedState() {
super();
}
public StringSetTimedState(String id, String name) {
super(id, name);
}
public StringSetTimedState(String id, String name) {
super(id, name);
}
public StringSetTimedState(Element element) {
super.fromDom(element);
public StringSetTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
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));
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()));
}
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);
}
}
StringSetValue integerValue = new StringSetValue(value);
this.state.getTimeEvolution().setValueAt(time, integerValue);
}
}
@Override
public Element toDom(Document doc) {
@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();
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();
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);
}
Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, valueAsString);
stateElement.appendChild(valueElem);
}
return stateElement;
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
StringSetTimedState clone = new StringSetTimedState();
fillClone(clone);
return clone;
}
@Override
public StrolchElement getClone() {
StringSetTimedState clone = new StringSetTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -38,5 +38,5 @@ public interface StrolchTimedState<T extends IValue> extends StrolchElement {
public ITimeVariable<T> getTimeEvolution();
public void setParent(Resource aThis);
public void setParent(Resource aThis);
}

View File

@ -19,11 +19,10 @@ import li.strolch.model.timevalue.impl.TimeVariable;
/**
* Interface for timed value objects to be used with the {@link TimeVariable}
*
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* the backing value of the timed value object
*
* @param <T> the backing value of the timed value object
*/
@SuppressWarnings("rawtypes")
public interface ITimeValue<T extends IValue> extends Comparable<ITimeValue<T>> {

View File

@ -20,22 +20,19 @@ import java.util.SortedSet;
/**
* A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity.
*
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* the backing value of the timed value object
*
* @param <T> the backing value of the timed value object
*/
@SuppressWarnings("rawtypes")
public interface ITimeVariable<T extends IValue> {
/**
* set the value at a point in time to a given time value object
*
* @param time
* the time to set the {@link IValue}
* @param value
* the {@link IValue} to set
*
* @param time the time to set the {@link IValue}
* @param value the {@link IValue} to set
*/
void setValueAt(final Long time, final T value);
@ -46,33 +43,30 @@ public interface ITimeVariable<T extends IValue> {
/**
* Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
*
* @param change
* the {@link IValueChange} to be applied
*
* @param change the {@link IValueChange} to be applied
*/
void applyChange(final IValueChange<T> change);
/**
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time
*
* @param time
* the time the sequence starts with
*
* @param time the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future
*/
Collection<ITimeValue<T>> getFutureValues(final Long time);
/**
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
*
* @param time
* the time the sequence starts with
*
* @param time the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future
*/
Collection<ITimeValue<T>> getPastValues(final Long time);
/**
* Get all {@link ITimeValue} objects
*
*
* @return a defensive copy of the {@link ITimeValue}s
*/
SortedSet<ITimeValue<T>> getValues();

View File

@ -16,13 +16,12 @@
package li.strolch.model.timevalue;
/**
* A value object defining some basic algebraic operations. Mathematically
* speaking {@link IValue} objects define a group with a addition operation.
*
* A value object defining some basic algebraic operations. Mathematically speaking {@link IValue} objects define a
* group with a addition operation.
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* any object for which a (generalized) add operation can be defined.
*
* @param <T> any object for which a (generalized) add operation can be defined.
*/
public interface IValue<T> {
@ -42,8 +41,7 @@ public interface IValue<T> {
boolean matches(IValue<T> other);
/**
* @return the inverse value, such that add(value.getInverse()) returns the
* neutral element of the group
* @return the inverse value, such that add(value.getInverse()) returns the neutral element of the group
*/
IValue<T> getInverse();

View File

@ -16,9 +16,8 @@
package li.strolch.model.timevalue;
/**
* Interface for operators to be used to change the values of {@link ITimeValue}
* in a {@link ITimeVariable}.
*
* Interface for operators to be used to change the values of {@link ITimeValue} in a {@link ITimeVariable}.
*
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
@ -35,8 +34,7 @@ public interface IValueChange<T extends IValue> {
T getValue();
/**
* @return the inverse neutralizing a change. Very useful to undo changes
* applied.
* @return the inverse neutralizing a change. Very useful to undo changes applied.
*/
IValueChange<T> getInverse();

View File

@ -18,15 +18,14 @@ package li.strolch.model.timevalue.impl;
import java.io.Serializable;
/**
* Wrapper for java.util.String object defining a inverse to support algebraic
* operations.
*
* Wrapper for java.util.String object defining a inverse to support algebraic operations.
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class AString implements Serializable {
private static final long serialVersionUID = 1L;
private final String string;
private final boolean inverse;
@ -63,20 +62,26 @@ public class AString implements Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
AString other = (AString) obj;
if (this.inverse != other.inverse)
if (this.inverse != other.inverse) {
return false;
}
if (this.string == null) {
if (other.string != null)
if (other.string != null) {
return false;
} else if (!this.string.equals(other.string))
}
} else if (!this.string.equals(other.string)) {
return false;
}
return true;
}

View File

@ -22,7 +22,7 @@ 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 {
@ -91,18 +91,23 @@ public class BooleanValue implements IValue<Boolean>, Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
BooleanValue other = (BooleanValue) obj;
if (this.value == null) {
if (other.value != null)
if (other.value != null) {
return false;
} else if (!this.value.equals(other.value))
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -22,7 +22,7 @@ import li.strolch.model.timevalue.IValue;
/**
* {@link IValue} implementation to work with Double valued {@link ITimeValue} objects
*
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class FloatValue implements IValue<Double>, Serializable {
@ -85,8 +85,8 @@ public class FloatValue implements IValue<Double>, Serializable {
}
@Override
public FloatValue getCopy(){
return new FloatValue(this.value);
public FloatValue getCopy() {
return new FloatValue(this.value);
}
@Override
@ -99,20 +99,24 @@ public class FloatValue implements IValue<Double>, Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
FloatValue other = (FloatValue) obj;
if (this.value == null) {
if (other.value != null)
if (other.value != null) {
return false;
} else if (!this.value.equals(other.value))
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -22,7 +22,7 @@ import li.strolch.model.timevalue.IValue;
/**
* {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects
*
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class IntegerValue implements IValue<Integer>, Serializable {
@ -91,18 +91,23 @@ public class IntegerValue implements IValue<Integer>, Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
IntegerValue other = (IntegerValue) obj;
if (this.value == null) {
if (other.value != null)
if (other.value != null) {
return false;
} else if (!this.value.equals(other.value))
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}

View File

@ -33,85 +33,85 @@ import li.strolch.model.timevalue.IValue;
*/
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();
public static final IValue<Set<AString>> NEUTRAL = new StringSetValue(neu);
private static Set<AString> neu = Collections.emptySet();
public static final IValue<Set<AString>> NEUTRAL = new StringSetValue(neu);
private Set<AString> aStrings = new HashSet<>();
private Set<AString> aStrings = new HashSet<>();
public StringSetValue() {
}
public StringSetValue() {
}
public StringSetValue(final Set<AString> aStrings) {
// assert no null values in set
for (AString aString : aStrings) {
if (StringHelper.isEmpty(aString.getString())) {
throw new StrolchException("StringSetValue may not contain null values in set!");
}
}
this.aStrings = aStrings;
}
public StringSetValue(final Set<AString> aStrings) {
// assert no null values in set
for (AString aString : aStrings) {
if (StringHelper.isEmpty(aString.getString())) {
throw new StrolchException("StringSetValue may not contain null values in set!");
}
}
this.aStrings = aStrings;
}
@Override
public Set<AString> getValue() {
return this.aStrings;
}
@Override
public Set<AString> getValue() {
return this.aStrings;
}
@Override
public IValue<Set<AString>> add(Set<AString> o) {
@Override
public IValue<Set<AString>> add(Set<AString> o) {
Set<AString> toBeAdded = new HashSet<>(o);
Set<AString> toBeAdded = new HashSet<>(o);
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
AString toAdd = iter1.next();
if (StringHelper.isEmpty(toAdd.getString())) {
throw new StrolchException("StringSetValue may not contain null values in set!");
}
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
AString toAdd = iter1.next();
if (StringHelper.isEmpty(toAdd.getString())) {
throw new StrolchException("StringSetValue may not contain null values in set!");
}
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
AString aString = iter.next();
boolean valueMatch = aString.getString().equals(toAdd.getString());
boolean compensate = (toAdd.isInverse() && !aString.isInverse())
|| (!toAdd.isInverse() && aString.isInverse());
if (valueMatch && compensate) {
iter.remove();
iter1.remove();
}
}
}
this.aStrings.addAll(toBeAdded);
return this;
}
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
AString aString = iter.next();
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
public boolean matches(IValue<Set<AString>> other) {
return getValue().equals(other.getValue());
}
@Override
public boolean matches(IValue<Set<AString>> other) {
return getValue().equals(other.getValue());
}
@Override
public StringSetValue getInverse() {
Set<AString> inverseSet = new HashSet<>();
for (AString as : this.aStrings) {
inverseSet.add(as.getInverse());
}
StringSetValue inverse = new StringSetValue();
inverse.aStrings = inverseSet;
return inverse;
}
@Override
public StringSetValue getInverse() {
Set<AString> inverseSet = new HashSet<>();
for (AString as : this.aStrings) {
inverseSet.add(as.getInverse());
}
StringSetValue inverse = new StringSetValue();
inverse.aStrings = inverseSet;
return inverse;
}
@Override
public StringSetValue getCopy() {
return new StringSetValue(new HashSet<>(this.aStrings));
}
@Override
public StringSetValue getCopy() {
return new StringSetValue(new HashSet<>(this.aStrings));
}
@SuppressWarnings("nls")
@Override
public String toString() {
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();
}
}

View File

@ -98,24 +98,31 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("unchecked")
TimeValue<T> other = (TimeValue<T>) obj;
if (this.time == null) {
if (other.time != null)
if (other.time != null) {
return false;
} else if (!this.time.equals(other.time))
}
} else if (!this.time.equals(other.time)) {
return false;
}
if (this.value == null) {
if (other.value != null)
if (other.value != null) {
return false;
} else if (!this.value.equals(other.value))
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -101,8 +101,9 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
@Override
public void compact() {
if (this.container.size() < 2)
if (this.container.size() < 2) {
return;
}
Iterator<ITimeValue<T>> iterator = this.container.iterator();
ITimeValue<T> predecessor = iterator.next();

View File

@ -59,23 +59,30 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
ValueChange<?> other = (ValueChange<?>) obj;
if (this.time == null) {
if (other.time != null)
if (other.time != null) {
return false;
} else if (!this.time.equals(other.time))
}
} else if (!this.time.equals(other.time)) {
return false;
}
if (this.value == null) {
if (other.value != null)
if (other.value != null) {
return false;
} else if (!this.value.equals(other.value))
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}

View File

@ -34,156 +34,156 @@ import li.strolch.model.timevalue.ITimeVariable;
*/
public class StrolchElementDeepEqualsVisitor {
private List<Locator> mismatchedLocators;
private List<Locator> mismatchedLocators;
public StrolchElementDeepEqualsVisitor() {
this.mismatchedLocators = new ArrayList<>();
}
public StrolchElementDeepEqualsVisitor() {
this.mismatchedLocators = new ArrayList<>();
}
/**
* @return the mismatchedLocators
*/
public List<Locator> getMismatchedLocators() {
return this.mismatchedLocators;
}
/**
* @return the mismatchedLocators
*/
public List<Locator> getMismatchedLocators() {
return this.mismatchedLocators;
}
public boolean isEqual() {
return this.mismatchedLocators.isEmpty();
}
public boolean isEqual() {
return this.mismatchedLocators.isEmpty();
}
protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) {
if (!srcElement.getName().equals(dstElement.getName())) {
this.mismatchedLocators.add(dstElement.getLocator());
}
if (!srcElement.getType().equals(dstElement.getType())) {
this.mismatchedLocators.add(dstElement.getLocator());
}
}
protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) {
if (!srcElement.getName().equals(dstElement.getName())) {
this.mismatchedLocators.add(dstElement.getLocator());
}
if (!srcElement.getType().equals(dstElement.getType())) {
this.mismatchedLocators.add(dstElement.getLocator());
}
}
protected void deepEquals(Order srcOrder, Order dstOrder) {
deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder);
if (!srcOrder.getState().equals(dstOrder.getState())) {
this.mismatchedLocators.add(dstOrder.getLocator());
}
if (!srcOrder.getDate().equals(dstOrder.getDate())) {
this.mismatchedLocators.add(dstOrder.getLocator());
}
protected void deepEquals(Order srcOrder, Order dstOrder) {
deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder);
if (!srcOrder.getState().equals(dstOrder.getState())) {
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) {
deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes);
deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes);
Set<String> srcTimedStateKeySet = srcRes.getTimedStateKeySet();
for (String timedStateKey : srcTimedStateKeySet) {
StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey);
protected void deepEquals(Resource srcRes, Resource dstRes) {
deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes);
deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes);
if (!dstRes.hasTimedState(timedStateKey)) {
this.mismatchedLocators.add(srcTimedState.getLocator());
continue;
}
Set<String> srcTimedStateKeySet = srcRes.getTimedStateKeySet();
for (String timedStateKey : srcTimedStateKeySet) {
StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey);
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
deepEquals(srcTimedState, dstTimedState);
}
if (!dstRes.hasTimedState(timedStateKey)) {
this.mismatchedLocators.add(srcTimedState.getLocator());
continue;
}
Set<String> dstTimedStateKeySet = dstRes.getTimedStateKeySet();
for (String timedStateKey : dstTimedStateKeySet) {
if (!srcRes.hasTimedState(timedStateKey)) {
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
this.mismatchedLocators.add(dstTimedState.getLocator());
}
}
}
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
deepEquals(srcTimedState, dstTimedState);
}
protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) {
Set<String> srcBagKeySet = srcElement.getParameterBagKeySet();
for (String bagKey : srcBagKeySet) {
ParameterBag srcBag = srcElement.getParameterBag(bagKey);
Set<String> dstTimedStateKeySet = dstRes.getTimedStateKeySet();
for (String timedStateKey : dstTimedStateKeySet) {
if (!srcRes.hasTimedState(timedStateKey)) {
StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey);
this.mismatchedLocators.add(dstTimedState.getLocator());
}
}
}
if (!dstElement.hasParameterBag(bagKey)) {
this.mismatchedLocators.add(srcBag.getLocator());
continue;
}
protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) {
Set<String> srcBagKeySet = srcElement.getParameterBagKeySet();
for (String bagKey : srcBagKeySet) {
ParameterBag srcBag = srcElement.getParameterBag(bagKey);
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
deepEquals(srcBag, dstBag);
}
if (!dstElement.hasParameterBag(bagKey)) {
this.mismatchedLocators.add(srcBag.getLocator());
continue;
}
Set<String> dstBagKeySet = dstElement.getParameterBagKeySet();
for (String bagKey : dstBagKeySet) {
if (!srcElement.hasParameterBag(bagKey)) {
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
this.mismatchedLocators.add(dstBag.getLocator());
}
}
}
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
deepEquals(srcBag, dstBag);
}
protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) {
deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag);
Set<String> dstBagKeySet = dstElement.getParameterBagKeySet();
for (String bagKey : dstBagKeySet) {
if (!srcElement.hasParameterBag(bagKey)) {
ParameterBag dstBag = dstElement.getParameterBag(bagKey);
this.mismatchedLocators.add(dstBag.getLocator());
}
}
}
Set<String> srcParamKeySet = srcBag.getParameterKeySet();
for (String paramKey : srcParamKeySet) {
Parameter<?> srcParam = srcBag.getParameter(paramKey);
if (!dstBag.hasParameter(paramKey)) {
this.mismatchedLocators.add(srcParam.getLocator());
continue;
}
protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) {
deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag);
Parameter<?> dstParam = dstBag.getParameter(paramKey);
deepEquals(srcParam, dstParam);
}
Set<String> srcParamKeySet = srcBag.getParameterKeySet();
for (String paramKey : srcParamKeySet) {
Parameter<?> srcParam = srcBag.getParameter(paramKey);
if (!dstBag.hasParameter(paramKey)) {
this.mismatchedLocators.add(srcParam.getLocator());
continue;
}
Set<String> dstParamKeySet = dstBag.getParameterKeySet();
for (String paramKey : dstParamKeySet) {
if (!srcBag.hasParameter(paramKey)) {
Parameter<?> dstParam = dstBag.getParameter(paramKey);
this.mismatchedLocators.add(dstParam.getLocator());
}
}
}
Parameter<?> dstParam = dstBag.getParameter(paramKey);
deepEquals(srcParam, dstParam);
}
protected void deepEquals(Parameter<?> srcParam, Parameter<?> dstParam) {
deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam);
if (!srcParam.getUom().equals(dstParam.getUom())) {
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());
}
Set<String> dstParamKeySet = dstBag.getParameterKeySet();
for (String paramKey : dstParamKeySet) {
if (!srcBag.hasParameter(paramKey)) {
Parameter<?> dstParam = dstBag.getParameter(paramKey);
this.mismatchedLocators.add(dstParam.getLocator());
}
}
}
if (!srcParam.getValue().equals(dstParam.getValue())) {
this.mismatchedLocators.add(dstParam.getLocator());
}
}
protected void deepEquals(Parameter<?> srcParam, Parameter<?> dstParam) {
deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam);
if (!srcParam.getUom().equals(dstParam.getUom())) {
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());
}
protected void deepEquals(StrolchTimedState<?> srcState, StrolchTimedState<?> dstState) {
deepEquals((StrolchElement) srcState, (StrolchElement) dstState);
final ITimeVariable<?> srcTimeEvolution = srcState.getTimeEvolution();
final ITimeVariable<?> dstTimeEvolution = dstState.getTimeEvolution();
if (!srcParam.getValue().equals(dstParam.getValue())) {
this.mismatchedLocators.add(dstParam.getLocator());
}
}
if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) {
this.mismatchedLocators.add(dstState.getLocator());
}
}
protected void deepEquals(StrolchTimedState<?> srcState, StrolchTimedState<?> dstState) {
deepEquals((StrolchElement) srcState, (StrolchElement) dstState);
final ITimeVariable<?> srcTimeEvolution = srcState.getTimeEvolution();
final ITimeVariable<?> dstTimeEvolution = dstState.getTimeEvolution();
public static boolean isEqual(Order srcOrder, Order dstOrder) {
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
visitor.visit(dstOrder);
return visitor.isEqual();
}
if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) {
this.mismatchedLocators.add(dstState.getLocator());
}
}
public static boolean isEqual(Resource srcRes, Resource dstRes) {
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
return visitor.isEqual();
}
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();
}
}

View File

@ -17,7 +17,7 @@ package li.strolch.model.visitor;
/**
* Marker interface to allow to quickly see the visitor implementations in Strolch
*
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchVisitor {

View File

@ -55,14 +55,16 @@ public abstract class AbstractToSaxWriterVisitor {
protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element)
throws XMLStreamException {
if (empty)
if (empty) {
this.writer.writeEmptyElement(tag);
else
} else {
this.writer.writeStartElement(tag);
}
this.writer.writeAttribute(Tags.ID, element.getId());
if (StringHelper.isNotEmpty(element.getName()))
if (StringHelper.isNotEmpty(element.getName())) {
this.writer.writeAttribute(Tags.NAME, element.getName());
}
this.writer.writeAttribute(Tags.TYPE, element.getType());
}
@ -78,14 +80,18 @@ public abstract class AbstractToSaxWriterVisitor {
for (Parameter<?> parameter : parameters) {
writeStartStrolchElement(Tags.PARAMETER, true, parameter);
if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation()))
if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) {
this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation());
if (!Parameter.UOM_NONE.equals(parameter.getUom()))
}
if (!Parameter.UOM_NONE.equals(parameter.getUom())) {
this.writer.writeAttribute(Tags.UOM, parameter.getUom());
if (parameter.isHidden())
}
if (parameter.isHidden()) {
this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden()));
if (parameter.getIndex() != 0)
}
if (parameter.getIndex() != 0) {
this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex()));
}
this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString());
}

View File

@ -31,15 +31,17 @@ public class SimpleStrolchElementListener implements StrolchElementListener {
@Override
public void notifyResource(Resource resource) {
if (this.resources == null)
if (this.resources == null) {
this.resources = new ArrayList<>();
}
this.resources.add(resource);
}
@Override
public void notifyOrder(Order order) {
if (this.orders == null)
if (this.orders == null) {
this.orders = new ArrayList<>();
}
this.orders.add(order);
}

View File

@ -20,7 +20,7 @@ import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public interface StrolchElementListener {

View File

@ -61,14 +61,18 @@ public abstract class StrolchElementToDomVisitor {
AttributesImpl attributes = attributesFor((StrolchElement) parameter);
attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString());
if (!Parameter.UOM_NONE.equals(parameter.getUom()))
if (!Parameter.UOM_NONE.equals(parameter.getUom())) {
attributes.addAttribute(null, null, Tags.UOM, Tags.CDATA, parameter.getUom());
if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation()))
}
if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) {
attributes.addAttribute(null, null, Tags.INTERPRETATION, Tags.CDATA, parameter.getInterpretation());
if (parameter.isHidden())
}
if (parameter.isHidden()) {
attributes.addAttribute(null, null, Tags.HIDDEN, Tags.CDATA, Boolean.toString(parameter.isHidden()));
if (parameter.getIndex() != 0)
}
if (parameter.getIndex() != 0) {
attributes.addAttribute(null, null, Tags.INDEX, Tags.CDATA, Integer.toString(parameter.getIndex()));
}
return attributes;
}

View File

@ -34,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
public class XmlModelSaxFileReader extends XmlModelSaxReader {
@ -54,27 +54,28 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader {
switch (qName) {
case Tags.INCLUDE_FILE:
case Tags.INCLUDE_FILE:
String includeFileS = attributes.getValue(Tags.FILE);
if (StringHelper.isEmpty(includeFileS))
throw new IllegalArgumentException(MessageFormat.format(
"The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
File includeFile = new File(this.modelFile.getParentFile(), includeFileS);
if (!includeFile.exists() || !includeFile.canRead()) {
String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS);
throw new IllegalArgumentException(msg);
}
String includeFileS = attributes.getValue(Tags.FILE);
if (StringHelper.isEmpty(includeFileS)) {
throw new IllegalArgumentException(MessageFormat.format(
"The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
}
File includeFile = new File(this.modelFile.getParentFile(), includeFileS);
if (!includeFile.exists() || !includeFile.canRead()) {
String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS);
throw new IllegalArgumentException(msg);
}
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile);
handler.parseFile();
this.statistics.nrOfOrders += handler.statistics.nrOfOrders;
this.statistics.nrOfResources += handler.statistics.nrOfResources;
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile);
handler.parseFile();
this.statistics.nrOfOrders += handler.statistics.nrOfOrders;
this.statistics.nrOfResources += handler.statistics.nrOfResources;
break;
default:
super.startElement(uri, localName, qName, attributes);
break;
default:
super.startElement(uri, localName, qName, attributes);
}
}

View File

@ -74,101 +74,100 @@ public class XmlModelSaxReader extends DefaultHandler {
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
// TODO split each root object into its own file
switch (qName) {
case Tags.STROLCH_MODEL:
break;
case Tags.STROLCH_MODEL:
break;
case Tags.RESOURCE:
case Tags.RESOURCE:
String resId = attributes.getValue(Tags.ID);
String resName = attributes.getValue(Tags.NAME);
String resType = attributes.getValue(Tags.TYPE);
Resource resource = new Resource(resId, resName, resType);
this.parameterizedElement = resource;
break;
String resId = attributes.getValue(Tags.ID);
String resName = attributes.getValue(Tags.NAME);
String resType = attributes.getValue(Tags.TYPE);
Resource resource = new Resource(resId, resName, resType);
this.parameterizedElement = resource;
break;
case Tags.ORDER:
String orderId = attributes.getValue(Tags.ID);
String orderName = attributes.getValue(Tags.NAME);
String orderType = attributes.getValue(Tags.TYPE);
String orderDateS = attributes.getValue(Tags.DATE);
String orderStateS = attributes.getValue(Tags.STATE);
Order order = new Order(orderId, orderName, orderType);
if (orderDateS != null) {
Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS);
order.setDate(orderDate);
}
if (orderStateS != null) {
State orderState = State.valueOf(orderStateS);
order.setState(orderState);
}
this.parameterizedElement = order;
break;
case Tags.PARAMETER_BAG:
String pBagId = attributes.getValue(Tags.ID);
String pBagName = attributes.getValue(Tags.NAME);
String pBagType = attributes.getValue(Tags.TYPE);
ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType);
this.pBag = pBag;
this.parameterizedElement.addParameterBag(pBag);
break;
case Tags.PARAMETER:
String paramId = attributes.getValue(Tags.ID);
String paramName = attributes.getValue(Tags.NAME);
String paramType = attributes.getValue(Tags.TYPE);
String paramValue = attributes.getValue(Tags.VALUE);
String paramHiddenS = attributes.getValue(Tags.HIDDEN);
String paramIndexS = attributes.getValue(Tags.INDEX);
try {
int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS);
boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper
.parseBoolean(paramHiddenS);
String paramUom = attributes.getValue(Tags.UOM);
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
Parameter<?> param;
switch (paramType) {
case StringParameter.TYPE:
param = new StringParameter(paramId, paramName, paramValue);
break;
case IntegerParameter.TYPE:
param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue));
break;
case BooleanParameter.TYPE:
param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue));
break;
case LongParameter.TYPE:
param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue));
break;
case DateParameter.TYPE:
param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue));
break;
case StringListParameter.TYPE:
param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue));
break;
case FloatParameter.TYPE:
param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue));
break;
default:
throw new UnsupportedOperationException(MessageFormat.format(
"Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$
case Tags.ORDER:
String orderId = attributes.getValue(Tags.ID);
String orderName = attributes.getValue(Tags.NAME);
String orderType = attributes.getValue(Tags.TYPE);
String orderDateS = attributes.getValue(Tags.DATE);
String orderStateS = attributes.getValue(Tags.STATE);
Order order = new Order(orderId, orderName, orderType);
if (orderDateS != null) {
Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS);
order.setDate(orderDate);
}
param.setHidden(paramHidden);
param.setUom(paramUom);
param.setInterpretation(paramInterpretation);
param.setIndex(index);
this.pBag.addParameter(param);
} catch (Exception e) {
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
}
break;
if (orderStateS != null) {
State orderState = State.valueOf(orderStateS);
order.setState(orderState);
}
this.parameterizedElement = order;
break;
default:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
case Tags.PARAMETER_BAG:
String pBagId = attributes.getValue(Tags.ID);
String pBagName = attributes.getValue(Tags.NAME);
String pBagType = attributes.getValue(Tags.TYPE);
ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType);
this.pBag = pBag;
this.parameterizedElement.addParameterBag(pBag);
break;
case Tags.PARAMETER:
String paramId = attributes.getValue(Tags.ID);
String paramName = attributes.getValue(Tags.NAME);
String paramType = attributes.getValue(Tags.TYPE);
String paramValue = attributes.getValue(Tags.VALUE);
String paramHiddenS = attributes.getValue(Tags.HIDDEN);
String paramIndexS = attributes.getValue(Tags.INDEX);
try {
int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS);
boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper
.parseBoolean(paramHiddenS);
String paramUom = attributes.getValue(Tags.UOM);
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
Parameter<?> param;
switch (paramType) {
case StringParameter.TYPE:
param = new StringParameter(paramId, paramName, paramValue);
break;
case IntegerParameter.TYPE:
param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue));
break;
case BooleanParameter.TYPE:
param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue));
break;
case LongParameter.TYPE:
param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue));
break;
case DateParameter.TYPE:
param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue));
break;
case StringListParameter.TYPE:
param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue));
break;
case FloatParameter.TYPE:
param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue));
break;
default:
throw new UnsupportedOperationException(MessageFormat.format(
"Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$
}
param.setHidden(paramHidden);
param.setUom(paramUom);
param.setInterpretation(paramInterpretation);
param.setIndex(index);
this.pBag.addParameter(param);
} catch (Exception e) {
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
}
break;
default:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
}
}
@ -176,31 +175,32 @@ public class XmlModelSaxReader extends DefaultHandler {
public void endElement(String uri, String localName, String qName) throws SAXException {
switch (qName) {
case Tags.STROLCH_MODEL:
break;
case Tags.RESOURCE:
this.listener.notifyResource((Resource) this.parameterizedElement);
this.statistics.nrOfResources++;
this.parameterizedElement = null;
break;
case Tags.ORDER:
this.listener.notifyOrder((Order) this.parameterizedElement);
this.statistics.nrOfOrders++;
this.parameterizedElement = null;
break;
case Tags.PARAMETER_BAG:
this.pBag = null;
break;
case Tags.PARAMETER:
break;
case Tags.INCLUDE_FILE:
break;
default:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
case Tags.STROLCH_MODEL:
break;
case Tags.RESOURCE:
this.listener.notifyResource((Resource) this.parameterizedElement);
this.statistics.nrOfResources++;
this.parameterizedElement = null;
break;
case Tags.ORDER:
this.listener.notifyOrder((Order) this.parameterizedElement);
this.statistics.nrOfOrders++;
this.parameterizedElement = null;
break;
case Tags.PARAMETER_BAG:
this.pBag = null;
break;
case Tags.PARAMETER:
break;
case Tags.INCLUDE_FILE:
break;
default:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
}
}
public static class XmlModelStatistics {
public Date startTime;
public long durationNanos;
public int nrOfResources;

View File

@ -41,112 +41,112 @@ import org.junit.Test;
@SuppressWarnings("nls")
public class ModelTest {
@Test
public void shouldCreateResource() {
@Test
public void shouldCreateResource() {
Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID);
validateBag(bag);
}
Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID);
validateBag(bag);
}
@Test
public void shouldCreateOrder() {
@Test
public void shouldCreateOrder() {
Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN);
ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID);
validateBag(bag);
}
Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN);
ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID);
validateBag(bag);
}
@Test
public void shouldPerformDeepResourceEquals() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertTrue("Same Resource should be deep equal!", visitor.isEqual());
}
@Test
public void shouldPerformDeepResourceEquals() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertTrue("Same Resource should be deep equal!", visitor.isEqual());
}
@Test
public void shouldFailDeepResourceEquals1() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID);
bag.setName("Bla bla");
FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
fParam.setValue(23434234.234);
fParam.setName("Ohla");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size());
}
@Test
public void shouldFailDeepResourceEquals1() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID);
bag.setName("Bla bla");
FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
fParam.setValue(23434234.234);
fParam.setName("Ohla");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size());
}
@Test
public void shouldFailDeepResourceEquals2() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE)));
timedState.setName("Ohla");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size());
}
@Test
public void shouldFailDeepResourceEquals2() {
Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType");
BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE)));
timedState.setName("Ohla");
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
visitor.visit(dstRes);
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size());
}
@Test
public void shouldPerformDeepOrderEquals() {
Date date = new Date();
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());
}
@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());
}
public static void validateBag(ParameterBag bag) {
public static void validateBag(ParameterBag bag) {
assertNotNull(bag);
assertNotNull(bag);
assertEquals(ModelGenerator.BAG_ID, bag.getId());
assertEquals(ModelGenerator.BAG_NAME, bag.getName());
assertEquals(ModelGenerator.BAG_TYPE, bag.getType());
assertEquals(ModelGenerator.BAG_ID, bag.getId());
assertEquals(ModelGenerator.BAG_NAME, bag.getName());
assertEquals(ModelGenerator.BAG_TYPE, bag.getType());
validateParams(bag);
}
validateParams(bag);
}
public static void validateParams(ParameterBag bag) {
public static void validateParams(ParameterBag bag) {
BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID);
assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam);
assertEquals(true, boolParam.getValue().booleanValue());
BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID);
assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam);
assertEquals(true, boolParam.getValue().booleanValue());
FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam);
assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001);
FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID);
assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam);
assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001);
IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID);
assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam);
assertEquals(77, integerParam.getValue().intValue());
IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID);
assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam);
assertEquals(77, integerParam.getValue().intValue());
LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID);
assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam);
assertEquals(4453234566L, longParam.getValue().longValue());
LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID);
assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam);
assertEquals(4453234566L, longParam.getValue().longValue());
StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID);
assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam);
assertEquals("Strolch", stringParam.getValue());
StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID);
assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam);
assertEquals("Strolch", stringParam.getValue());
DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID);
assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam);
assertEquals(1354295525628L, dateParam.getValue().getTime());
DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID);
assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam);
assertEquals(1354295525628L, dateParam.getValue().getTime());
StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID);
assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP);
StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID);
assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP);
ArrayList<String> stringList = new ArrayList<>();
stringList.add("Hello");
stringList.add("World");
assertEquals(stringList, stringListP.getValue());
}
stringList.add("Hello");
stringList.add("World");
assertEquals(stringList, stringListP.getValue());
}
}

View File

@ -33,7 +33,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*
*/
@SuppressWarnings("nls")
public class XmlModelDefaultHandlerTest {

View File

@ -31,39 +31,39 @@ import org.w3c.dom.Element;
@SuppressWarnings("nls")
public class XmlToDomTest extends ModelTest {
@Test
public void shouldFormatAndParseOrder() {
@Test
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();
domVisitor.visit(order);
Document document = domVisitor.getDocument();
OrderToDomVisitor domVisitor = new OrderToDomVisitor();
domVisitor.visit(order);
Document document = domVisitor.getDocument();
Element rootElement = document.getDocumentElement();
Order parsedOrder = new Order(rootElement);
Element rootElement = document.getDocumentElement();
Order parsedOrder = new Order(rootElement);
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
visitor.visit(parsedOrder);
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(),
visitor.isEqual());
}
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
visitor.visit(parsedOrder);
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(),
visitor.isEqual());
}
@Test
public void shouldFormatAndParseResource() {
@Test
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();
domVisitor.visit(resource);
Document document = domVisitor.getDocument();
ResourceToDomVisitor domVisitor = new ResourceToDomVisitor();
domVisitor.visit(resource);
Document document = domVisitor.getDocument();
Element rootElement = document.getDocumentElement();
Resource parsedResource = new Resource(rootElement);
Element rootElement = document.getDocumentElement();
Resource parsedResource = new Resource(rootElement);
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
visitor.visit(parsedResource);
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
visitor.isEqual());
}
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
visitor.visit(parsedResource);
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
visitor.isEqual());
}
}

View File

@ -33,85 +33,85 @@ import org.junit.Test;
*/
public class StrolchTimedStateTest {
@Test
public void testFloatState() {
@Test
public void testFloatState() {
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
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());
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> 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> 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());
}
ITimeValue<FloatValue> valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue());
}
@Test
public void testIntegerState() {
@Test
public void testIntegerState() {
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
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());
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> 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> 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());
}
ITimeValue<IntegerValue> valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue());
}
@Test
public void testBooleanState() {
@Test
public void testBooleanState() {
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
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());
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> 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> 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());
}
ITimeValue<BooleanValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue());
}
@Test
public void testStringSetState() {
@Test
public void testStringSetState() {
Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated");
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());
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> 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> 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());
}
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;
}
private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value));
return hashSet;
}
}

View File

@ -71,8 +71,7 @@ public class FloatTimeVariableTest {
}
/**
* test, that the past values time fields start with 0 and are strictly
* smaller than PICK
* test, that the past values time fields start with 0 and are strictly smaller than PICK
*/
@Test
public void testGetPastValues() {
@ -124,16 +123,15 @@ public class FloatTimeVariableTest {
IValueChange<FloatValue> change = new ValueChange<FloatValue>(PICK, doubleValue);
this.timeVariable.applyChange(change);
ITimeValue<FloatValue> actual = this.timeVariable.getValueAt(PICK);
assertNotNull(actual);
ITimeValue<FloatValue> actual = this.timeVariable.getValueAt(PICK);
assertNotNull(actual);
IValue<Double> expectedValue = new FloatValue(STEP.doubleValue());
assertEquals(true, actual.getValue().matches(expectedValue));
}
/**
* test that successors matching the values of their predecessors are
* removed
* test that successors matching the values of their predecessors are removed
*/
@Test
public void testCompact() {

View File

@ -32,7 +32,7 @@ import org.junit.Test;
/**
* Basic tests for a {@link TimeVariable} with integer values.
*
*
* @author martin_smock
*/
public class IntegerTimeVariableTest {