[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> * @author Robert von Burg <eitch@eitchnet.ch>
* *
*/ */
public class StrolchException extends RuntimeException { public class StrolchException extends RuntimeException {

View File

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

View File

@ -49,7 +49,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/** /**
* Default Constructor * Default Constructor
* *
* @param id * @param id
* @param name * @param name
* @param type * @param type
@ -66,9 +66,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/** /**
* Sets the type of this {@link GroupedParameterizedElement} * Sets the type of this {@link GroupedParameterizedElement}
* *
* @param type * @param type the type to set
* the type to set
*/ */
public void setType(String type) { public void setType(String type) {
if (StringHelper.isEmpty(type)) { if (StringHelper.isEmpty(type)) {
@ -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 * 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 * the {@link Parameter} or the {@link ParameterBag} does not exist
* *
* @param bagKey * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
* 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 paramKey *
* the key of the {@link Parameter} which is to be returned
*
* @return the found {@link Parameter} or null if it was not found * @return the found {@link Parameter} or null if it was not found
*/ */
public <T> T getParameter(String bagKey, String paramKey) { public <T> T getParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return null; return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey); ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) if (bag == null) {
return null; return null;
}
return bag.getParameter(paramKey); return bag.getParameter(paramKey);
} }
/** /**
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
* *
* @param bagKey * @param bagKey the key of the {@link ParameterBag} to which the {@link Parameter} should be added
* 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}
* @param parameter *
* the {@link Parameter} to be added to the {@link ParameterBag} * @throws StrolchException if the {@link ParameterBag} does not exist
*
* @throws StrolchException
* if the {@link ParameterBag} does not exist
*/ */
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException { public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>(); this.parameterBagMap = new HashMap<String, ParameterBag>();
}
ParameterBag bag = this.parameterBagMap.get(bagKey); ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) { if (bag == null) {
String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$ 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 * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
* *
* @param bagKey * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
* 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 paramKey *
* the key of the {@link Parameter} which is to be removed
*
* @return the removed {@link Parameter} or null if it did not exist * @return the removed {@link Parameter} or null if it did not exist
*/ */
public <T> Parameter<T> removeParameter(String bagKey, String paramKey) { public <T> Parameter<T> removeParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return null; return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey); ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) if (bag == null) {
return null; return null;
}
return bag.removeParameter(paramKey); return bag.removeParameter(paramKey);
} }
/** /**
* Returns the {@link ParameterBag} with the given key, or null if it does not exist * Returns the {@link ParameterBag} with the given key, or null if it does not exist
* *
* @param key * @param key the key of the {@link ParameterBag} to return
* the key of the {@link ParameterBag} to return *
*
* @return the {@link ParameterBag} with the given key, or null if it does not exist * @return the {@link ParameterBag} with the given key, or null if it does not exist
*/ */
public ParameterBag getParameterBag(String key) { public ParameterBag getParameterBag(String key) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return null; return null;
}
return this.parameterBagMap.get(key); return this.parameterBagMap.get(key);
} }
/** /**
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement} * Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
* *
* @param bag * @param bag the {@link ParameterBag} to add
* the {@link ParameterBag} to add
*/ */
public void addParameterBag(ParameterBag bag) { public void addParameterBag(ParameterBag bag) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>(); this.parameterBagMap = new HashMap<String, ParameterBag>();
}
this.parameterBagMap.put(bag.getId(), bag); this.parameterBagMap.put(bag.getId(), bag);
bag.setParent(this); bag.setParent(this);
} }
/** /**
* Removes the {@link ParameterBag} with the given key * Removes the {@link ParameterBag} with the given key
* *
* @param key * @param key the key of the {@link ParameterBag} to remove
* the key of the {@link ParameterBag} to remove *
*
* @return the removed {@link ParameterBag}, or null if it does not exist * @return the removed {@link ParameterBag}, or null if it does not exist
*/ */
public ParameterBag removeParameterBag(String key) { public ParameterBag removeParameterBag(String key) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return null; return null;
}
return this.parameterBagMap.remove(key); return this.parameterBagMap.remove(key);
} }
/** /**
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} * Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
* *
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} * @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
*/ */
public boolean hasParameterBags() { 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}. * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
* *
* @param bagKey * @param bagKey the key of the {@link ParameterBag} which is to be checked for existence
* 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}. * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
*/ */
public boolean hasParameterBag(String bagKey) { 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 * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
* bagKey * bagKey
* *
* @param bagKey * @param bagKey the key of the {@link ParameterBag} on which to find the {@link Parameter}
* 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 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 * @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 * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
* exist on the {@link ParameterBag} * the {@link ParameterBag}
*/ */
public boolean hasParameter(String bagKey, String paramKey) { public boolean hasParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return false; return false;
}
ParameterBag bag = this.parameterBagMap.get(bagKey); ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) if (bag == null) {
return false; return false;
}
return bag.hasParameter(paramKey); return bag.hasParameter(paramKey);
} }
/** /**
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} * 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} * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
*/ */
public Set<String> getParameterBagKeySet() { public Set<String> getParameterBagKeySet() {
if (this.parameterBagMap == null) if (this.parameterBagMap == null) {
return Collections.emptySet(); return Collections.emptySet();
}
return new HashSet<String>(this.parameterBagMap.keySet()); return new HashSet<String>(this.parameterBagMap.keySet());
} }
@ -268,7 +265,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
/** /**
* Fills {@link GroupedParameterizedElement} properties of this clone * Fills {@link GroupedParameterizedElement} properties of this clone
* *
* @param clone * @param clone
*/ */
protected void fillClone(GroupedParameterizedElement 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 * consists of a {@link List} of Strings which starting from the first value, defining the root, with the last item
* defining the objects id. * defining the objects id.
* </p> * </p>
* *
* <p> * <p>
* When the {@link Locator} is formatted to a String, it resembles the same format as is used in Unix based files * 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 * systems, with slashes (/), separating the different list values
* </p> * </p>
* *
* <p> * <p>
* A {@link Locator} is always immutable, modifications return a new instance * A {@link Locator} is always immutable, modifications return a new instance
* </p> * </p>
* *
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public class Locator { public class Locator {
@ -56,27 +56,24 @@ public class Locator {
/** /**
* Constructs a new {@link Locator} with the given list of path elements * Constructs a new {@link Locator} with the given list of path elements
* *
* @param pathElements * @param pathElements the elements making up the {@link Locator}
* the elements making up the {@link Locator} *
* * @throws StrolchException if the path is invalid, meaning has less than two elements in it
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*/ */
public Locator(List<String> pathElements) throws StrolchException { 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$ 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)); this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
} }
/** /**
* Constructs a new {@link Locator} by parsing the given string path. * Constructs a new {@link Locator} by parsing the given string path.
* *
* @param path * @param path the path to parse for instantiate this {@link Locator} with elements
* 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
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*/ */
public Locator(String path) throws StrolchException { public Locator(String path) throws StrolchException {
this.pathElements = Collections.unmodifiableList(parsePath(path)); this.pathElements = Collections.unmodifiableList(parsePath(path));
@ -84,11 +81,9 @@ public class Locator {
/** /**
* Internal constructor to append a sub path to a constructor * Internal constructor to append a sub path to a constructor
* *
* @param path * @param path the base path of the locator
* the base path of the locator * @param subPath the additional path
* @param subPath
* the additional path
*/ */
private Locator(List<String> path, List<String> subPath) { private Locator(List<String> path, List<String> subPath) {
List<String> fullPath = new ArrayList<String>(); List<String> fullPath = new ArrayList<String>();
@ -99,11 +94,9 @@ public class Locator {
/** /**
* Internal constructor to append a element to a constructor * Internal constructor to append a element to a constructor
* *
* @param path * @param path the base path of the locator
* the base path of the locator * @param element the additional element
* @param element
* the additional element
*/ */
private Locator(List<String> path, String element) { private Locator(List<String> path, String element) {
List<String> fullPath = new ArrayList<String>(); List<String> fullPath = new ArrayList<String>();
@ -114,7 +107,7 @@ public class Locator {
/** /**
* Returns the immutable list of path elements making up this locator * Returns the immutable list of path elements making up this locator
* *
* @return the pathElements * @return the pathElements
*/ */
public List<String> getPathElements() { public List<String> getPathElements() {
@ -123,7 +116,7 @@ public class Locator {
/** /**
* Returns the number of elements which this {@link Locator} contains * Returns the number of elements which this {@link Locator} contains
* *
* @return the number of elements which this {@link Locator} contains * @return the number of elements which this {@link Locator} contains
*/ */
public int getSize() { 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 * Returns a new {@link Locator} where the given sub path is appended to the locator
* *
* @param subPathElements * @param subPathElements the sub path to append
* the sub path to append *
*
* @return the new locator * @return the new locator
*/ */
public Locator append(List<String> subPathElements) { 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 * Returns a new {@link Locator} where the given element is appended to the locator
* *
* @param element * @param element the element to append
* the element to append *
*
* @return the new locator * @return the new locator
*/ */
public Locator append(String element) { 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} * Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR}
* *
* @param path * @param path the path to parse
* the path to parse *
*
* @return the list of path elements for the list * @return the list of path elements for the list
* *
* @throws StrolchException * @throws StrolchException if the path is empty, or does not contain at least 2 elements separated by
* if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR} * {@link #PATH_SEPARATOR}
*/ */
private List<String> parsePath(String path) throws StrolchException { 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$ throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$
}
String[] elements = path.split(Locator.PATH_SEPARATOR); String[] elements = path.split(Locator.PATH_SEPARATOR);
return Arrays.asList(elements); return Arrays.asList(elements);
} }
/** /**
* Formats the given list of path elements to a String representation of the {@link Locator} * Formats the given list of path elements to a String representation of the {@link Locator}
* *
* @param pathElements * @param pathElements the locator elements
* the locator elements *
*
* @return a string representation of the path elements * @return a string representation of the path elements
* *
* @throws StrolchException * @throws StrolchException if the path elements does not contain at least two items
* if the path elements does not contain at least two items
*/ */
private String formatPath(List<String> pathElements) throws StrolchException { private String formatPath(List<String> pathElements) throws StrolchException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -200,8 +188,9 @@ public class Locator {
while (iter.hasNext()) { while (iter.hasNext()) {
String element = iter.next(); String element = iter.next();
sb.append(element); sb.append(element);
if (iter.hasNext()) if (iter.hasNext()) {
sb.append(Locator.PATH_SEPARATOR); sb.append(Locator.PATH_SEPARATOR);
}
} }
return sb.toString(); return sb.toString();
@ -217,26 +206,30 @@ public class Locator {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
Locator other = (Locator) obj; Locator other = (Locator) obj;
if (this.pathElements == null) { if (this.pathElements == null) {
if (other.pathElements != null) if (other.pathElements != null) {
return false; return false;
} else if (!this.pathElements.equals(other.pathElements)) }
} else if (!this.pathElements.equals(other.pathElements)) {
return false; return false;
}
return true; return true;
} }
/** /**
* Instantiates a new immutable {@link Locator} instance from the given string * Instantiates a new immutable {@link Locator} instance from the given string
* *
* @param locatorPath * @param locatorPath the path from which to instantiate the locator
* the path from which to instantiate the locator
* @return the immutable {@link Locator} instance * @return the immutable {@link Locator} instance
*/ */
public static Locator valueOf(String locatorPath) { 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 * Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it
* *
* @param rootElement * @param rootElement the first element on the {@link Locator}
* the first element on the {@link Locator} *
*
* @return a new {@link LocatorBuilder} instance with the given root element tag as the first element * @return a new {@link LocatorBuilder} instance with the given root element tag as the first element
*/ */
public static LocatorBuilder newBuilder(String rootElement) { 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 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 * {@link #append(String)} method returns itself for chain building
* *
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public static class LocatorBuilder { public static class LocatorBuilder {
@ -274,10 +266,9 @@ public class Locator {
/** /**
* Append an element to the path * Append an element to the path
* *
* @param element * @param element the element to add
* the element to add *
*
* @return this instance for chaining * @return this instance for chaining
*/ */
public LocatorBuilder append(String element) { public LocatorBuilder append(String element) {
@ -287,7 +278,7 @@ public class Locator {
/** /**
* Remove the last element from the path * Remove the last element from the path
* *
* @return this instance for chaining * @return this instance for chaining
*/ */
public LocatorBuilder removeLast() { public LocatorBuilder removeLast() {
@ -297,12 +288,13 @@ public class Locator {
/** /**
* Creates an immutable {@link Locator} instance with the current elements * Creates an immutable {@link Locator} instance with the current elements
* *
* @return a new {@link Locator} instance * @return a new {@link Locator} instance
*/ */
public Locator build() { 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$ throw new StrolchException("The path elements must contain at least 1 item"); //$NON-NLS-1$
}
return new Locator(this.pathElements); return new Locator(this.pathElements);
} }
} }

View File

@ -51,298 +51,298 @@ import li.strolch.model.timevalue.impl.ValueChange;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ModelGenerator { public class ModelGenerator {
public static final String PARAM_BOOLEAN_ID = "@param1"; public static final String PARAM_BOOLEAN_ID = "@param1";
public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
public static final String PARAM_FLOAT_ID = "@param2"; public static final String PARAM_FLOAT_ID = "@param2";
public static final String PARAM_FLOAT_NAME = "Float Param"; public static final String PARAM_FLOAT_NAME = "Float Param";
public static final String PARAM_INTEGER_ID = "@param3"; public static final String PARAM_INTEGER_ID = "@param3";
public static final String PARAM_INTEGER_NAME = "Integer Param"; public static final String PARAM_INTEGER_NAME = "Integer Param";
public static final String PARAM_LONG_ID = "@param4"; public static final String PARAM_LONG_ID = "@param4";
public static final String PARAM_LONG_NAME = "Long Param"; public static final String PARAM_LONG_NAME = "Long Param";
public static final String PARAM_STRING_ID = "@param5"; public static final String PARAM_STRING_ID = "@param5";
public static final String PARAM_STRING_NAME = "String Param"; public static final String PARAM_STRING_NAME = "String Param";
public static final String PARAM_DATE_ID = "@param6"; public static final String PARAM_DATE_ID = "@param6";
public static final String PARAM_DATE_NAME = "Date Param"; public static final String PARAM_DATE_NAME = "Date Param";
public static final String PARAM_LIST_STRING_ID = "@param7"; public static final String PARAM_LIST_STRING_ID = "@param7";
public static final String PARAM_LIST_STRING_NAME = "StringList Param"; public static final String PARAM_LIST_STRING_NAME = "StringList Param";
public static final String STATE_FLOAT_ID = "@state1"; public static final String STATE_FLOAT_ID = "@state1";
public static final String STATE_FLOAT_NAME = "Float State"; public static final String STATE_FLOAT_NAME = "Float State";
public static final String STATE_INTEGER_ID = "@state2"; public static final String STATE_INTEGER_ID = "@state2";
public static final String STATE_INTEGER_NAME = "Float State"; public static final String STATE_INTEGER_NAME = "Float State";
public static final String STATE_STRING_ID = "@state3"; public static final String STATE_STRING_ID = "@state3";
public static final String STATE_STRING_NAME = "Float State"; public static final String STATE_STRING_NAME = "Float State";
public static final String STATE_BOOLEAN_ID = "@state4"; public static final String STATE_BOOLEAN_ID = "@state4";
public static final String STATE_BOOLEAN_NAME = "Float State"; public static final String STATE_BOOLEAN_NAME = "Float State";
public static final long STATE_TIME_0 = 0L; public static final long STATE_TIME_0 = 0L;
public static final long STATE_TIME_10 = 10L; public static final long STATE_TIME_10 = 10L;
public static final long STATE_TIME_20 = 20L; public static final long STATE_TIME_20 = 20L;
public static final long STATE_TIME_30 = 30L; 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_0 = 0.0D;
public static final Double STATE_FLOAT_TIME_10 = 10.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_20 = 20.0D;
public static final Double STATE_FLOAT_TIME_30 = 30.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_0 = 0;
public static final Integer STATE_INTEGER_TIME_10 = 10; 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_20 = 20;
public static final Integer STATE_INTEGER_TIME_30 = 30; 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_0 = "empty";
public static final String STATE_STRING_TIME_10 = "a"; 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_20 = "b";
public static final String STATE_STRING_TIME_30 = "c"; 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_0 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE; 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_20 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE; public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
public static final String BAG_ID = "@bag01"; public static final String BAG_ID = "@bag01";
public static final String BAG_NAME = "Test Bag"; public static final String BAG_NAME = "Test Bag";
public static final String BAG_TYPE = "TestBag"; public static final String BAG_TYPE = "TestBag";
/** /**
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)} * {@link #createParameterBag(String, String, String)}
* *
* @param id the id of the {@link Resource} * @param id the id of the {@link Resource}
* @param name the name of the {@link Resource} * @param name the name of the {@link Resource}
* @param type the type of the {@link Resource} * @param type the type of the {@link Resource}
* *
* @return the newly created {@link Resource} * @return the newly created {@link Resource}
*/ */
public static Resource createResource(String id, String name, String type) { public static Resource createResource(String id, String name, String type) {
Resource resource = new Resource(id, name, type); Resource resource = new Resource(id, name, type);
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
resource.addParameterBag(bag); resource.addParameterBag(bag);
addTimedStates(resource); addTimedStates(resource);
return resource; return resource;
} }
/** /**
* Creates {@link StrolchTimedState} instances and adds them to the {@link 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} * @param resource the resource to which to addd the newly created {@link StrolchTimedState}
*/ */
public static void addTimedStates(Resource resource) { public static void addTimedStates(Resource resource) {
// float state // float state
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME); FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0))); floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)));
FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10); FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange)); floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange)); floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange)); floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange));
resource.addTimedState(floatTimedState); resource.addTimedState(floatTimedState);
// integer state // integer state
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME); IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new IntegerValue(STATE_INTEGER_TIME_0))); new IntegerValue(STATE_INTEGER_TIME_0)));
IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10); IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange)); integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange)); integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange)); integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange));
resource.addTimedState(integerTimedState); resource.addTimedState(integerTimedState);
// boolean state // boolean state
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME); BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0,
new BooleanValue(STATE_BOOLEAN_TIME_0))); new BooleanValue(STATE_BOOLEAN_TIME_0)));
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10); BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange)); booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse(); booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange)); booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse(); booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange)); booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
resource.addTimedState(booleanTimedState); resource.addTimedState(booleanTimedState);
// string state // string state
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME); StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0)); StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change)); stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change));
change = change.getInverse(); change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_10)); change.add(asSet(STATE_STRING_TIME_10));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change)); stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
removeInverted(change.getValue()); removeInverted(change.getValue());
change = change.getInverse(); change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_20)); change.add(asSet(STATE_STRING_TIME_20));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change)); stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
removeInverted(change.getValue()); removeInverted(change.getValue());
change = change.getInverse(); change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_30)); change.add(asSet(STATE_STRING_TIME_30));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change)); stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
resource.addTimedState(stringTimedState); resource.addTimedState(stringTimedState);
} }
private static Set<AString> asSet(String value) { private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>(); HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value)); hashSet.add(new AString(value));
return hashSet; return hashSet;
} }
private static void removeInverted(Set<AString> set) { private static void removeInverted(Set<AString> set) {
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) { for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
AString aString = iter.next(); AString aString = iter.next();
if (aString.isInverse()) { if (aString.isInverse()) {
iter.remove(); iter.remove();
} }
} }
} }
/** /**
* Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)} * {@link #createParameterBag(String, String, String)}
* *
* @param idStart id range start * @param idStart id range start
* @param count the number of elements to create * @param count the number of elements to create
* @param idPrefix the prefix to generate IDs for the {@link Resource Resources} * @param idPrefix the prefix to generate IDs for the {@link Resource Resources}
* @param name the name of the {@link Resource} * @param name the name of the {@link Resource}
* @param type the type of the {@link Resource} * @param type the type of the {@link Resource}
* *
* @return the list of newly created {@link Resource Resources} * @return the list of newly created {@link Resource Resources}
*/ */
public static List<Resource> createResources(int idStart, int count, String idPrefix, String name, String type) { public static List<Resource> createResources(int idStart, int count, String idPrefix, String name, String type) {
List<Resource> resources = new ArrayList<>(); List<Resource> resources = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); resources.add(createResource(idPrefix + "_" + id, name + " " + i, type));
} }
return resources; return resources;
} }
/** /**
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)} * {@link #createParameterBag(String, String, String)}
* *
* @param id the id of the {@link Order} * @param id the id of the {@link Order}
* @param name the name of the {@link Order} * @param name the name of the {@link Order}
* @param type the type of the {@link Order} * @param type the type of the {@link Order}
* *
* @return the newly created {@link Order} * @return the newly created {@link Order}
*/ */
public static Order createOrder(String id, String name, String type) { public static Order createOrder(String id, String name, String type) {
return createOrder(id, name, type, new Date(), State.CREATED); return createOrder(id, name, type, new Date(), State.CREATED);
} }
/** /**
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)} * {@link #createParameterBag(String, String, String)}
* *
* @param id the id of the {@link Order} * @param id the id of the {@link Order}
* @param name the name of the {@link Order} * @param name the name of the {@link Order}
* @param type the type of the {@link Order} * @param type the type of the {@link Order}
* @param date the date of the {@link Order} * @param date the date of the {@link Order}
* @param state the {@link State} of the {@link Order} * @param state the {@link State} of the {@link Order}
* *
* @return the newly created {@link Order} * @return the newly created {@link Order}
*/ */
public static Order createOrder(String id, String name, String type, Date date, State state) { public static Order createOrder(String id, String name, String type, Date date, State state) {
Order order = new Order(id, name, type, date, state); Order order = new Order(id, name, type, date, state);
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
order.addParameterBag(bag); 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 * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)} * {@link #createParameterBag(String, String, String)}
* *
* @param idStart id range start * @param idStart id range start
* @param count the number of elements to create * @param count the number of elements to create
* @param idPrefix the prefix to generate IDs for the {@link Order Orders} * @param idPrefix the prefix to generate IDs for the {@link Order Orders}
* @param name the name of the {@link Order} * @param name the name of the {@link Order}
* @param type the type of the {@link Order} * @param type the type of the {@link Order}
* *
* @return the list of newly created {@link Order Orders} * @return the list of newly created {@link Order Orders}
*/ */
public static List<Order> createOrders(int idStart, int count, String idPrefix, String name, String type) { public static List<Order> createOrders(int idStart, int count, String idPrefix, String name, String type) {
List<Order> orders = new ArrayList<>(); List<Order> orders = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type));
} }
return orders; return orders;
} }
/** /**
* Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add
* {@link Parameter}s * {@link Parameter}s
* *
* @param id the id of the {@link ParameterBag} * @param id the id of the {@link ParameterBag}
* @param name the name of the {@link ParameterBag} * @param name the name of the {@link ParameterBag}
* @param type the type of the {@link ParameterBag} * @param type the type of the {@link ParameterBag}
* *
* @return the newly created {@link ParameterBag} * @return the newly created {@link ParameterBag}
*/ */
public static ParameterBag createParameterBag(String id, String name, String type) { public static ParameterBag createParameterBag(String id, String name, String type) {
ParameterBag bag = new ParameterBag(id, name, type); ParameterBag bag = new ParameterBag(id, name, type);
addAllParameters(bag); addAllParameters(bag);
return bag; return bag;
} }
/** /**
* Adds the following {@link Parameter}s to the given {@link ParameterBag}: * Adds the following {@link Parameter}s to the given {@link ParameterBag}:
* <ul> * <ul>
* <li>BooleanParameter - true</li> * <li>BooleanParameter - true</li>
* <li>FloatParameter - 44.3</li> * <li>FloatParameter - 44.3</li>
* <li>IntegerParameter - 77</li> * <li>IntegerParameter - 77</li>
* <li>LongParameter - 4453234566L</li> * <li>LongParameter - 4453234566L</li>
* <li>StringParameter - "Strolch"</li> * <li>StringParameter - "Strolch"</li>
* <li>DateParameter - 1354295525628L</li> * <li>DateParameter - 1354295525628L</li>
* <li>StringListParameter - Hello, World</li> * <li>StringListParameter - Hello, World</li>
* </ul> * </ul>
* *
* @param bag * @param bag
*/ */
public static void addAllParameters(ParameterBag bag) { public static void addAllParameters(ParameterBag bag) {
BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true);
boolParam.setIndex(1); boolParam.setIndex(1);
bag.addParameter(boolParam); bag.addParameter(boolParam);
FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3);
floatParam.setIndex(2); floatParam.setIndex(2);
bag.addParameter(floatParam); bag.addParameter(floatParam);
IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77);
integerParam.setIndex(3); integerParam.setIndex(3);
bag.addParameter(integerParam); bag.addParameter(integerParam);
LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L);
longParam.setIndex(4); longParam.setIndex(4);
bag.addParameter(longParam); bag.addParameter(longParam);
StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch");
stringParam.setIndex(5); stringParam.setIndex(5);
bag.addParameter(stringParam); bag.addParameter(stringParam);
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L));
dateParam.setIndex(6); dateParam.setIndex(6);
bag.addParameter(dateParam); bag.addParameter(dateParam);
ArrayList<String> stringList = new ArrayList<String>(); ArrayList<String> stringList = new ArrayList<String>();
stringList.add("Hello"); stringList.add("Hello");
stringList.add("World"); stringList.add("World");
StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME,
stringList); stringList);
stringListP.setIndex(7); stringListP.setIndex(7);
bag.addParameter(stringListP); 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 * 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 * 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. * 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 * 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 * getVerifier()-method will return the null reference
* *
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public class Order extends GroupedParameterizedElement implements StrolchRootElement { public class Order extends GroupedParameterizedElement implements StrolchRootElement {
@ -52,7 +52,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/** /**
* Default Constructor * Default Constructor
* *
* @param id * @param id
* @param name * @param name
* @param type * @param type
@ -66,7 +66,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/** /**
* Extended Constructor for date and {@link State} * Extended Constructor for date and {@link State}
* *
* @param id * @param id
* @param name * @param name
* @param type * @param type
@ -82,7 +82,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
/** /**
* DOM Constructor * DOM Constructor
* *
* @param element * @param element
*/ */
public Order(Element element) { public Order(Element element) {
@ -112,8 +112,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
} }
/** /**
* @param date * @param date the date to set
* the date to set
*/ */
public void setDate(Date date) { public void setDate(Date date) {
this.date = date; this.date = date;
@ -127,8 +126,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
} }
/** /**
* @param state * @param state the state to set
* the state to set
*/ */
public void setState(State state) { public void setState(State state) {
this.state = state; this.state = state;

View File

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

View File

@ -46,255 +46,255 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public abstract class ParameterizedElement extends AbstractStrolchElement { public abstract class ParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
protected GroupedParameterizedElement parent; protected GroupedParameterizedElement parent;
protected Map<String, Parameter<?>> parameterMap; protected Map<String, Parameter<?>> parameterMap;
protected String type; protected String type;
/** /**
* Empty Constructor * Empty Constructor
*/ */
protected ParameterizedElement() { protected ParameterizedElement() {
// //
} }
/** /**
* Default Constructor * Default Constructor
* *
* @param id * @param id
* @param name * @param name
* @param type * @param type
*/ */
public ParameterizedElement(String id, String name, String type) { public ParameterizedElement(String id, String name, String type) {
setId(id); setId(id);
setName(name); setName(name);
setType(type); setType(type);
} }
@Override @Override
public String getType() { public String getType() {
return this.type; return this.type;
} }
/** /**
* Sets the type of this {@link ParameterizedElement} * Sets the type of this {@link ParameterizedElement}
* *
* @param type the type to set * @param type the type to set
*/ */
public void setType(String type) { public void setType(String type) {
if (StringHelper.isEmpty(type)) { if (StringHelper.isEmpty(type)) {
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator()); msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg); throw new StrolchException(msg);
} }
this.type = type; this.type = type;
} }
/** /**
* Returns the {@link Parameter} with the given id, or null if it does not exist * Returns the {@link Parameter} with the given id, or null if it does not exist
* *
* @param key the id of the parameter to return * @param key the id of the parameter to return
* *
* @return the {@link Parameter} with the given id, or null if it does not exist * @return the {@link Parameter} with the given id, or null if it does not exist
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getParameter(String key) { public <T> T getParameter(String key) {
if (this.parameterMap == null) { if (this.parameterMap == null) {
return null; return null;
} }
return (T) this.parameterMap.get(key); return (T) this.parameterMap.get(key);
} }
/** /**
* Adds the given {@link Parameter} to the {@link ParameterizedElement} * Adds the given {@link Parameter} to the {@link ParameterizedElement}
* *
* @param parameter the {@link Parameter} to add * @param parameter the {@link Parameter} to add
*/ */
public void addParameter(Parameter<?> parameter) { public void addParameter(Parameter<?> parameter) {
if (this.parameterMap == null) { if (this.parameterMap == null) {
this.parameterMap = new HashMap<String, Parameter<?>>(); this.parameterMap = new HashMap<String, Parameter<?>>();
} }
this.parameterMap.put(parameter.getId(), parameter); this.parameterMap.put(parameter.getId(), parameter);
parameter.setParent(this); parameter.setParent(this);
} }
/** /**
* Removes the {@link Parameter} with the given key * Removes the {@link Parameter} with the given key
* *
* @param key the key of the {@link Parameter} to remove * @param key the key of the {@link Parameter} to remove
* *
* @return the removed {@link Parameter}, or null if it does not exist * @return the removed {@link Parameter}, or null if it does not exist
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> Parameter<T> removeParameter(String key) { public <T> Parameter<T> removeParameter(String key) {
if (this.parameterMap == null) { if (this.parameterMap == null) {
return null; return null;
} }
return (Parameter<T>) this.parameterMap.remove(key); return (Parameter<T>) this.parameterMap.remove(key);
} }
/** /**
* Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement}
* *
* @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
*/ */
public List<Parameter<?>> getParameters() { public List<Parameter<?>> getParameters() {
if (this.parameterMap == null) { if (this.parameterMap == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return new ArrayList<Parameter<?>>(this.parameterMap.values()); return new ArrayList<Parameter<?>>(this.parameterMap.values());
} }
/** /**
* Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
* *
* @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
*/ */
public boolean hasParameters() { public boolean hasParameters() {
return this.parameterMap != null && !this.parameterMap.isEmpty(); return this.parameterMap != null && !this.parameterMap.isEmpty();
} }
/** /**
* Returns true, if the {@link Parameter} exists with the given key, false otherwise * Returns true, if the {@link Parameter} exists with the given key, false otherwise
* *
* @param key the key of the {@link Parameter} to check for * @param key the key of the {@link Parameter} to check for
* *
* @return true, if the {@link Parameter} exists with the given key, false otherwise * @return true, if the {@link Parameter} exists with the given key, false otherwise
*/ */
public boolean hasParameter(String key) { public boolean hasParameter(String key) {
if (this.parameterMap == null) { if (this.parameterMap == null) {
return false; return false;
} }
return this.parameterMap.containsKey(key); return this.parameterMap.containsKey(key);
} }
/** /**
* Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
* *
* @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
*/ */
public Set<String> getParameterKeySet() { public Set<String> getParameterKeySet() {
if (this.parameterMap == null) { if (this.parameterMap == null) {
return Collections.emptySet(); return Collections.emptySet();
} }
return new HashSet<String>(this.parameterMap.keySet()); return new HashSet<String>(this.parameterMap.keySet());
} }
@Override @Override
public void fillLocator(LocatorBuilder lb) { public void fillLocator(LocatorBuilder lb) {
this.parent.fillLocator(lb); this.parent.fillLocator(lb);
lb.append(this.id); lb.append(this.id);
} }
@Override @Override
public Locator getLocator() { public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder(); LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb); fillLocator(lb);
return lb.build(); return lb.build();
} }
@Override @Override
protected void fromDom(Element element) { protected void fromDom(Element element) {
super.fromDom(element); super.fromDom(element);
String type = element.getAttribute(Tags.TYPE); String type = element.getAttribute(Tags.TYPE);
setType(type); setType(type);
// add all the parameters // add all the parameters
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
for (int i = 0; i < parameterElements.getLength(); i++) { for (int i = 0; i < parameterElements.getLength(); i++) {
Element paramElement = (Element) parameterElements.item(i); Element paramElement = (Element) parameterElements.item(i);
String paramtype = paramElement.getAttribute(Tags.TYPE); String paramtype = paramElement.getAttribute(Tags.TYPE);
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)) { if (paramtype.equals(StringParameter.TYPE)) {
StringParameter param = new StringParameter(paramElement); StringParameter param = new StringParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(IntegerParameter.TYPE)) { } else if (paramtype.equals(IntegerParameter.TYPE)) {
IntegerParameter param = new IntegerParameter(paramElement); IntegerParameter param = new IntegerParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(FloatParameter.TYPE)) { } else if (paramtype.equals(FloatParameter.TYPE)) {
FloatParameter param = new FloatParameter(paramElement); FloatParameter param = new FloatParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(LongParameter.TYPE)) { } else if (paramtype.equals(LongParameter.TYPE)) {
LongParameter param = new LongParameter(paramElement); LongParameter param = new LongParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(DateParameter.TYPE)) { } else if (paramtype.equals(DateParameter.TYPE)) {
DateParameter param = new DateParameter(paramElement); DateParameter param = new DateParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(BooleanParameter.TYPE)) { } else if (paramtype.equals(BooleanParameter.TYPE)) {
BooleanParameter param = new BooleanParameter(paramElement); BooleanParameter param = new BooleanParameter(paramElement);
addParameter(param); addParameter(param);
} else if (paramtype.equals(StringListParameter.TYPE)) { } else if (paramtype.equals(StringListParameter.TYPE)) {
StringListParameter param = new StringListParameter(paramElement); StringListParameter param = new StringListParameter(paramElement);
addParameter(param); addParameter(param);
} else { } else {
String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, paramtype); msg = MessageFormat.format(msg, paramtype);
throw new StrolchException(msg); throw new StrolchException(msg);
} }
} }
} }
@Override @Override
protected void fillElement(Element element) { protected void fillElement(Element element) {
super.fillElement(element); super.fillElement(element);
if (this.parameterMap != null) { if (this.parameterMap != null) {
for (Parameter<?> parameter : this.parameterMap.values()) { for (Parameter<?> parameter : this.parameterMap.values()) {
element.appendChild(parameter.toDom(element.getOwnerDocument())); element.appendChild(parameter.toDom(element.getOwnerDocument()));
} }
} }
} }
@Override @Override
protected void fillClone(StrolchElement clone) { protected void fillClone(StrolchElement clone) {
super.fillClone(clone); super.fillClone(clone);
ParameterizedElement peClone = (ParameterizedElement) clone; ParameterizedElement peClone = (ParameterizedElement) clone;
peClone.setType(this.type); peClone.setType(this.type);
if (this.parameterMap != null) { if (this.parameterMap != null) {
for (Parameter<?> param : this.parameterMap.values()) { for (Parameter<?> param : this.parameterMap.values()) {
peClone.addParameter(param.getClone()); peClone.addParameter(param.getClone());
} }
} }
} }
@Override @Override
public GroupedParameterizedElement getParent() { public GroupedParameterizedElement getParent() {
return this.parent; return this.parent;
} }
/** /**
* Set the parent for this {@link ParameterizedElement} * Set the parent for this {@link ParameterizedElement}
* *
* @param parent the parent to set * @param parent the parent to set
*/ */
public void setParent(GroupedParameterizedElement parent) { public void setParent(GroupedParameterizedElement parent) {
this.parent = parent; this.parent = parent;
} }
@Override @Override
public StrolchRootElement getRootElement() { public StrolchRootElement getRootElement() {
return this.parent.getRootElement(); return this.parent.getRootElement();
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("ParameterizedElement [id="); builder.append("ParameterizedElement [id=");
builder.append(this.id); builder.append(this.id);
builder.append(", name="); builder.append(", name=");
builder.append(this.name); builder.append(this.name);
builder.append(", type="); builder.append(", type=");
builder.append(this.type); builder.append(this.type);
builder.append("]"); 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 { 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 * Empty constructor
*/ */
public Resource() { public Resource() {
// //
} }
/** /**
* Default constructor * Default constructor
* *
* @param id * @param id
* @param name * @param name
* @param type * @param type
*/ */
public Resource(String id, String name, String type) { public Resource(String id, String name, String type) {
super(id, name, type); super(id, name, type);
} }
/** /**
* DOM Constructor * DOM Constructor
* *
* @param element * @param element
*/ */
public Resource(Element element) { public Resource(Element element) {
super.fromDom(element); super.fromDom(element);
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE); NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
for (int i = 0; i < timedStateElems.getLength(); i++) { for (int i = 0; i < timedStateElems.getLength(); i++) {
Element timedStateElem = (Element) timedStateElems.item(i); Element timedStateElem = (Element) timedStateElems.item(i);
String typeS = timedStateElem.getAttribute(Tags.TYPE); 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)) { if (typeS.equals(FloatTimedState.TYPE)) {
StrolchTimedState timedState = new FloatTimedState(timedStateElem); StrolchTimedState timedState = new FloatTimedState(timedStateElem);
addTimedState(timedState); addTimedState(timedState);
} else if (typeS.equals(IntegerTimedState.TYPE)) { } else if (typeS.equals(IntegerTimedState.TYPE)) {
StrolchTimedState timedState = new IntegerTimedState(timedStateElem); StrolchTimedState timedState = new IntegerTimedState(timedStateElem);
addTimedState(timedState); addTimedState(timedState);
} else if (typeS.equals(BooleanTimedState.TYPE)) { } else if (typeS.equals(BooleanTimedState.TYPE)) {
StrolchTimedState timedState = new BooleanTimedState(timedStateElem); StrolchTimedState timedState = new BooleanTimedState(timedStateElem);
addTimedState(timedState); addTimedState(timedState);
} else if (typeS.equals(StringSetTimedState.TYPE)) { } else if (typeS.equals(StringSetTimedState.TYPE)) {
StrolchTimedState timedState = new StringSetTimedState(timedStateElem); StrolchTimedState timedState = new StringSetTimedState(timedStateElem);
addTimedState(timedState); addTimedState(timedState);
} else { } else {
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$ String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, typeS); msg = MessageFormat.format(msg, typeS);
throw new StrolchException(msg); throw new StrolchException(msg);
} }
} }
} }
public void addTimedState(StrolchTimedState<?> strolchTimedState) { public void addTimedState(StrolchTimedState<?> strolchTimedState) {
if (this.timedStateMap == null) { if (this.timedStateMap == null) {
this.timedStateMap = new HashMap<>(); this.timedStateMap = new HashMap<>();
} }
this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState); this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState);
strolchTimedState.setParent(this); strolchTimedState.setParent(this);
} }
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public <T extends StrolchTimedState> T getTimedState(String id) { public <T extends StrolchTimedState> T getTimedState(String id) {
if (this.timedStateMap == null) { if (this.timedStateMap == null) {
return null; return null;
} }
return (T) this.timedStateMap.get(id); return (T) this.timedStateMap.get(id);
} }
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public <T extends StrolchTimedState> T removeTimedState(String id) { public <T extends StrolchTimedState> T removeTimedState(String id) {
if (this.timedStateMap == null) { if (this.timedStateMap == null) {
return null; return null;
} }
return (T) this.timedStateMap.remove(id); return (T) this.timedStateMap.remove(id);
} }
public Set<String> getTimedStateKeySet() { public Set<String> getTimedStateKeySet() {
if (this.timedStateMap == null) { if (this.timedStateMap == null) {
return Collections.emptySet(); return Collections.emptySet();
} }
return new HashSet<>(this.timedStateMap.keySet()); return new HashSet<>(this.timedStateMap.keySet());
} }
public List<StrolchTimedState<?>> getTimedStates() { public List<StrolchTimedState<?>> getTimedStates() {
if (this.timedStateMap == null) { if (this.timedStateMap == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return new ArrayList<>(this.timedStateMap.values()); return new ArrayList<>(this.timedStateMap.values());
} }
public boolean hasTimedStates() { public boolean hasTimedStates() {
return this.timedStateMap != null && !this.timedStateMap.isEmpty(); return this.timedStateMap != null && !this.timedStateMap.isEmpty();
} }
public boolean hasTimedState(String id) { public boolean hasTimedState(String id) {
return this.timedStateMap != null && this.timedStateMap.containsKey(id); return this.timedStateMap != null && this.timedStateMap.containsKey(id);
} }
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element element = doc.createElement(Tags.RESOURCE); Element element = doc.createElement(Tags.RESOURCE);
fillElement(element); fillElement(element);
if (this.timedStateMap != null) { if (this.timedStateMap != null) {
for (StrolchTimedState<?> state : this.timedStateMap.values()) { for (StrolchTimedState<?> state : this.timedStateMap.values()) {
Element timedStateElem = state.toDom(element.getOwnerDocument()); Element timedStateElem = state.toDom(element.getOwnerDocument());
element.appendChild(timedStateElem); element.appendChild(timedStateElem);
} }
} }
return element; return element;
} }
@Override @Override
public Resource getClone() { public Resource getClone() {
Resource clone = new Resource(); Resource clone = new Resource();
super.fillClone(clone); super.fillClone(clone);
return clone; return clone;
} }
@Override @Override
public void fillLocator(LocatorBuilder lb) { public void fillLocator(LocatorBuilder lb) {
lb.append(Tags.RESOURCE).append(getType()).append(getId()); lb.append(Tags.RESOURCE).append(getType()).append(getId());
} }
@Override @Override
public Locator getLocator() { public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder(); LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb); fillLocator(lb);
return lb.build(); return lb.build();
} }
@Override @Override
public StrolchElement getParent() { public StrolchElement getParent() {
return null; return null;
} }
@Override @Override
public Resource getRootElement() { public Resource getRootElement() {
return this; return this;
} }
@Override @Override
public <T> T accept(StrolchRootElementVisitor visitor) { public <T> T accept(StrolchRootElementVisitor visitor) {
return visitor.visitResource(this); return visitor.visitResource(this);
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("Resource [id="); builder.append("Resource [id=");
builder.append(this.id); builder.append(this.id);
builder.append(", name="); builder.append(", name=");
builder.append(this.name); builder.append(this.name);
builder.append(", type="); builder.append(", type=");
builder.append(this.type); builder.append(this.type);
builder.append("]"); 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> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public interface ResourceVisitor extends StrolchElementVisitor<Resource>{ public interface ResourceVisitor extends StrolchElementVisitor<Resource> {
@Override @Override
public void visit(Resource element); 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
* *
* @return the {@link Locator} for this element * @return the {@link Locator} for this element
*/ */
public Locator getLocator(); 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 * Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface * implementations of this interface
* *
* @param id * @param id
*/ */
public void setId(String 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 * Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface * implementations of this interface
* *
* @return * @return
*/ */
public String getId(); public String getId();
/** /**
* Set the name of this {@link StrolchElement} * Set the name of this {@link StrolchElement}
* *
* @param name * @param name
*/ */
public void setName(String name); public void setName(String name);
/** /**
* Returns the name of this {@link StrolchElement} * Returns the name of this {@link StrolchElement}
* *
* @return * @return
*/ */
public String getName(); public String getName();
/** /**
* Set the currently set long value which defines the primary key for use in RDBM-Systems * Set the currently set long value which defines the primary key for use in RDBM-Systems
* *
* @param dbid * @param dbid
*/ */
public void setDbid(long dbid); public void setDbid(long dbid);
/** /**
* Returns the currently set long value which defines the primary key for use in RDBM-Systems * Returns the currently set long value which defines the primary key for use in RDBM-Systems
* *
* @return * @return
*/ */
public long getDbid(); public long getDbid();
/** /**
* Returns an {@link Element} object which is an XML representation of this object * Returns an {@link Element} object which is an XML representation of this object
* *
* @param doc * @param doc the document to which this element is being written. The client must not append to the document, the
* the document to which this element is being written. The client must not append to the document, the * caller will perform this as needed
* caller will perform this as needed *
*
* @return * @return
*/ */
public Element toDom(Document doc); public Element toDom(Document doc);
/** /**
* Returns the type of this {@link StrolchElement} * Returns the type of this {@link StrolchElement}
* *
* @return * @return
*/ */
public String getType(); public String getType();
@ -100,7 +99,7 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
/** /**
* Return a clone of this {@link StrolchElement} * Return a clone of this {@link StrolchElement}
* *
* @return * @return
*/ */
public StrolchElement getClone(); 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 * Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
* Resources} and {@link Order Orders} * Resources} and {@link Order Orders}
* *
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public interface StrolchRootElement extends StrolchElement { public interface StrolchRootElement extends StrolchElement {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -139,6 +139,7 @@ public abstract class ParameterSelection implements Selection {
} }
public static class BooleanParameterSelection extends ParameterSelection { public static class BooleanParameterSelection extends ParameterSelection {
private Boolean value; private Boolean value;
public BooleanParameterSelection(String bagKey, String paramKey, 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 { public static class LongParameterSelection extends ParameterSelection {
private Long value; private Long value;
public LongParameterSelection(String bagKey, String paramKey, 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 { public static class FloatParameterSelection extends ParameterSelection {
private Double value; private Double value;
public FloatParameterSelection(String bagKey, String paramKey, 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 { public static class DateParameterSelection extends ParameterSelection {
private Date value; private Date value;
public DateParameterSelection(String bagKey, String paramKey, 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 { public static class StringListParameterSelection extends ParameterSelection {
private List<String> value; private List<String> value;
public StringListParameterSelection(String bagKey, String paramKey, 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> * @author Robert von Burg <eitch@eitchnet.ch>
* *
*/ */
public interface ParameterSelectionVisitor extends QueryVisitor { public interface ParameterSelectionVisitor extends QueryVisitor {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,96 +32,96 @@ import li.strolch.model.timevalue.IValueChange;
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public abstract class AbstractStrolchTimedState<T extends IValue> extends AbstractStrolchElement implements 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 Resource parent;
protected ITimedState<T> state; protected ITimedState<T> state;
public AbstractStrolchTimedState() { public AbstractStrolchTimedState() {
this.state = new TimedState<>(); this.state = new TimedState<>();
} }
public AbstractStrolchTimedState(String id, String name) { public AbstractStrolchTimedState(String id, String name) {
super(id, name); super(id, name);
this.state = new TimedState<>(); this.state = new TimedState<>();
} }
@Override @Override
public ITimeValue<T> getNextMatch(Long time, T value) { public ITimeValue<T> getNextMatch(Long time, T value) {
return this.state.getNextMatch(time, value); return this.state.getNextMatch(time, value);
} }
@Override @Override
public ITimeValue<T> getPreviousMatch(Long time, T value) { public ITimeValue<T> getPreviousMatch(Long time, T value) {
return this.state.getPreviousMatch(time, value); return this.state.getPreviousMatch(time, value);
} }
@Override @Override
public <U extends IValueChange<T>> void applyChange(U change) { public <U extends IValueChange<T>> void applyChange(U change) {
this.state.applyChange(change); this.state.applyChange(change);
} }
@Override @Override
public ITimeValue<T> getStateAt(Long time) { public ITimeValue<T> getStateAt(Long time) {
return this.state.getStateAt(time); return this.state.getStateAt(time);
} }
@Override @Override
public ITimeVariable<T> getTimeEvolution() { public ITimeVariable<T> getTimeEvolution() {
return this.state.getTimeEvolution(); return this.state.getTimeEvolution();
} }
@Override @Override
public StrolchElement getParent() { public StrolchElement getParent() {
return this.parent; return this.parent;
} }
@Override @Override
public void setParent(Resource parent) { public void setParent(Resource parent) {
this.parent = parent; this.parent = parent;
} }
@Override @Override
public StrolchRootElement getRootElement() { public StrolchRootElement getRootElement() {
return this.parent; return this.parent;
} }
@Override @Override
protected void fillLocator(LocatorBuilder locatorBuilder) { protected void fillLocator(LocatorBuilder locatorBuilder) {
locatorBuilder.append(Tags.TIMED_STATE); locatorBuilder.append(Tags.TIMED_STATE);
locatorBuilder.append(getId()); locatorBuilder.append(getId());
} }
@Override @Override
public Locator getLocator() { public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder(); LocatorBuilder lb = new LocatorBuilder();
this.parent.fillLocator(lb); this.parent.fillLocator(lb);
fillLocator(lb); fillLocator(lb);
return lb.build(); return lb.build();
} }
protected void fillClone(AbstractStrolchTimedState<T> clone) { protected void fillClone(AbstractStrolchTimedState<T> clone) {
super.fillClone(clone); super.fillClone(clone);
clone.state = this.state.getCopy(); clone.state = this.state.getCopy();
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName()); builder.append(getClass().getSimpleName());
builder.append(" [id="); builder.append(" [id=");
builder.append(this.id); builder.append(this.id);
builder.append(", name="); builder.append(", name=");
builder.append(this.name); builder.append(this.name);
builder.append(", valueNow="); builder.append(", valueNow=");
builder.append(this.state.getStateAt(System.currentTimeMillis())); builder.append(this.state.getStateAt(System.currentTimeMillis()));
builder.append("]"); 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> { 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() { public BooleanTimedState() {
super(); super();
} }
public BooleanTimedState(String id, String name) { public BooleanTimedState(String id, String name) {
super(id, name); super(id, name);
} }
public BooleanTimedState(Element element) { public BooleanTimedState(Element element) {
super.fromDom(element); super.fromDom(element);
this.state = new TimedState<>(); this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) { for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i); Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE)); Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE));
BooleanValue booleanValue = new BooleanValue(value); BooleanValue booleanValue = new BooleanValue(value);
this.state.getTimeEvolution().setValueAt(time, booleanValue); this.state.getTimeEvolution().setValueAt(time, booleanValue);
} }
} }
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE); Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement); super.fillElement(stateElement);
SortedSet<ITimeValue<BooleanValue>> values = this.state.getTimeEvolution().getValues(); SortedSet<ITimeValue<BooleanValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<BooleanValue> timeValue : values) { for (ITimeValue<BooleanValue> timeValue : values) {
Long time = timeValue.getTime(); Long time = timeValue.getTime();
BooleanValue value = timeValue.getValue(); BooleanValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE); Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString()); valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem); stateElement.appendChild(valueElem);
} }
return stateElement; return stateElement;
} }
@Override @Override
public String getType() { public String getType() {
return TYPE; return TYPE;
} }
@Override @Override
public StrolchElement getClone() { public StrolchElement getClone() {
BooleanTimedState clone = new BooleanTimedState(); BooleanTimedState clone = new BooleanTimedState();
fillClone(clone); fillClone(clone);
return clone; return clone;
} }
} }

View File

@ -29,60 +29,60 @@ import org.w3c.dom.NodeList;
*/ */
public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> { 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() { public FloatTimedState() {
super(); super();
} }
public FloatTimedState(String id, String name) { public FloatTimedState(String id, String name) {
super(id, name); super(id, name);
} }
public FloatTimedState(Element element) { public FloatTimedState(Element element) {
super.fromDom(element); super.fromDom(element);
this.state = new TimedState<>(); this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) { for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i); Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE)); Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE));
FloatValue floatValue = new FloatValue(value); FloatValue floatValue = new FloatValue(value);
this.state.getTimeEvolution().setValueAt(time, floatValue); this.state.getTimeEvolution().setValueAt(time, floatValue);
} }
} }
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE); Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement); super.fillElement(stateElement);
SortedSet<ITimeValue<FloatValue>> values = this.state.getTimeEvolution().getValues(); SortedSet<ITimeValue<FloatValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<FloatValue> timeValue : values) { for (ITimeValue<FloatValue> timeValue : values) {
Long time = timeValue.getTime(); Long time = timeValue.getTime();
FloatValue value = timeValue.getValue(); FloatValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE); Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString()); valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem); stateElement.appendChild(valueElem);
} }
return stateElement; return stateElement;
} }
@Override @Override
public String getType() { public String getType() {
return TYPE; return TYPE;
} }
@Override @Override
public StrolchElement getClone() { public StrolchElement getClone() {
FloatTimedState clone = new FloatTimedState(); FloatTimedState clone = new FloatTimedState();
fillClone(clone); fillClone(clone);
return 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. * A time based state characterized by a {@link IValue} object implementation.
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
* *
* @param <T> * @param <T> IValue implementation representing the state at a given time
* IValue implementation representing the state at a given time
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public interface ITimedState<T extends IValue> { public interface ITimedState<T extends IValue> {
@ -42,8 +41,7 @@ public interface ITimedState<T extends IValue> {
ITimeValue<T> getPreviousMatch(final Long time, T value); ITimeValue<T> getPreviousMatch(final Long time, T value);
/** /**
* @param change * @param change the state change to be applied
* the state change to be applied
*/ */
<U extends IValueChange<T>> void applyChange(final U change); <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 * @return a copy of this timed state
*/ */
ITimedState<T> getCopy(); ITimedState<T> getCopy();
} }

View File

@ -29,60 +29,60 @@ import org.w3c.dom.NodeList;
*/ */
public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> { 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() { public IntegerTimedState() {
super(); super();
} }
public IntegerTimedState(String id, String name) { public IntegerTimedState(String id, String name) {
super(id, name); super(id, name);
} }
public IntegerTimedState(Element element) { public IntegerTimedState(Element element) {
super.fromDom(element); super.fromDom(element);
this.state = new TimedState<>(); this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) { for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i); Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE)); Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE));
IntegerValue integerValue = new IntegerValue(value); IntegerValue integerValue = new IntegerValue(value);
this.state.getTimeEvolution().setValueAt(time, integerValue); this.state.getTimeEvolution().setValueAt(time, integerValue);
} }
} }
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE); Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement); super.fillElement(stateElement);
SortedSet<ITimeValue<IntegerValue>> values = this.state.getTimeEvolution().getValues(); SortedSet<ITimeValue<IntegerValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<IntegerValue> timeValue : values) { for (ITimeValue<IntegerValue> timeValue : values) {
Long time = timeValue.getTime(); Long time = timeValue.getTime();
IntegerValue value = timeValue.getValue(); IntegerValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE); Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString()); valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem); stateElement.appendChild(valueElem);
} }
return stateElement; return stateElement;
} }
@Override @Override
public String getType() { public String getType() {
return TYPE; return TYPE;
} }
@Override @Override
public StrolchElement getClone() { public StrolchElement getClone() {
IntegerTimedState clone = new IntegerTimedState(); IntegerTimedState clone = new IntegerTimedState();
fillClone(clone); fillClone(clone);
return clone; return clone;
} }
} }

