[Minor] cleaned up compiler warnings and added Tags constants class

This commit is contained in:
Robert von Burg 2013-10-24 18:37:47 +02:00
parent 70258baf7c
commit 6b12b31605
36 changed files with 466 additions and 340 deletions

View File

@ -21,6 +21,8 @@
*/ */
package li.strolch.model; package li.strolch.model;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Locator.LocatorBuilder; import li.strolch.model.Locator.LocatorBuilder;
@ -75,10 +77,10 @@ public abstract class AbstractStrolchElement implements StrolchElement {
@Override @Override
public void setId(String id) { public void setId(String id) {
if (id == null) if (id == null)
throw new StrolchException("The id may never be null"); throw new StrolchException("The id may never be null"); //$NON-NLS-1$
if (id.isEmpty()) if (id.isEmpty())
throw new StrolchException("The id may never be empty"); throw new StrolchException("The id may never be empty"); //$NON-NLS-1$
this.id = id; this.id = id;
} }
@ -113,9 +115,9 @@ public abstract class AbstractStrolchElement implements StrolchElement {
} }
protected void fillElement(Element element) { protected void fillElement(Element element) {
element.setAttribute("Id", getId()); element.setAttribute(Tags.ID, getId());
element.setAttribute("Name", getName()); element.setAttribute(Tags.NAME, getName());
element.setAttribute("Type", getType()); element.setAttribute(Tags.TYPE, getType());
} }
/** /**
@ -124,15 +126,16 @@ public abstract class AbstractStrolchElement implements StrolchElement {
* @param element * @param element
*/ */
protected void fromDom(Element element) { protected void fromDom(Element element) {
String id = element.getAttribute("Id"); String id = element.getAttribute(Tags.ID);
String name = element.getAttribute("Name"); String name = element.getAttribute(Tags.NAME);
if (id != null && name != null) { if (id != null && name != null) {
setId(id); setId(id);
setName(name); setName(name);
} else { } else {
throw new StrolchException("Check the values of the element: " + element.getNodeName() String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$
+ " either id or name attribute is null!"); msg = MessageFormat.format(msg, element.getNodeName());
throw new StrolchException(msg);
} }
} }

View File

@ -21,6 +21,7 @@
*/ */
package li.strolch.model; package li.strolch.model;
import java.text.MessageFormat;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -77,8 +78,11 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
* 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)) {
throw new StrolchException("Type must be set on element " + getLocator()); String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg);
}
this.type = type; this.type = type;
} }
@ -120,7 +124,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
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) {
throw new StrolchException("No parameter bag exists with key " + bagKey); String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, bagKey);
throw new StrolchException(msg);
} }
bag.addParameter(parameter); bag.addParameter(parameter);
@ -225,10 +231,10 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
public void fromDom(Element element) { public void fromDom(Element element) {
super.fromDom(element); super.fromDom(element);
String type = element.getAttribute("Type"); String type = element.getAttribute(Tags.TYPE);
setType(type); setType(type);
NodeList bags = element.getElementsByTagName("ParameterBag"); NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG);
for (int i = 0; i < bags.getLength(); i++) { for (int i = 0; i < bags.getLength(); i++) {
Element bagElement = (Element) bags.item(i); Element bagElement = (Element) bags.item(i);
ParameterBag bag = new ParameterBag(bagElement); ParameterBag bag = new ParameterBag(bagElement);

View File

@ -21,6 +21,7 @@
*/ */
package li.strolch.model; package li.strolch.model;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -52,7 +53,7 @@ public class Locator {
/** /**
* The separator used when formatting a {@link Locator} object ot a string * The separator used when formatting a {@link Locator} object ot a string
*/ */
public static final String PATH_SEPARATOR = "/"; public static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
/** /**
* {@link List} of path elements, with the first being the top level or root element * {@link List} of path elements, with the first being the top level or root element
@ -70,7 +71,7 @@ public class Locator {
*/ */
public Locator(List<String> pathElements) throws StrolchException { public Locator(List<String> pathElements) throws StrolchException {
if (pathElements == null || pathElements.size() > 2) if (pathElements == null || pathElements.size() > 2)
throw new StrolchException("The path elements may not be null and must contain at least 2 items"); throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$
this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements)); this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
} }
@ -145,11 +146,14 @@ public class Locator {
*/ */
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!"); 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);
if (elements.length > 2) if (elements.length > 2) {
throw new StrolchException("Path is invalid as it does not contain at least 2 elements: " + path); String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, path);
throw new StrolchException(msg);
}
return Arrays.asList(elements); return Arrays.asList(elements);
} }
@ -166,8 +170,11 @@ public class Locator {
* 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 {
if (pathElements.size() > 2) if (pathElements.size() > 2) {
throw new StrolchException("A Path always consists of at least 2 elements: " + pathElements); String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, pathElements);
throw new StrolchException(msg);
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -21,11 +21,11 @@
*/ */
package li.strolch.model; package li.strolch.model;
import li.strolch.model.Locator.LocatorBuilder;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import li.strolch.model.Locator.LocatorBuilder;
/** /**
* 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
@ -41,8 +41,6 @@ public class Order extends GroupedParameterizedElement {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
public static final String PREFIX_ORDER = "OrderPrefix";
private long date; private long date;
private State state; private State state;
@ -91,8 +89,8 @@ public class Order extends GroupedParameterizedElement {
public Order(Element element) { public Order(Element element) {
super.fromDom(element); super.fromDom(element);
String date = element.getAttribute("Date"); String date = element.getAttribute(Tags.DATE);
String state = element.getAttribute("State"); String state = element.getAttribute(Tags.STATE);
// TODO the format should be globally configured // TODO the format should be globally configured
if (date == null || date.isEmpty()) { if (date == null || date.isEmpty()) {
@ -138,18 +136,15 @@ public class Order extends GroupedParameterizedElement {
this.state = state; this.state = state;
} }
/**
* @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom(Document)
*/
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element orderElement = doc.createElement("Order"); Element orderElement = doc.createElement(Tags.ORDER);
fillElement(orderElement); fillElement(orderElement);
// TODO the format should be globally configured // TODO the format should be globally configured
orderElement.setAttribute("Date", Long.toString(this.date)); orderElement.setAttribute(Tags.DATE, Long.toString(this.date));
orderElement.setAttribute("State", this.state.toString()); orderElement.setAttribute(Tags.STATE, this.state.toString());
return orderElement; return orderElement;
} }
@ -168,7 +163,7 @@ public class Order extends GroupedParameterizedElement {
@Override @Override
protected void fillLocator(LocatorBuilder lb) { protected void fillLocator(LocatorBuilder lb) {
lb.append("Order").append(getId()); lb.append(Tags.ORDER).append(getId());
} }
@Override @Override
@ -178,6 +173,7 @@ public class Order extends GroupedParameterizedElement {
return lb.build(); return lb.build();
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

View File

@ -24,7 +24,6 @@ package li.strolch.model;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
@ -68,7 +67,7 @@ public class ParameterBag extends ParameterizedElement {
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element element = doc.createElement("ParameterBag"); Element element = doc.createElement(Tags.PARAMETER_BAG);
fillElement(element); fillElement(element);

View File

@ -21,6 +21,7 @@
*/ */
package li.strolch.model; package li.strolch.model;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -87,8 +88,11 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
* 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)) {
throw new StrolchException("Type must be set on element " + getLocator()); String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg);
}
this.type = type; this.type = type;
} }
@ -193,7 +197,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
@Override @Override
public void fillLocator(LocatorBuilder lb) { public void fillLocator(LocatorBuilder lb) {
lb.append("ParameterizedElement").append(this.id); lb.append(Tags.PARAMETERIZED_ELEMENT).append(this.id);
} }
@Override @Override
@ -208,14 +212,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
protected void fromDom(Element element) { protected void fromDom(Element element) {
super.fromDom(element); super.fromDom(element);
String type = element.getAttribute("Type"); String type = element.getAttribute(Tags.TYPE);
setType(type); setType(type);
// add all the parameters // add all the parameters
NodeList parameterElements = element.getElementsByTagName("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("Type"); String paramtype = paramElement.getAttribute(Tags.TYPE);
if (paramtype.equals(StringParameter.TYPE)) { if (paramtype.equals(StringParameter.TYPE)) {
StringParameter param = new StringParameter(paramElement); StringParameter param = new StringParameter(paramElement);
@ -236,7 +240,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
BooleanParameter param = new BooleanParameter(paramElement); BooleanParameter param = new BooleanParameter(paramElement);
addParameter(param); addParameter(param);
} else { } else {
throw new StrolchException("What kind of parameter is this: " + paramtype); String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, paramtype);
throw new StrolchException(msg);
} }
} }
} }
@ -258,6 +264,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
((ParameterizedElement) clone).setType(this.type); ((ParameterizedElement) clone).setType(this.type);
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