View File

@ -33,79 +33,79 @@ import org.w3c.dom.NodeList;
*/ */
public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValue> { 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() { public StringSetTimedState() {
super(); super();
} }
public StringSetTimedState(String id, String name) { public StringSetTimedState(String id, String name) {
super(id, name); super(id, name);
} }
public StringSetTimedState(Element element) { public StringSetTimedState(Element element) {
super.fromDom(element); super.fromDom(element);
this.state = new TimedState<>(); this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) { for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i); Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
String valueAsString = timeValueElem.getAttribute(Tags.VALUE); String valueAsString = timeValueElem.getAttribute(Tags.VALUE);
Set<AString> value = new HashSet<>(); Set<AString> value = new HashSet<>();
String[] values = valueAsString.split(","); String[] values = valueAsString.split(",");
for (String s : values) { for (String s : values) {
value.add(new AString(s.trim())); value.add(new AString(s.trim()));
} }
StringSetValue integerValue = new StringSetValue(value); StringSetValue integerValue = new StringSetValue(value);
this.state.getTimeEvolution().setValueAt(time, integerValue); this.state.getTimeEvolution().setValueAt(time, integerValue);
} }
} }
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE); Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement); super.fillElement(stateElement);
SortedSet<ITimeValue<StringSetValue>> values = this.state.getTimeEvolution().getValues(); SortedSet<ITimeValue<StringSetValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<StringSetValue> timeValue : values) { for (ITimeValue<StringSetValue> timeValue : values) {
Long time = timeValue.getTime(); Long time = timeValue.getTime();
StringSetValue stringSetValue = timeValue.getValue(); StringSetValue stringSetValue = timeValue.getValue();
Set<AString> value = stringSetValue.getValue(); Set<AString> value = stringSetValue.getValue();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Iterator<AString> iter = value.iterator(); Iterator<AString> iter = value.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
sb.append(iter.next().getString()); sb.append(iter.next().getString());
if (iter.hasNext()) { if (iter.hasNext()) {
sb.append(", "); sb.append(", ");
} }
} }
String valueAsString = sb.toString(); String valueAsString = sb.toString();
Element valueElem = doc.createElement(Tags.VALUE); Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString()); valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, valueAsString); valueElem.setAttribute(Tags.VALUE, valueAsString);
stateElement.appendChild(valueElem); stateElement.appendChild(valueElem);
} }
return stateElement; return stateElement;
} }
@Override @Override
public String getType() { public String getType() {
return TYPE; return TYPE;
} }
@Override @Override
public StrolchElement getClone() { public StrolchElement getClone() {
StringSetTimedState clone = new StringSetTimedState(); StringSetTimedState clone = new StringSetTimedState();
fillClone(clone); fillClone(clone);
return clone; return clone;
} }
} }