View File

@ -32,7 +32,6 @@ import li.strolch.model.Locator.LocatorBuilder;
public class Resource extends GroupedParameterizedElement { public class Resource extends GroupedParameterizedElement {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
public static final String PREFIX_RESOURCE = "ResourcePrefix";
/** /**
* Empty constructor * Empty constructor
@ -64,7 +63,7 @@ public class Resource extends GroupedParameterizedElement {
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element element = doc.createElement("Resource"); Element element = doc.createElement(Tags.RESOURCE);
fillElement(element); fillElement(element);
return element; return element;
@ -81,7 +80,7 @@ public class Resource extends GroupedParameterizedElement {
@Override @Override
protected void fillLocator(LocatorBuilder lb) { protected void fillLocator(LocatorBuilder lb) {
lb.append("Resource").append(getId()); lb.append(Tags.RESOURCE).append(getId());
} }
@Override @Override
@ -91,6 +90,7 @@ public class Resource extends GroupedParameterizedElement {
return lb.build(); return lb.build();
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

View File

@ -26,7 +26,10 @@ package li.strolch.model;
*/ */
public enum State { public enum State {
CREATED("Created"), OPEN("Open"), EXECUTION("Execution"), CLOSED("Closed"); CREATED("Created"), //$NON-NLS-1$
OPEN("Open"), //$NON-NLS-1$
EXECUTION("Execution"), //$NON-NLS-1$
CLOSED("Closed"); //$NON-NLS-1$
private String state; private String state;

View File

@ -28,7 +28,6 @@ import org.w3c.dom.Element;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
* @param <T>
*/ */
public interface StrolchElement extends Serializable, Comparable<StrolchElement> { public interface StrolchElement extends Serializable, Comparable<StrolchElement> {

View File

@ -0,0 +1,21 @@
package li.strolch.model;
@SuppressWarnings("nls")
public class Tags {
public static final String ID="Id";
public static final String NAME="Name";
public static final String TYPE = "Type";
public static final String DATE="Date";
public static final String STATE="State";
public static final String VALUE="Value";
public static final String INTERPRETATION="Interpretation";
public static final String UOM="Uom";
public static final String HIDDEN="Hidden";
public static final String PARAMETER="Parameter";
public static final String PARAMETERIZED_ELEMENT="ParameterizedElement";
public static final String RESOURCE = "Resource";
public static final String ORDER = "Order";
public static final String PARAMETER_BAG = "ParameterBag";
}

View File

@ -21,14 +21,18 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import org.w3c.dom.Document; import java.text.MessageFormat;
import org.w3c.dom.Element;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.AbstractStrolchElement; import li.strolch.model.AbstractStrolchElement;
import li.strolch.model.Locator; import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder; import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.ParameterizedElement; import li.strolch.model.ParameterizedElement;
import li.strolch.model.Tags;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -113,17 +117,17 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
@Override @Override
public Element toDom(Document doc) { public Element toDom(Document doc) {
Element element = doc.createElement("Parameter"); Element element = doc.createElement(Tags.PARAMETER);
fillElement(element); fillElement(element);
element.setAttribute("Value", getValueAsString()); element.setAttribute(Tags.VALUE, getValueAsString());
if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE))
element.setAttribute("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("Uom", this.uom); element.setAttribute(Tags.UOM, this.uom);
if (this.hidden) if (this.hidden)
element.setAttribute("Hidden", Boolean.toString(this.hidden)); element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
return element; return element;
} }
@ -133,16 +137,20 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
super.fromDom(element); super.fromDom(element);
String typeS = element.getAttribute("Type"); String typeS = element.getAttribute(Tags.TYPE);
if (StringHelper.isEmpty(typeS)) { if (StringHelper.isEmpty(typeS)) {
throw new StrolchException("Type must be set on element with id " + this.id); String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, this.id);
throw new StrolchException(msg);
} else if (!typeS.equals(getType())) { } else if (!typeS.equals(getType())) {
throw new StrolchException(getClass().getSimpleName() + " must have type " + getType() + ", not: " + typeS); String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS);
throw new StrolchException(msg);
} }
String interpretation = element.getAttribute("Interpretation"); String interpretation = element.getAttribute(Tags.INTERPRETATION);
String isHidden = element.getAttribute("Hidden"); String isHidden = element.getAttribute(Tags.HIDDEN);
String uom = element.getAttribute("Uom"); String uom = element.getAttribute(Tags.UOM);
setInterpretation(interpretation); setInterpretation(interpretation);
setUom(uom); setUom(uom);
@ -155,15 +163,16 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
} else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) { } else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
setHidden(false); setHidden(false);
} else { } else {
throw new StrolchException("Boolean string must be either " + Boolean.TRUE.toString() + " or " String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
+ Boolean.FALSE.toString()); msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
throw new StrolchException(msg);
} }
} }
} }
@Override @Override
protected void fillLocator(LocatorBuilder locatorBuilder) { protected void fillLocator(LocatorBuilder locatorBuilder) {
locatorBuilder.append("Parameter").append(this.id); locatorBuilder.append(Tags.PARAMETER).append(this.id);
} }
@Override @Override
@ -184,8 +193,11 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
* if the value is null * 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) {
throw new StrolchException(getType() + " Parameter " + getId() + " may not have a null value!"); String msg = "{0} Parameter {1} may not have a null value!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getType(), getId());
throw new StrolchException(msg);
}
} }
/** /**
@ -201,6 +213,7 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
clone.setUom(this.uom); clone.setUom(this.uom);
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

View File

@ -21,9 +21,12 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import java.text.MessageFormat;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -31,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class BooleanParameter extends AbstractParameter<Boolean> { public class BooleanParameter extends AbstractParameter<Boolean> {
public static final String TYPE = "Boolean"; public static final String TYPE = "Boolean"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private Boolean value = Boolean.FALSE; private Boolean value = Boolean.FALSE;
@ -63,9 +66,10 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
public BooleanParameter(Element element) { public BooleanParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(Boolean.valueOf(valueS)); setValue(Boolean.valueOf(valueS));

View File

@ -22,10 +22,12 @@
package li.strolch.model.parameter; package li.strolch.model.parameter;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.MessageFormat;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -33,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class DateParameter extends AbstractParameter<Long> { public class DateParameter extends AbstractParameter<Long> {
public static final String TYPE = "Date"; public static final String TYPE = "Date"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private Long value; private Long value;
@ -65,9 +67,10 @@ public class DateParameter extends AbstractParameter<Long> {
public DateParameter(Element element) { public DateParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(Long.valueOf(valueS)); setValue(Long.valueOf(valueS));

View File

@ -21,9 +21,13 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import org.w3c.dom.Element; import java.text.MessageFormat;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class FloatParameter extends AbstractParameter<Double> { public class FloatParameter extends AbstractParameter<Double> {
public static final String TYPE = "Float"; public static final String TYPE = "Float"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private Double value = Double.MAX_VALUE; private Double value = Double.MAX_VALUE;
@ -65,9 +69,10 @@ public class FloatParameter extends AbstractParameter<Double> {
public FloatParameter(Element element) { public FloatParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(Double.valueOf(valueS)); setValue(Double.valueOf(valueS));

View File

@ -21,9 +21,13 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import org.w3c.dom.Element; import java.text.MessageFormat;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class IntegerParameter extends AbstractParameter<Integer> { public class IntegerParameter extends AbstractParameter<Integer> {
public static final String TYPE = "Integer"; public static final String TYPE = "Integer"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private Integer value = Integer.MAX_VALUE; private Integer value = Integer.MAX_VALUE;
@ -64,9 +68,10 @@ public class IntegerParameter extends AbstractParameter<Integer> {
public IntegerParameter(Element element) { public IntegerParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(Integer.valueOf(valueS)); setValue(Integer.valueOf(valueS));

View File

@ -23,13 +23,14 @@ package li.strolch.model.parameter;
import java.util.List; 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>> {
public static final String VALUE_SEPARATOR = ";"; //$NON-NLS-1$
/** /**
* Adds a single value to the {@link List} of values * Adds a single value to the {@link List} of values
* *

View File

@ -21,9 +21,12 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import java.text.MessageFormat;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -32,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class LongParameter extends AbstractParameter<Long> { public class LongParameter extends AbstractParameter<Long> {
public static final String TYPE = "Long"; public static final String TYPE = "Long"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
protected Long value; protected Long value;
@ -64,9 +67,10 @@ public class LongParameter extends AbstractParameter<Long> {
public LongParameter(Element element) { public LongParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(Long.valueOf(valueS)); setValue(Long.valueOf(valueS));

View File

@ -35,24 +35,24 @@ public interface Parameter<T> extends StrolchElement {
/** /**
* This interpretation value indicates that the {@link Parameter} has no defined interpretation * This interpretation value indicates that the {@link Parameter} has no defined interpretation
*/ */
public static final String INTERPRETATION_NONE = "None"; public static final String INTERPRETATION_NONE = "None"; //$NON-NLS-1$
/** /**
* This uom value indicates that the {@link Parameter} has no defined uom * This uom value indicates that the {@link Parameter} has no defined uom
*/ */
public static final String UOM_NONE = "None"; public static final String UOM_NONE = "None"; //$NON-NLS-1$
/** /**
* This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference
* to a {@link Resource} * to a {@link Resource}
*/ */
public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; //$NON-NLS-1$
/** /**
* This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference
* to a {@link Order} * to a {@link Order}
*/ */
public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; //$NON-NLS-1$
/** /**
* the value of the parameter as string * the value of the parameter as string
@ -99,7 +99,7 @@ public interface Parameter<T> extends StrolchElement {
/** /**
* Set the UOM of this {@link Parameter} * Set the UOM of this {@link Parameter}
* *
* @param hidden * @param uom
*/ */
public void setUom(String uom); public void setUom(String uom);