View File

@ -38,5 +38,5 @@ public interface StrolchTimedState<T extends IValue> extends StrolchElement {
public ITimeVariable<T> getTimeEvolution(); 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} * Interface for timed value objects to be used with the {@link TimeVariable}
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
* *
* @param <T> * @param <T> the backing value of the timed value object
* the backing value of the timed value object
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public interface ITimeValue<T extends IValue> extends Comparable<ITimeValue<T>> { 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. * 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> * @author Martin Smock <smock.martin@gmail.com>
* *
* @param <T> * @param <T> the backing value of the timed value object
* the backing value of the timed value object
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public interface ITimeVariable<T extends IValue> { public interface ITimeVariable<T extends IValue> {
/** /**
* set the value at a point in time to a given time value object * set the value at a point in time to a given time value object
* *
* @param time * @param time the time to set the {@link IValue}
* the time to set the {@link IValue} * @param value the {@link IValue} to set
* @param value
* the {@link IValue} to set
*/ */
void setValueAt(final Long time, final T value); 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. * Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
* *
* @param change * @param change the {@link IValueChange} to be applied
* the {@link IValueChange} to be applied
*/ */
void applyChange(final IValueChange<T> change); void applyChange(final IValueChange<T> change);
/** /**
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time * Get all {@link ITimeValue} objects whose time field is greater or equal to the given time
* *
* @param time * @param time the time the sequence starts with
* the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future * @return the sequence of {@link ITimeValue} objects in the future
*/ */
Collection<ITimeValue<T>> getFutureValues(final Long time); Collection<ITimeValue<T>> getFutureValues(final Long time);
/** /**
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time * Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
* *
* @param time * @param time the time the sequence starts with
* the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future * @return the sequence of {@link ITimeValue} objects in the future
*/ */
Collection<ITimeValue<T>> getPastValues(final Long time); Collection<ITimeValue<T>> getPastValues(final Long time);
/** /**
* Get all {@link ITimeValue} objects * Get all {@link ITimeValue} objects
* *
* @return a defensive copy of the {@link ITimeValue}s * @return a defensive copy of the {@link ITimeValue}s
*/ */
SortedSet<ITimeValue<T>> getValues(); SortedSet<ITimeValue<T>> getValues();

View File

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

View File

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

View File

@ -18,15 +18,14 @@ package li.strolch.model.timevalue.impl;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Wrapper for java.util.String object defining a inverse to support algebraic * Wrapper for java.util.String object defining a inverse to support algebraic operations.
* operations. *
*
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
public class AString implements Serializable { public class AString implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final String string; private final String string;
private final boolean inverse; private final boolean inverse;
@ -63,20 +62,26 @@ public class AString implements Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
AString other = (AString) obj; AString other = (AString) obj;
if (this.inverse != other.inverse) if (this.inverse != other.inverse) {
return false; return false;
}
if (this.string == null) { if (this.string == null) {
if (other.string != null) if (other.string != null) {
return false; return false;
} else if (!this.string.equals(other.string)) }
} else if (!this.string.equals(other.string)) {
return false; return false;
}
return true; 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 * {@link IValue} implementation to work with Boolean valued {@link ITimeValue} objects
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
public class BooleanValue implements IValue<Boolean>, Serializable { public class BooleanValue implements IValue<Boolean>, Serializable {
@ -91,18 +91,23 @@ public class BooleanValue implements IValue<Boolean>, Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
BooleanValue other = (BooleanValue) obj; BooleanValue other = (BooleanValue) obj;
if (this.value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null) {
return false; return false;
} else if (!this.value.equals(other.value)) }
} else if (!this.value.equals(other.value)) {
return false; return false;
}
return true; 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 * {@link IValue} implementation to work with Double valued {@link ITimeValue} objects
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
public class FloatValue implements IValue<Double>, Serializable { public class FloatValue implements IValue<Double>, Serializable {
@ -85,8 +85,8 @@ public class FloatValue implements IValue<Double>, Serializable {
} }
@Override @Override
public FloatValue getCopy(){ public FloatValue getCopy() {
return new FloatValue(this.value); return new FloatValue(this.value);
} }
@Override @Override
@ -99,20 +99,24 @@ public class FloatValue implements IValue<Double>, Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
FloatValue other = (FloatValue) obj; FloatValue other = (FloatValue) obj;
if (this.value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null) {
return false; return false;
} else if (!this.value.equals(other.value)) }
} else if (!this.value.equals(other.value)) {
return false; return false;
}
return true; 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 * {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
public class IntegerValue implements IValue<Integer>, Serializable { public class IntegerValue implements IValue<Integer>, Serializable {
@ -91,18 +91,23 @@ public class IntegerValue implements IValue<Integer>, Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
IntegerValue other = (IntegerValue) obj; IntegerValue other = (IntegerValue) obj;
if (this.value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null) {
return false; return false;
} else if (!this.value.equals(other.value)) }
} else if (!this.value.equals(other.value)) {
return false; return false;
}
return true; return true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -61,14 +61,18 @@ public abstract class StrolchElementToDomVisitor {
AttributesImpl attributes = attributesFor((StrolchElement) parameter); AttributesImpl attributes = attributesFor((StrolchElement) parameter);
attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString()); 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()); 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()); 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())); 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())); attributes.addAttribute(null, null, Tags.INDEX, Tags.CDATA, Integer.toString(parameter.getIndex()));
}
return attributes; return attributes;
} }

View File

@ -34,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
* *
*/ */
public class XmlModelSaxFileReader extends XmlModelSaxReader { public class XmlModelSaxFileReader extends XmlModelSaxReader {
@ -54,27 +54,28 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader {
switch (qName) { switch (qName) {
case Tags.INCLUDE_FILE: case Tags.INCLUDE_FILE:
String includeFileS = attributes.getValue(Tags.FILE); String includeFileS = attributes.getValue(Tags.FILE);
if (StringHelper.isEmpty(includeFileS)) if (StringHelper.isEmpty(includeFileS)) {
throw new IllegalArgumentException(MessageFormat.format( throw new IllegalArgumentException(MessageFormat.format(
"The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ "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()) { File includeFile = new File(this.modelFile.getParentFile(), includeFileS);
String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ if (!includeFile.exists() || !includeFile.canRead()) {
msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$
throw new IllegalArgumentException(msg); msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS);
} throw new IllegalArgumentException(msg);
}
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile);
handler.parseFile(); handler.parseFile();
this.statistics.nrOfOrders += handler.statistics.nrOfOrders; this.statistics.nrOfOrders += handler.statistics.nrOfOrders;
this.statistics.nrOfResources += handler.statistics.nrOfResources; this.statistics.nrOfResources += handler.statistics.nrOfResources;
break; break;
default: default:
super.startElement(uri, localName, qName, attributes); 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 { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
// TODO split each root object into its own file // TODO split each root object into its own file
switch (qName) { switch (qName) {
case Tags.STROLCH_MODEL: case Tags.STROLCH_MODEL:
break; break;
case Tags.RESOURCE: case Tags.RESOURCE:
String resId = attributes.getValue(Tags.ID); String resId = attributes.getValue(Tags.ID);
String resName = attributes.getValue(Tags.NAME); String resName = attributes.getValue(Tags.NAME);
String resType = attributes.getValue(Tags.TYPE); String resType = attributes.getValue(Tags.TYPE);
Resource resource = new Resource(resId, resName, resType); Resource resource = new Resource(resId, resName, resType);
this.parameterizedElement = resource; this.parameterizedElement = resource;
break; break;
case Tags.ORDER: case Tags.ORDER:
String orderId = attributes.getValue(Tags.ID); String orderId = attributes.getValue(Tags.ID);
String orderName = attributes.getValue(Tags.NAME); String orderName = attributes.getValue(Tags.NAME);
String orderType = attributes.getValue(Tags.TYPE); String orderType = attributes.getValue(Tags.TYPE);
String orderDateS = attributes.getValue(Tags.DATE); String orderDateS = attributes.getValue(Tags.DATE);
String orderStateS = attributes.getValue(Tags.STATE); String orderStateS = attributes.getValue(Tags.STATE);
Order order = new Order(orderId, orderName, orderType); Order order = new Order(orderId, orderName, orderType);
if (orderDateS != null) { if (orderDateS != null) {
Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS);
order.setDate(orderDate); 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$
} }
param.setHidden(paramHidden); if (orderStateS != null) {
param.setUom(paramUom); State orderState = State.valueOf(orderStateS);
param.setInterpretation(paramInterpretation); order.setState(orderState);
param.setIndex(index); }
this.pBag.addParameter(param); this.parameterizedElement = order;
} catch (Exception e) { break;
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
}
break;
default: case Tags.PARAMETER_BAG:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ 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 { public void endElement(String uri, String localName, String qName) throws SAXException {
switch (qName) { switch (qName) {
case Tags.STROLCH_MODEL: case Tags.STROLCH_MODEL:
break; break;
case Tags.RESOURCE: case Tags.RESOURCE:
this.listener.notifyResource((Resource) this.parameterizedElement); this.listener.notifyResource((Resource) this.parameterizedElement);
this.statistics.nrOfResources++; this.statistics.nrOfResources++;
this.parameterizedElement = null; this.parameterizedElement = null;
break; break;
case Tags.ORDER: case Tags.ORDER:
this.listener.notifyOrder((Order) this.parameterizedElement); this.listener.notifyOrder((Order) this.parameterizedElement);
this.statistics.nrOfOrders++; this.statistics.nrOfOrders++;
this.parameterizedElement = null; this.parameterizedElement = null;
break; break;
case Tags.PARAMETER_BAG: case Tags.PARAMETER_BAG:
this.pBag = null; this.pBag = null;
break; break;
case Tags.PARAMETER: case Tags.PARAMETER:
break; break;
case Tags.INCLUDE_FILE: case Tags.INCLUDE_FILE:
break; break;
default: default:
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
} }
} }
public static class XmlModelStatistics { public static class XmlModelStatistics {
public Date startTime; public Date startTime;
public long durationNanos; public long durationNanos;
public int nrOfResources; public int nrOfResources;

View File

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

View File

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

View File

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

View File

@ -33,85 +33,85 @@ import org.junit.Test;
*/ */
public class StrolchTimedStateTest { public class StrolchTimedStateTest {
@Test @Test
public void testFloatState() { 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); FloatTimedState floatState = myRes.getTimedState(ModelGenerator.STATE_FLOAT_ID);
ITimeValue<FloatValue> valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); ITimeValue<FloatValue> valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue()); assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue());
ITimeValue<FloatValue> valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); ITimeValue<FloatValue> valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue()); assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue());
ITimeValue<FloatValue> valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); ITimeValue<FloatValue> valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue()); assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue());
ITimeValue<FloatValue> valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); ITimeValue<FloatValue> valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue()); assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue());
} }
@Test @Test
public void testIntegerState() { 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); IntegerTimedState integerState = myRes.getTimedState(ModelGenerator.STATE_INTEGER_ID);
ITimeValue<IntegerValue> valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); ITimeValue<IntegerValue> valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue()); assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue());
ITimeValue<IntegerValue> valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); ITimeValue<IntegerValue> valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue()); assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue());
ITimeValue<IntegerValue> valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); ITimeValue<IntegerValue> valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue()); assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue());
ITimeValue<IntegerValue> valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); ITimeValue<IntegerValue> valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue()); assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue());
} }
@Test @Test
public void testBooleanState() { 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); BooleanTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID);
ITimeValue<BooleanValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); ITimeValue<BooleanValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue()); assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue());
ITimeValue<BooleanValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); ITimeValue<BooleanValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue()); assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue());
ITimeValue<BooleanValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); ITimeValue<BooleanValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue()); assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue());
ITimeValue<BooleanValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); ITimeValue<BooleanValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue()); assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue());
} }
@Test @Test
public void testStringSetState() { 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); StringSetTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_STRING_ID);
ITimeValue<StringSetValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); ITimeValue<StringSetValue> valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0);
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue()); assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue());
ITimeValue<StringSetValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); ITimeValue<StringSetValue> valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10);
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue()); assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue());
ITimeValue<StringSetValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); ITimeValue<StringSetValue> valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20);
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue()); assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue());
ITimeValue<StringSetValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); ITimeValue<StringSetValue> valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30);
assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue()); assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue());
} }
private static Set<AString> asSet(String value) { private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>(); HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value)); hashSet.add(new AString(value));
return hashSet; return hashSet;
} }
} }

View File

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

View File

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