View File

@ -21,6 +21,7 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -31,6 +32,7 @@ import org.w3c.dom.Element;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchElement; import li.strolch.model.StrolchElement;
import li.strolch.model.Tags;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -38,7 +40,7 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class StringListParameter extends AbstractParameter<List<String>> implements ListParameter<String> { public class StringListParameter extends AbstractParameter<List<String>> implements ListParameter<String> {
public static final String TYPE = "StringList"; public static final String TYPE = "StringList"; //$NON-NLS-1$
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected List<String> value; protected List<String> value;
@ -71,9 +73,10 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
public StringListParameter(Element element) { public StringListParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(parse(valueS)); setValue(parse(valueS));
@ -83,14 +86,14 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
if (value.isEmpty()) if (value.isEmpty())
return Collections.emptyList(); return Collections.emptyList();
String[] valueArr = value.split(";"); String[] valueArr = value.split(VALUE_SEPARATOR);
return Arrays.asList(valueArr); return Arrays.asList(valueArr);
} }
@Override @Override
public String getValueAsString() { public String getValueAsString() {
if (this.value.isEmpty()) if (this.value.isEmpty())
return ""; return StringHelper.EMPTY;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Iterator<String> iter = this.value.iterator(); Iterator<String> iter = this.value.iterator();
@ -99,7 +102,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
sb.append(iter.next()); sb.append(iter.next());
if (iter.hasNext()) if (iter.hasNext())
sb.append(";"); sb.append(VALUE_SEPARATOR);
} }
return sb.toString(); return sb.toString();

View File

@ -21,9 +21,13 @@
*/ */
package li.strolch.model.parameter; package li.strolch.model.parameter;
import org.w3c.dom.Element; import java.text.MessageFormat;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.StringHelper;
/** /**
@ -32,10 +36,11 @@ import ch.eitchnet.utils.helper.StringHelper;
*/ */
public class StringParameter extends AbstractParameter<String> { public class StringParameter extends AbstractParameter<String> {
public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$
public static final String TYPE = "String"; //$NON-NLS-1$
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
public static final String TYPE = "String";
private String value = "-"; private String value = UNDEFINED_VALUE;
/** /**
* Empty constructor * Empty constructor
@ -65,9 +70,10 @@ public class StringParameter extends AbstractParameter<String> {
public StringParameter(Element element) { public StringParameter(Element element) {
super.fromDom(element); super.fromDom(element);
String valueS = element.getAttribute("Value"); String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) { if (StringHelper.isEmpty(valueS)) {
throw new StrolchException("No value defined for " + this.id); String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
} }
setValue(valueS); setValue(valueS);

View File

@ -25,7 +25,7 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ITimeValue<T> getNextMatch(final Long time, final T value) { public ITimeValue<T> getNextMatch(final Long time, final T value) {
Collection<ITimeValue<T>> futureValues = timeVariable.getFutureValues(time); Collection<ITimeValue<T>> futureValues = this.timeVariable.getFutureValues(time);
for (ITimeValue<T> iTimeValue : futureValues) { for (ITimeValue<T> iTimeValue : futureValues) {
if (iTimeValue.getValue().matches(value)) { if (iTimeValue.getValue().matches(value)) {
return iTimeValue; return iTimeValue;
@ -37,7 +37,7 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ITimeValue<T> getPreviousMatch(final Long time, final T value) { public ITimeValue<T> getPreviousMatch(final Long time, final T value) {
Collection<ITimeValue<T>> pastValues = timeVariable.getPastValues(time); Collection<ITimeValue<T>> pastValues = this.timeVariable.getPastValues(time);
List<ITimeValue<T>> asList = new ArrayList<ITimeValue<T>>(pastValues); List<ITimeValue<T>> asList = new ArrayList<ITimeValue<T>>(pastValues);
Collections.reverse(asList); Collections.reverse(asList);
for (ITimeValue<T> iTimeValue : asList) { for (ITimeValue<T> iTimeValue : asList) {
@ -50,17 +50,17 @@ public class TimedState<T extends IValue> implements ITimedState<T>, Serializabl
@Override @Override
public void applyChange(final IValueChange<T> change) { public void applyChange(final IValueChange<T> change) {
timeVariable.applyChange(change); this.timeVariable.applyChange(change);
} }
@Override @Override
public ITimeValue<T> getStateAt(final Long time) { public ITimeValue<T> getStateAt(final Long time) {
return timeVariable.getValueAt(time); return this.timeVariable.getValueAt(time);
} }
@Override @Override
public ITimeVariable<T> getTimeEvolution() { public ITimeVariable<T> getTimeEvolution() {
return timeVariable; return this.timeVariable;
} }
} }

View File

@ -12,8 +12,7 @@ import java.util.SortedSet;
* @param <T> * @param <T>
* the backing value of the timed value object * the backing value of the timed value object
*/ */
@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

View File

@ -26,23 +26,23 @@ public class AString implements Serializable {
} }
public String getString() { public String getString() {
return string; return this.string;
} }
public boolean isInverse() { public boolean isInverse() {
return inverse; return this.inverse;
} }
public AString getInverse() { public AString getInverse() {
return new AString(string, !inverse); return new AString(this.string, !this.inverse);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (inverse ? 1231 : 1237); result = prime * result + (this.inverse ? 1231 : 1237);
result = prime * result + ((string == null) ? 0 : string.hashCode()); result = prime * result + ((this.string == null) ? 0 : this.string.hashCode());
return result; return result;
} }
@ -55,19 +55,26 @@ public class AString implements Serializable {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
AString other = (AString) obj; AString other = (AString) obj;
if (inverse != other.inverse) if (this.inverse != other.inverse)
return false; return false;
if (string == null) { if (this.string == null) {
if (other.string != null) if (other.string != null)
return false; return false;
} else if (!string.equals(other.string)) } else if (!this.string.equals(other.string))
return false; return false;
return true; return true;
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "AString [string=" + string + ", inverse=" + inverse + "]"; StringBuilder sb = new StringBuilder();
sb.append("AString [string=");
sb.append(this.string);
sb.append(", inverse=");
sb.append(this.inverse);
sb.append("]");
return sb.toString();
} }
} }

View File

@ -40,18 +40,23 @@ public class DoubleValue implements IValue<Double>, Serializable {
@Override @Override
public DoubleValue add(Double o) { public DoubleValue add(Double o) {
value += o; this.value += o;
return this; return this;
} }
@Override @Override
public Double getValue() { public Double getValue() {
return value; return this.value;
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "DoubleValue [value=" + value + "]"; StringBuilder sb = new StringBuilder();
sb.append("DoubleValue [value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
} }
@Override @Override
@ -66,14 +71,14 @@ public class DoubleValue implements IValue<Double>, Serializable {
@Override @Override
public DoubleValue getCopy(){ public DoubleValue getCopy(){
return new DoubleValue(value); return new DoubleValue(this.value);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result; return result;
} }
@ -86,10 +91,10 @@ public class DoubleValue implements IValue<Double>, Serializable {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
DoubleValue other = (DoubleValue) obj; DoubleValue other = (DoubleValue) obj;
if (value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null)
return false; return false;
} else if (!value.equals(other.value)) } else if (!this.value.equals(other.value))
return false; return false;
return true; return true;
} }

View File

@ -6,8 +6,7 @@ import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValue;
/** /**
* {@link IValue} implementation to work with Integer valued {@link ITimeValue} * {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects
* objects
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
@ -33,7 +32,7 @@ public class IntegerValue implements IValue<Integer>, Serializable {
@Override @Override
public IntegerValue add(Integer o) { public IntegerValue add(Integer o) {
value += o; this.value += o;
return this; return this;
} }
@ -44,7 +43,7 @@ public class IntegerValue implements IValue<Integer>, Serializable {
@Override @Override
public Integer getValue() { public Integer getValue() {
return value; return this.value;
} }
@Override @Override
@ -52,21 +51,26 @@ public class IntegerValue implements IValue<Integer>, Serializable {
return new IntegerValue(-getValue()); return new IntegerValue(-getValue());
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "IntegerValue [value=" + value + "]"; StringBuilder sb = new StringBuilder();
sb.append("IntegerValue [value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
} }
@Override @Override
public IntegerValue getCopy() { public IntegerValue getCopy() {
return new IntegerValue(value); return new IntegerValue(this.value);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result; return result;
} }
@ -79,10 +83,10 @@ public class IntegerValue implements IValue<Integer>, Serializable {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
IntegerValue other = (IntegerValue) obj; IntegerValue other = (IntegerValue) obj;
if (value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null)
return false; return false;
} else if (!value.equals(other.value)) } else if (!this.value.equals(other.value))
return false; return false;
return true; return true;
} }

View File

@ -10,9 +10,8 @@ import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValue;
/** /**
* {@link IValue} implementation to work with String valued {@link ITimeValue} * {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object
* objects. Since a java.util.String object does not define a inverse, a * does not define a inverse, a algebraic {@link AString} wrapper is used.
* algebraic {@link AString} wrapper is used.
* *
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
@ -34,7 +33,7 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
@Override @Override
public Set<AString> getValue() { public Set<AString> getValue() {
return aStrings; return this.aStrings;
} }
@Override @Override
@ -44,7 +43,7 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) { for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
AString toAdd = iter1.next(); AString toAdd = iter1.next();
for (Iterator<AString> iter = 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())
@ -55,19 +54,19 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
} }
} }
} }
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 this.getValue().equals(other.getValue()); return getValue().equals(other.getValue());
} }
@Override @Override
public IValue<Set<AString>> getInverse() { public IValue<Set<AString>> getInverse() {
Set<AString> inverseSet = new HashSet<AString>(); Set<AString> inverseSet = new HashSet<AString>();
for (AString as : aStrings) { for (AString as : this.aStrings) {
inverseSet.add(as.getInverse()); inverseSet.add(as.getInverse());
} }
StringSetValue inverse = new StringSetValue(); StringSetValue inverse = new StringSetValue();
@ -77,12 +76,17 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
@Override @Override
public StringSetValue getCopy() { public StringSetValue getCopy() {
return new StringSetValue(aStrings); return new StringSetValue(this.aStrings);
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "StringSetValue [aStrings=" + aStrings + "]"; StringBuilder sb = new StringBuilder();
sb.append("StringSetValue [aStrings=");
sb.append(this.aStrings);
sb.append("]");
return sb.toString();
} }
} }

View File

@ -9,62 +9,69 @@ import li.strolch.model.timevalue.IValue;
* @author Martin Smock <smock.martin@gmail.com> * @author Martin Smock <smock.martin@gmail.com>
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class TimeValue<T extends IValue> implements ITimeValue <T>, Serializable { public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected final Long time; protected final Long time;
protected T value; protected T value;
/** /**
* @param time * @param time
* @param value * @param value
*/ */
public TimeValue(final Long time, final T value){ public TimeValue(final Long time, final T value) {
this.time = time; this.time = time;
this.value = value; this.value = value;
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T getValue() { public T getValue() {
return (T) value.getCopy(); return (T) this.value.getCopy();
} }
@Override @Override
public Long getTime() { public Long getTime() {
return time; return this.time;
} }
@Override @Override
public ITimeValue<T> setValue(final T value) { public ITimeValue<T> setValue(final T value) {
this.value = value; this.value = value;
return this; return this;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public ITimeValue<T> add(final T change) { public ITimeValue<T> add(final T change) {
this.value.add(change.getValue()); this.value.add(change.getValue());
return this; return this;
} }
@Override @Override
public int compareTo(final ITimeValue<T> arg0) { public int compareTo(final ITimeValue<T> arg0) {
return this.getTime().compareTo(arg0.getTime()); return this.getTime().compareTo(arg0.getTime());
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "TimeValue [time=" + time + ", value=" + value + "]"; StringBuilder sb = new StringBuilder();
sb.append("TimeValue [time=");
sb.append(this.time);
sb.append(", value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((time == null) ? 0 : time.hashCode()); result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result; return result;
} }
@ -78,17 +85,17 @@ public class TimeValue<T extends IValue> implements ITimeValue <T>, Serializable
return false; return false;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
TimeValue<T> other = (TimeValue<T>) obj; TimeValue<T> other = (TimeValue<T>) obj;
if (time == null) { if (this.time == null) {
if (other.time != null) if (other.time != null)
return false; return false;
} else if (!time.equals(other.time)) } else if (!this.time.equals(other.time))
return false; return false;
if (value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null)
return false; return false;
} else if (!value.equals(other.value)) } else if (!this.value.equals(other.value))
return false; return false;
return true; return true;
} }
} }

View File

@ -25,7 +25,7 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
@Override @Override
public ITimeValue<T> getValueAt(final Long time) { public ITimeValue<T> getValueAt(final Long time) {
ITimeValue<T> tmp = null; ITimeValue<T> tmp = null;
for (ITimeValue<T> value : container) { for (ITimeValue<T> value : this.container) {
if (value.getTime() <= time) { if (value.getTime() <= time) {
tmp = value; tmp = value;
} else { } else {
@ -41,25 +41,25 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
if (current != null && current.getTime().equals(time)) { if (current != null && current.getTime().equals(time)) {
current.setValue(targetValue); current.setValue(targetValue);
} else { } else {
container.add(new TimeValue<T>(time, targetValue)); this.container.add(new TimeValue<T>(time, targetValue));
} }
} }
@Override @Override
public SortedSet<ITimeValue<T>> getFutureValues(final Long time) { public SortedSet<ITimeValue<T>> getFutureValues(final Long time) {
TimeValue<T> picker = new TimeValue<T>(time, null); TimeValue<T> picker = new TimeValue<T>(time, null);
return new TreeSet<ITimeValue<T>>(container.tailSet(picker)); return new TreeSet<ITimeValue<T>>(this.container.tailSet(picker));
} }
@Override @Override
public Collection<ITimeValue<T>> getPastValues(final Long time) { public Collection<ITimeValue<T>> getPastValues(final Long time) {
TimeValue<T> picker = new TimeValue<T>(time, null); TimeValue<T> picker = new TimeValue<T>(time, null);
return new TreeSet<ITimeValue<T>>(container.headSet(picker)); return new TreeSet<ITimeValue<T>>(this.container.headSet(picker));
} }
@Override @Override
public SortedSet<ITimeValue<T>> getValues() { public SortedSet<ITimeValue<T>> getValues() {
return new TreeSet<ITimeValue<T>>(container); return new TreeSet<ITimeValue<T>>(this.container);
} }
@Override @Override
@ -73,11 +73,11 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
ITimeValue<T> initialValue = getValueAt(change.getTime()); ITimeValue<T> initialValue = getValueAt(change.getTime());
if (initialValue == null) { if (initialValue == null) {
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), change.getValue()); ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), change.getValue());
container.add(newValue); this.container.add(newValue);
} else if (initialValue.getTime().longValue() < change.getTime().longValue()) { } else if (initialValue.getTime().longValue() < change.getTime().longValue()) {
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), initialValue.getValue()); ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), initialValue.getValue());
newValue.add(change.getValue()); newValue.add(change.getValue());
container.add(newValue); this.container.add(newValue);
} }
compact(); compact();
} }
@ -86,10 +86,10 @@ public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Seriali
@Override @Override
public void compact() { public void compact() {
if (container.size() < 2) if (this.container.size() < 2)
return; return;
Iterator<ITimeValue<T>> iterator = container.iterator(); Iterator<ITimeValue<T>> iterator = this.container.iterator();
ITimeValue<T> predecessor = iterator.next(); ITimeValue<T> predecessor = iterator.next();
while (iterator.hasNext()) { while (iterator.hasNext()) {

View File

@ -12,7 +12,7 @@ import li.strolch.model.timevalue.IValueChange;
public class ValueChange<T extends IValue> implements IValueChange<T>, Serializable { public class ValueChange<T extends IValue> implements IValueChange<T>, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected final Long time; protected final Long time;
protected final T value; protected final T value;
@ -27,19 +27,19 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
@Override @Override
public Long getTime() { public Long getTime() {
return time; return this.time;
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T getValue() { public T getValue() {
return (T) value.getCopy(); return (T) this.value.getCopy();
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public IValueChange<T> getInverse() { public IValueChange<T> getInverse() {
return new ValueChange(time, value.getInverse()); return new ValueChange(this.time, this.value.getInverse());
} }
@Override @Override
@ -51,15 +51,15 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ValueChange<?> other = (ValueChange<?>) obj; ValueChange<?> other = (ValueChange<?>) obj;
if (time == null) { if (this.time == null) {
if (other.time != null) if (other.time != null)
return false; return false;
} else if (!time.equals(other.time)) } else if (!this.time.equals(other.time))
return false; return false;
if (value == null) { if (this.value == null) {
if (other.value != null) if (other.value != null)
return false; return false;
} else if (!value.equals(other.value)) } else if (!this.value.equals(other.value))
return false; return false;
return true; return true;
} }
@ -68,14 +68,21 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((time == null) ? 0 : time.hashCode()); result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result; return result;
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
return "ValueChange [time=" + time + ", value=" + value + "]"; StringBuilder sb = new StringBuilder();
sb.append("ValueChange [time=");
sb.append(this.time);
sb.append(", value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
} }
} }

View File

@ -1,6 +1,8 @@
package li.strolch.model.timedstate; package li.strolch.model.timedstate;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.IValueChange;
import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.DoubleValue;
@ -25,69 +27,69 @@ public class TimeStateTest {
@Before @Before
public void before() { public void before() {
final IValueChange<DoubleValue> change1 = new ValueChange<DoubleValue>(t10, expectedValue1); final IValueChange<DoubleValue> change1 = new ValueChange<DoubleValue>(this.t10, this.expectedValue1);
state.applyChange(change1); this.state.applyChange(change1);
final ITimeValue<DoubleValue> stateAt9 = state.getStateAt(9L); final ITimeValue<DoubleValue> stateAt9 = this.state.getStateAt(9L);
Assert.assertNull(stateAt9); assertNull(stateAt9);
final ITimeValue<DoubleValue> stateAt11 = state.getStateAt(11L); final ITimeValue<DoubleValue> stateAt11 = this.state.getStateAt(11L);
Assert.assertNotNull(stateAt11); assertNotNull(stateAt11);
Assert.assertEquals(true, stateAt11.getValue().matches(expectedValue1)); assertEquals(true, stateAt11.getValue().matches(this.expectedValue1));
final IValueChange<DoubleValue> change2 = new ValueChange<DoubleValue>(t30, expectedValue1); final IValueChange<DoubleValue> change2 = new ValueChange<DoubleValue>(this.t30, this.expectedValue1);
state.applyChange(change2); this.state.applyChange(change2);
final ITimeValue<DoubleValue> stateAt31 = state.getStateAt(31L); final ITimeValue<DoubleValue> stateAt31 = this.state.getStateAt(31L);
Assert.assertNotNull(stateAt31); assertNotNull(stateAt31);
Assert.assertEquals(true, stateAt31.getValue().matches(expectedValue2)); assertEquals(true, stateAt31.getValue().matches(this.expectedValue2));
} }
@Test @Test
public void testGetNextMatch() { public void testGetNextMatch() {
ITimeValue<DoubleValue> nextMatch = state.getNextMatch(t0, expectedValue1); ITimeValue<DoubleValue> nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1);
Assert.assertNotNull(nextMatch); assertNotNull(nextMatch);
Assert.assertEquals(t10, nextMatch.getTime()); assertEquals(this.t10, nextMatch.getTime());
nextMatch = state.getNextMatch(t20, expectedValue1); nextMatch = this.state.getNextMatch(this.t20, this.expectedValue1);
Assert.assertNull(nextMatch); assertNull(nextMatch);
nextMatch = state.getNextMatch(t20, expectedValue2); nextMatch = this.state.getNextMatch(this.t20, this.expectedValue2);
Assert.assertNotNull(nextMatch); assertNotNull(nextMatch);
Assert.assertEquals(t30, nextMatch.getTime()); assertEquals(this.t30, nextMatch.getTime());
nextMatch = state.getNextMatch(t30, expectedValue2); nextMatch = this.state.getNextMatch(this.t30, this.expectedValue2);
Assert.assertNotNull(nextMatch); assertNotNull(nextMatch);
Assert.assertEquals(t30, nextMatch.getTime()); assertEquals(this.t30, nextMatch.getTime());
nextMatch = state.getNextMatch(t100, expectedValue1); nextMatch = this.state.getNextMatch(this.t100, this.expectedValue1);
Assert.assertNull(nextMatch); assertNull(nextMatch);
nextMatch = state.getNextMatch(t100, expectedValue2); nextMatch = this.state.getNextMatch(this.t100, this.expectedValue2);
Assert.assertNull(nextMatch); assertNull(nextMatch);
} }
@Test @Test
public void testGetPreviousMatch() { public void testGetPreviousMatch() {
ITimeValue<DoubleValue> previousMatch = state.getPreviousMatch(t100, expectedValue2); ITimeValue<DoubleValue> previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2);
Assert.assertNotNull(previousMatch); assertNotNull(previousMatch);
Assert.assertEquals(t30, previousMatch.getTime()); assertEquals(this.t30, previousMatch.getTime());
previousMatch = state.getPreviousMatch(t30, expectedValue2); previousMatch = this.state.getPreviousMatch(this.t30, this.expectedValue2);
Assert.assertNull(previousMatch); assertNull(previousMatch);
previousMatch = state.getPreviousMatch(t20, expectedValue2); previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue2);
Assert.assertNull(previousMatch); assertNull(previousMatch);
previousMatch = state.getPreviousMatch(t20, expectedValue1); previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue1);
Assert.assertNotNull(previousMatch); assertNotNull(previousMatch);
Assert.assertEquals(t10, previousMatch.getTime()); assertEquals(this.t10, previousMatch.getTime());
previousMatch = state.getPreviousMatch(t10, expectedValue1); previousMatch = this.state.getPreviousMatch(this.t10, this.expectedValue1);
Assert.assertNull(previousMatch); assertNull(previousMatch);
} }

View File

@ -1,9 +1,12 @@
package li.strolch.model.timevalue; package li.strolch.model.timevalue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collection; import java.util.Collection;
import java.util.SortedSet; import java.util.SortedSet;
import junit.framework.Assert;
import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.DoubleValue;
import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.TimeVariable;
import li.strolch.model.timevalue.impl.ValueChange; import li.strolch.model.timevalue.impl.ValueChange;
@ -24,16 +27,16 @@ public class FloatTimeVariableTest {
*/ */
@Before @Before
public void init() { public void init() {
timeVariable = new TimeVariable<DoubleValue>(); this.timeVariable = new TimeVariable<DoubleValue>();
for (long i = 0; i < MAX; i += STEP) { for (long i = 0; i < MAX; i += STEP) {
timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i)); this.timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i));
} }
} }
@Test @Test
public void testGetValueAt() { public void testGetValueAt() {
ITimeValue<DoubleValue> valueAt = timeVariable.getValueAt(PICK); ITimeValue<DoubleValue> valueAt = this.timeVariable.getValueAt(PICK);
Assert.assertEquals(PICK.doubleValue(), valueAt.getValue().getValue()); assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001);
} }
/** /**
@ -41,12 +44,12 @@ public class FloatTimeVariableTest {
*/ */
@Test @Test
public void testGetFutureValues() { public void testGetFutureValues() {
Collection<ITimeValue<DoubleValue>> futureValues = timeVariable.getFutureValues(PICK); Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK; Long expectedTime = PICK;
Double expectedValue = PICK.doubleValue(); Double expectedValue = PICK.doubleValue();
for (ITimeValue<DoubleValue> value : futureValues) { for (ITimeValue<DoubleValue> value : futureValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
expectedTime += STEP; expectedTime += STEP;
expectedValue += STEP.doubleValue(); expectedValue += STEP.doubleValue();
} }
@ -58,12 +61,12 @@ public class FloatTimeVariableTest {
*/ */
@Test @Test
public void testGetPastValues() { public void testGetPastValues() {
Collection<ITimeValue<DoubleValue>> pastValues = timeVariable.getPastValues(MAX); Collection<ITimeValue<DoubleValue>> pastValues = this.timeVariable.getPastValues(MAX);
Long expectedTime = 0L; Long expectedTime = 0L;
Double expectedValue = expectedTime.doubleValue(); Double expectedValue = expectedTime.doubleValue();
for (ITimeValue<DoubleValue> value : pastValues) { for (ITimeValue<DoubleValue> value : pastValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); assertTrue(value.getValue().matches(new DoubleValue(expectedValue)));
expectedTime += STEP; expectedTime += STEP;
expectedValue += STEP.doubleValue(); expectedValue += STEP.doubleValue();
} }
@ -78,16 +81,16 @@ public class FloatTimeVariableTest {
DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); DoubleValue doubleValue = new DoubleValue(STEP.doubleValue());
IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue); IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue);
timeVariable.applyChange(change); this.timeVariable.applyChange(change);
Collection<ITimeValue<DoubleValue>> futureValues = timeVariable.getFutureValues(PICK); Collection<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK; Long expectedTime = PICK;
IValue<Double> expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue()); IValue<Double> expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue());
for (ITimeValue<DoubleValue> value : futureValues) { for (ITimeValue<DoubleValue> value : futureValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(expectedValue.matches(value.getValue())); assertTrue(expectedValue.matches(value.getValue()));
expectedTime += STEP; expectedTime += STEP;
expectedValue = expectedValue.add(STEP.doubleValue()); expectedValue = expectedValue.add(STEP.doubleValue());
} }
@ -99,18 +102,18 @@ public class FloatTimeVariableTest {
@Test @Test
public void testApply2Change() { public void testApply2Change() {
timeVariable = new TimeVariable<DoubleValue>(); this.timeVariable = new TimeVariable<DoubleValue>();
DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); DoubleValue doubleValue = new DoubleValue(STEP.doubleValue());
IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue); IValueChange<DoubleValue> change = new ValueChange<DoubleValue>(PICK, doubleValue);
timeVariable.applyChange(change); this.timeVariable.applyChange(change);
ITimeValue<DoubleValue> actual = timeVariable.getValueAt(PICK); ITimeValue<DoubleValue> actual = this.timeVariable.getValueAt(PICK);
Assert.assertNotNull(actual); assertNotNull(actual);
IValue<Double> expectedValue = new DoubleValue(STEP.doubleValue()); IValue<Double> expectedValue = new DoubleValue(STEP.doubleValue());
Assert.assertEquals(true, actual.getValue().matches(expectedValue)); assertEquals(true, actual.getValue().matches(expectedValue));
} }
/** /**
@ -120,15 +123,15 @@ public class FloatTimeVariableTest {
@Test @Test
public void testCompact() { public void testCompact() {
timeVariable = new TimeVariable<DoubleValue>(); this.timeVariable = new TimeVariable<DoubleValue>();
for (Long i = 0L; i < MAX; i += STEP) { for (Long i = 0L; i < MAX; i += STEP) {
timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); this.timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue()));
} }
// call // call
timeVariable.compact(); this.timeVariable.compact();
// check // check
SortedSet<ITimeValue<DoubleValue>> futureValues = timeVariable.getFutureValues(0L); SortedSet<ITimeValue<DoubleValue>> futureValues = this.timeVariable.getFutureValues(0L);
Assert.assertEquals(1, futureValues.size()); assertEquals(1, futureValues.size());
} }
} }

View File

@ -1,11 +1,13 @@
package li.strolch.model.timevalue; package li.strolch.model.timevalue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.SortedSet;
import junit.framework.Assert;
import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.IntegerValue;
import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.TimeVariable;
import li.strolch.model.timevalue.impl.ValueChange; import li.strolch.model.timevalue.impl.ValueChange;
@ -32,19 +34,19 @@ public class IntegerTimeVariableTest {
*/ */
@Before @Before
public void init() { public void init() {
timeVariable = new TimeVariable<IntegerValue>(); this.timeVariable = new TimeVariable<IntegerValue>();
for (int i = 0; i < MAX; i += STEP) { for (int i = 0; i < MAX; i += STEP) {
IntegerValue expectedValue = new IntegerValue(i); IntegerValue expectedValue = new IntegerValue(i);
Long time = Long.valueOf(i); Long time = Long.valueOf(i);
expectedValues.put(time, expectedValue); this.expectedValues.put(time, expectedValue);
timeVariable.setValueAt(time, expectedValue); this.timeVariable.setValueAt(time, expectedValue);
} }
} }
@Test @Test
public void testGetValueAt() { public void testGetValueAt() {
ITimeValue<IntegerValue> valueAt = timeVariable.getValueAt(PICK); ITimeValue<IntegerValue> valueAt = this.timeVariable.getValueAt(PICK);
Assert.assertEquals(expectedValues.get(PICK), valueAt.getValue()); assertEquals(this.expectedValues.get(PICK), valueAt.getValue());
} }
/** /**
@ -52,29 +54,28 @@ public class IntegerTimeVariableTest {
*/ */
@Test @Test
public void testGetFutureValues() { public void testGetFutureValues() {
Collection<ITimeValue<IntegerValue>> futureValues = timeVariable.getFutureValues(PICK); Collection<ITimeValue<IntegerValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK; Long expectedTime = PICK;
Integer expectedValue = PICK.intValue(); Integer expectedValue = PICK.intValue();
for (ITimeValue<IntegerValue> value : futureValues) { for (ITimeValue<IntegerValue> value : futureValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); assertTrue(value.getValue().matches(new IntegerValue(expectedValue)));
expectedTime += STEP; expectedTime += STEP;
expectedValue += STEP.intValue(); expectedValue += STEP.intValue();
} }
} }
/** /**
* 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() {
Collection<ITimeValue<IntegerValue>> pastValues = timeVariable.getPastValues(MAX); Collection<ITimeValue<IntegerValue>> pastValues = this.timeVariable.getPastValues(MAX);
Long expectedTime = 0L; Long expectedTime = 0L;
Integer expectedValue = expectedTime.intValue(); Integer expectedValue = expectedTime.intValue();
for (ITimeValue<IntegerValue> value : pastValues) { for (ITimeValue<IntegerValue> value : pastValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); assertTrue(value.getValue().matches(new IntegerValue(expectedValue)));
expectedTime += STEP; expectedTime += STEP;
expectedValue += STEP.intValue(); expectedValue += STEP.intValue();
} }
@ -89,40 +90,39 @@ public class IntegerTimeVariableTest {
IntegerValue integerValue = new IntegerValue(STEP.intValue()); IntegerValue integerValue = new IntegerValue(STEP.intValue());
IValueChange<IntegerValue> change = new ValueChange<IntegerValue>(PICK, integerValue); IValueChange<IntegerValue> change = new ValueChange<IntegerValue>(PICK, integerValue);
timeVariable.applyChange(change); this.timeVariable.applyChange(change);
Collection<ITimeValue<IntegerValue>> futureValues = timeVariable.getFutureValues(PICK); Collection<ITimeValue<IntegerValue>> futureValues = this.timeVariable.getFutureValues(PICK);
Long expectedTime = PICK; Long expectedTime = PICK;
IValue<Integer> expectedValue = new IntegerValue(PICK.intValue() + change.getValue().getValue()); IValue<Integer> expectedValue = new IntegerValue(PICK.intValue() + change.getValue().getValue());
for (ITimeValue<IntegerValue> value : futureValues) { for (ITimeValue<IntegerValue> value : futureValues) {
Assert.assertEquals(expectedTime, value.getTime()); assertEquals(expectedTime, value.getTime());
Assert.assertTrue(expectedValue.matches(value.getValue())); assertTrue(expectedValue.matches(value.getValue()));
expectedTime += STEP; expectedTime += STEP;
expectedValue = expectedValue.add(STEP.intValue()); expectedValue = expectedValue.add(STEP.intValue());
} }
} }
/** /**
* 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() {
timeVariable = new TimeVariable<IntegerValue>(); this.timeVariable = new TimeVariable<IntegerValue>();
for (Long i = 0L; i < MAX; i += STEP) { for (Long i = 0L; i < MAX; i += STEP) {
timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); this.timeVariable.setValueAt(i, new IntegerValue(STEP.intValue()));
} }
// call // call
timeVariable.compact(); this.timeVariable.compact();
// check // check
SortedSet<ITimeValue<IntegerValue>> futureValues = timeVariable.getFutureValues(0L); SortedSet<ITimeValue<IntegerValue>> futureValues = this.timeVariable.getFutureValues(0L);
Assert.assertEquals(1, futureValues.size()); assertEquals(1, futureValues.size());
ITimeValue<IntegerValue> next = futureValues.iterator().next(); ITimeValue<IntegerValue> next = futureValues.iterator().next();
Assert.assertEquals(Long.valueOf(0), next.getTime()); assertEquals(Long.valueOf(0), next.getTime());
} }
} }

View File

@ -1,5 +1,8 @@
package li.strolch.model.timevalue; package li.strolch.model.timevalue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -7,7 +10,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import junit.framework.Assert;
import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.AString;
import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.StringSetValue;
import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.TimeVariable;
@ -28,41 +30,41 @@ public class StringTimeVariableTest {
@Before @Before
public void init() { public void init() {
timeVariable = new TimeVariable<IValue<Set<AString>>>(); this.timeVariable = new TimeVariable<IValue<Set<AString>>>();
for (Long i = 0L; i < MAX; i += STEP) { for (Long i = 0L; i < MAX; i += STEP) {
Set<AString> testSet = new HashSet<AString>(); Set<AString> testSet = new HashSet<AString>();
StringSetValue testValue = new StringSetValue(testSet); StringSetValue testValue = new StringSetValue(testSet);
testSets.put(i, testValue); this.testSets.put(i, testValue);
testSet.add(new AString("string " + i)); testSet.add(new AString("string " + i)); //$NON-NLS-1$
timeVariable.setValueAt(i, new StringSetValue(testSet)); this.timeVariable.setValueAt(i, new StringSetValue(testSet));
} }
} }
@Test @Test
public void testGetValueAt() { public void testGetValueAt() {
ITimeValue<IValue<Set<AString>>> valueAt = timeVariable.getValueAt(PICK); ITimeValue<IValue<Set<AString>>> valueAt = this.timeVariable.getValueAt(PICK);
Assert.assertEquals(true, valueAt.getValue().matches(testSets.get(PICK))); assertEquals(true, valueAt.getValue().matches(this.testSets.get(PICK)));
} }
@Test @Test
public void testGetFutureValues() { public void testGetFutureValues() {
Collection<ITimeValue<IValue<Set<AString>>>> futureValues = timeVariable.getFutureValues(PICK); Collection<ITimeValue<IValue<Set<AString>>>> futureValues = this.timeVariable.getFutureValues(PICK);
for (ITimeValue<IValue<Set<AString>>> iTimeValue : futureValues) { for (ITimeValue<IValue<Set<AString>>> iTimeValue : futureValues) {
Long time = iTimeValue.getTime(); Long time = iTimeValue.getTime();
Assert.assertEquals(true, time >= PICK); assertEquals(true, time >= PICK);
Assert.assertNotNull(iTimeValue.getValue()); assertNotNull(iTimeValue.getValue());
Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time)));
} }
} }
@Test @Test
public void testGetPastValues() { public void testGetPastValues() {
Collection<ITimeValue<IValue<Set<AString>>>> pastValues = timeVariable.getPastValues(PICK); Collection<ITimeValue<IValue<Set<AString>>>> pastValues = this.timeVariable.getPastValues(PICK);
for (ITimeValue<IValue<Set<AString>>> iTimeValue : pastValues) { for (ITimeValue<IValue<Set<AString>>> iTimeValue : pastValues) {
Long time = iTimeValue.getTime(); Long time = iTimeValue.getTime();
Assert.assertEquals(true, time < PICK); assertEquals(true, time < PICK);
Assert.assertNotNull(iTimeValue.getValue()); assertNotNull(iTimeValue.getValue());
Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time)));
} }
} }
@ -70,45 +72,45 @@ public class StringTimeVariableTest {
public void testApplyChange() { public void testApplyChange() {
Set<AString> testSet = new HashSet<AString>(); Set<AString> testSet = new HashSet<AString>();
testSet.add(new AString("Martin")); testSet.add(new AString("Martin")); //$NON-NLS-1$
StringSetValue testValue = new StringSetValue(testSet); StringSetValue testValue = new StringSetValue(testSet);
timeVariable = new TimeVariable<IValue<Set<AString>>>(); this.timeVariable = new TimeVariable<IValue<Set<AString>>>();
timeVariable.setValueAt(PICK, testValue); this.timeVariable.setValueAt(PICK, testValue);
IValue<Set<AString>> inverseTestValue = testValue.getInverse(); IValue<Set<AString>> inverseTestValue = testValue.getInverse();
IValueChange<IValue<Set<AString>>> change = new ValueChange<IValue<Set<AString>>>(PICK, inverseTestValue); IValueChange<IValue<Set<AString>>> change = new ValueChange<IValue<Set<AString>>>(PICK, inverseTestValue);
timeVariable.applyChange(change); this.timeVariable.applyChange(change);
// check the future values // check the future values
Collection<ITimeValue<IValue<Set<AString>>>> futureValues = timeVariable.getFutureValues(0L); Collection<ITimeValue<IValue<Set<AString>>>> futureValues = this.timeVariable.getFutureValues(0L);
for (ITimeValue<IValue<Set<AString>>> iTimeValue : futureValues) { for (ITimeValue<IValue<Set<AString>>> iTimeValue : futureValues) {
System.out.println("++ " + iTimeValue); System.out.println("++ " + iTimeValue); //$NON-NLS-1$
} }
Assert.assertEquals(1, futureValues.size()); // a empty one is left assertEquals(1, futureValues.size()); // a empty one is left
} }
@Test @Test
public void testCompact() { public void testCompact() {
timeVariable = new TimeVariable<IValue<Set<AString>>>(); this.timeVariable = new TimeVariable<IValue<Set<AString>>>();
for (Long i = 0L; i < MAX; i += STEP) { for (Long i = 0L; i < MAX; i += STEP) {
Set<AString> testSet = new HashSet<AString>(); Set<AString> testSet = new HashSet<AString>();
StringSetValue testValue = new StringSetValue(testSet); StringSetValue testValue = new StringSetValue(testSet);
testSets.put(i, testValue); this.testSets.put(i, testValue);
testSet.add(new AString("same string")); testSet.add(new AString("same string")); //$NON-NLS-1$
timeVariable.setValueAt(i, new StringSetValue(testSet)); this.timeVariable.setValueAt(i, new StringSetValue(testSet));
} }
SortedSet<ITimeValue<IValue<Set<AString>>>> valuesInitial = timeVariable.getFutureValues(0L); SortedSet<ITimeValue<IValue<Set<AString>>>> valuesInitial = this.timeVariable.getFutureValues(0L);
Assert.assertEquals(true, valuesInitial.size() > 1); assertEquals(true, valuesInitial.size() > 1);
timeVariable.compact(); this.timeVariable.compact();
SortedSet<ITimeValue<IValue<Set<AString>>>> valuesCompacted = timeVariable.getFutureValues(0L); SortedSet<ITimeValue<IValue<Set<AString>>>> valuesCompacted = this.timeVariable.getFutureValues(0L);
Assert.assertEquals(1, valuesCompacted.size()); assertEquals(1, valuesCompacted.size());
} }

View File

@ -22,10 +22,9 @@ public class ValueTests {
DoubleValue value = new DoubleValue(10.0d); DoubleValue value = new DoubleValue(10.0d);
DoubleValue inverse = value.getInverse(); DoubleValue inverse = value.getInverse();
assertEquals(Double.valueOf(-10.0d), inverse.getValue()); assertEquals(Double.valueOf(-10.0d), inverse.getValue());
assertEquals(Double.valueOf(0), value.add(inverse.getValue()) assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue());
.getValue());
} }
/** /**
* check, that adding the inverse results in the neutral element (=0) * check, that adding the inverse results in the neutral element (=0)
*/ */
@ -34,8 +33,7 @@ public class ValueTests {
IntegerValue value = new IntegerValue(10); IntegerValue value = new IntegerValue(10);
IntegerValue inverse = value.getInverse(); IntegerValue inverse = value.getInverse();
assertEquals(Integer.valueOf(-10), inverse.getValue()); assertEquals(Integer.valueOf(-10), inverse.getValue());
assertEquals(Integer.valueOf(0), value.add(inverse.getValue()) assertEquals(Integer.valueOf(0), value.add(inverse.getValue()).getValue());
.getValue());
} }
/** /**
@ -45,7 +43,7 @@ public class ValueTests {
public void testStringSetInverse() { public void testStringSetInverse() {
Set<AString> aStrings = new HashSet<AString>(); Set<AString> aStrings = new HashSet<AString>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
aStrings.add(new AString("string " + i)); aStrings.add(new AString("string " + i)); //$NON-NLS-1$
} }
IValue<Set<AString>> value = new StringSetValue(aStrings); IValue<Set<AString>> value = new StringSetValue(aStrings);
IValue<Set<AString>> inverse = value.getInverse(); IValue<Set<AString>> inverse = value.getInverse();
@ -61,20 +59,19 @@ public class ValueTests {
Set<AString> aStrings1 = new HashSet<AString>(); Set<AString> aStrings1 = new HashSet<AString>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
aStrings1.add(new AString("string " + i)); aStrings1.add(new AString("string " + i)); //$NON-NLS-1$
} }
IValue<Set<AString>> value1 = new StringSetValue(aStrings1); IValue<Set<AString>> value1 = new StringSetValue(aStrings1);
Set<AString> aStrings2 = new HashSet<AString>(); Set<AString> aStrings2 = new HashSet<AString>();
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
aStrings2.add(new AString("string " + i, true)); aStrings2.add(new AString("string " + i, true)); //$NON-NLS-1$
} }
IValue<Set<AString>> value2 = new StringSetValue(aStrings2); IValue<Set<AString>> value2 = new StringSetValue(aStrings2);
assertEquals(false, value1.matches(value2)); assertEquals(false, value1.matches(value2));
assertEquals(1, value1.add(value2.getValue()).getValue().size()); assertEquals(1, value1.add(value2.getValue()).getValue().size());
assertEquals(10, value1.add(value2.getInverse().getValue()).getValue() assertEquals(10, value1.add(value2.getInverse().getValue()).getValue().size());
.size());
} }
} }

View File

@ -1,8 +1,10 @@
package li.strolch.test.model; package li.strolch.test.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.Assert;
import li.strolch.model.Order; import li.strolch.model.Order;
import li.strolch.model.ParameterBag; import li.strolch.model.ParameterBag;
import li.strolch.model.Resource; import li.strolch.model.Resource;
@ -17,6 +19,7 @@ import li.strolch.model.parameter.StringParameter;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("nls")
public class ModelTest { public class ModelTest {
@Test @Test
@ -38,11 +41,11 @@ public class ModelTest {
public static void validateBag(ParameterBag bag) { public static void validateBag(ParameterBag bag) {
Assert.assertNotNull(bag); assertNotNull(bag);
Assert.assertEquals(ModelTestHelper.BAG_ID, bag.getId()); assertEquals(ModelTestHelper.BAG_ID, bag.getId());
Assert.assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); assertEquals(ModelTestHelper.BAG_NAME, bag.getName());
Assert.assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); assertEquals(ModelTestHelper.BAG_TYPE, bag.getType());
validateParams(bag); validateParams(bag);
} }
@ -50,35 +53,35 @@ public class ModelTest {
public static void validateParams(ParameterBag bag) { public static void validateParams(ParameterBag bag) {
BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID);
Assert.assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam);
Assert.assertEquals(true, boolParam.getValue().booleanValue()); assertEquals(true, boolParam.getValue().booleanValue());
FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID);
Assert.assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam);
Assert.assertEquals(44.3, floatParam.getValue().doubleValue()); assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001);
IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID);
Assert.assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam);
Assert.assertEquals(77, integerParam.getValue().intValue()); assertEquals(77, integerParam.getValue().intValue());
LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID);
Assert.assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam);
Assert.assertEquals(4453234566L, longParam.getValue().longValue()); assertEquals(4453234566L, longParam.getValue().longValue());
StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID);
Assert.assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam);
Assert.assertEquals("Strolch", stringParam.getValue()); assertEquals("Strolch", stringParam.getValue());
DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID);
Assert.assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam);
Assert.assertEquals(1354295525628L, dateParam.getValue().longValue()); assertEquals(1354295525628L, dateParam.getValue().longValue());
StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID);
Assert.assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP);
ArrayList<String> stringList = new ArrayList<String>(); ArrayList<String> stringList = new ArrayList<String>();
stringList.add("Hello"); stringList.add("Hello");
stringList.add("World"); stringList.add("World");
Assert.assertEquals(stringList, stringListP.getValue()); assertEquals(stringList, stringListP.getValue());
} }
} }

View File

@ -40,6 +40,7 @@ import li.strolch.model.parameter.StringParameter;
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
* *
*/ */
@SuppressWarnings("nls")
public class ModelTestHelper { public class ModelTestHelper {
public static final String PARAM_BOOLEAN_ID = "@param1"; public static final String PARAM_BOOLEAN_ID = "@param1";