From 6b12b31605d968175767c3884ac0fcffef5000d0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 18:37:47 +0200 Subject: [PATCH] [Minor] cleaned up compiler warnings and added Tags constants class --- .../strolch/model/AbstractStrolchElement.java | 21 +++-- .../model/GroupedParameterizedElement.java | 16 ++-- src/main/java/li/strolch/model/Locator.java | 21 +++-- src/main/java/li/strolch/model/Order.java | 22 ++--- .../java/li/strolch/model/ParameterBag.java | 3 +- .../strolch/model/ParameterizedElement.java | 21 +++-- src/main/java/li/strolch/model/Resource.java | 6 +- src/main/java/li/strolch/model/State.java | 5 +- .../java/li/strolch/model/StrolchElement.java | 1 - src/main/java/li/strolch/model/Tags.java | 21 +++++ .../model/parameter/AbstractParameter.java | 49 +++++++---- .../model/parameter/BooleanParameter.java | 10 ++- .../model/parameter/DateParameter.java | 9 +- .../model/parameter/FloatParameter.java | 13 ++- .../model/parameter/IntegerParameter.java | 13 ++- .../model/parameter/ListParameter.java | 3 +- .../model/parameter/LongParameter.java | 10 ++- .../li/strolch/model/parameter/Parameter.java | 10 +-- .../model/parameter/StringListParameter.java | 15 ++-- .../model/parameter/StringParameter.java | 16 ++-- .../strolch/model/timedstate/TimedState.java | 10 +-- .../model/timevalue/ITimeVariable.java | 3 +- .../strolch/model/timevalue/impl/AString.java | 25 ++++-- .../model/timevalue/impl/DoubleValue.java | 19 ++-- .../model/timevalue/impl/IntegerValue.java | 22 +++-- .../model/timevalue/impl/StringSetValue.java | 24 ++--- .../model/timevalue/impl/TimeValue.java | 53 ++++++----- .../model/timevalue/impl/TimeVariable.java | 18 ++-- .../model/timevalue/impl/ValueChange.java | 29 +++--- .../model/timedstate/TimeStateTest.java | 88 ++++++++++--------- .../timevalue/FloatTimeVariableTest.java | 53 +++++------ .../timevalue/IntegerTimeVariableTest.java | 52 +++++------ .../timevalue/StringTimeVariableTest.java | 66 +++++++------- .../strolch/model/timevalue/ValueTests.java | 17 ++-- .../java/li/strolch/test/model/ModelTest.java | 41 +++++---- .../strolch/test/model/ModelTestHelper.java | 1 + 36 files changed, 466 insertions(+), 340 deletions(-) create mode 100644 src/main/java/li/strolch/model/Tags.java diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 8a34e27a0..0b5acb25c 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -21,6 +21,8 @@ */ package li.strolch.model; +import java.text.MessageFormat; + import li.strolch.exception.StrolchException; import li.strolch.model.Locator.LocatorBuilder; @@ -75,10 +77,10 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public void setId(String id) { 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()) - throw new StrolchException("The id may never be empty"); + throw new StrolchException("The id may never be empty"); //$NON-NLS-1$ this.id = id; } @@ -113,9 +115,9 @@ public abstract class AbstractStrolchElement implements StrolchElement { } protected void fillElement(Element element) { - element.setAttribute("Id", getId()); - element.setAttribute("Name", getName()); - element.setAttribute("Type", getType()); + element.setAttribute(Tags.ID, getId()); + element.setAttribute(Tags.NAME, getName()); + element.setAttribute(Tags.TYPE, getType()); } /** @@ -124,15 +126,16 @@ public abstract class AbstractStrolchElement implements StrolchElement { * @param element */ protected void fromDom(Element element) { - String id = element.getAttribute("Id"); - String name = element.getAttribute("Name"); + String id = element.getAttribute(Tags.ID); + String name = element.getAttribute(Tags.NAME); if (id != null && name != null) { setId(id); setName(name); } else { - throw new StrolchException("Check the values of the element: " + element.getNodeName() - + " either id or name attribute is null!"); + String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, element.getNodeName()); + throw new StrolchException(msg); } } diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 16c936349..2428e8444 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -77,8 +78,11 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement * the type to set */ public void setType(String type) { - if (StringHelper.isEmpty(type)) - throw new StrolchException("Type must be set on element " + getLocator()); + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } this.type = type; } @@ -120,7 +124,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement this.parameterBagMap = new HashMap(); ParameterBag bag = this.parameterBagMap.get(bagKey); 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); @@ -225,10 +231,10 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement public void fromDom(Element element) { super.fromDom(element); - String type = element.getAttribute("Type"); + String type = element.getAttribute(Tags.TYPE); setType(type); - NodeList bags = element.getElementsByTagName("ParameterBag"); + NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG); for (int i = 0; i < bags.getLength(); i++) { Element bagElement = (Element) bags.item(i); ParameterBag bag = new ParameterBag(bagElement); diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index cff524545..7e89000c2 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -52,7 +53,7 @@ public class Locator { /** * 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 @@ -70,7 +71,7 @@ public class Locator { */ public Locator(List pathElements) throws StrolchException { 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(pathElements)); } @@ -145,11 +146,14 @@ public class Locator { */ private List parsePath(String path) throws StrolchException { 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); - if (elements.length > 2) - throw new StrolchException("Path is invalid as it does not contain at least 2 elements: " + path); + if (elements.length > 2) { + 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); } @@ -166,8 +170,11 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.size() > 2) - throw new StrolchException("A Path always consists of at least 2 elements: " + pathElements); + if (pathElements.size() > 2) { + 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(); diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 91061facd..95d8bc26b 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -21,11 +21,11 @@ */ package li.strolch.model; +import li.strolch.model.Locator.LocatorBuilder; + import org.w3c.dom.Document; 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 * 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; - public static final String PREFIX_ORDER = "OrderPrefix"; - private long date; private State state; @@ -91,8 +89,8 @@ public class Order extends GroupedParameterizedElement { public Order(Element element) { super.fromDom(element); - String date = element.getAttribute("Date"); - String state = element.getAttribute("State"); + String date = element.getAttribute(Tags.DATE); + String state = element.getAttribute(Tags.STATE); // TODO the format should be globally configured if (date == null || date.isEmpty()) { @@ -138,18 +136,15 @@ public class Order extends GroupedParameterizedElement { this.state = state; } - /** - * @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom(Document) - */ @Override public Element toDom(Document doc) { - Element orderElement = doc.createElement("Order"); + Element orderElement = doc.createElement(Tags.ORDER); fillElement(orderElement); // TODO the format should be globally configured - orderElement.setAttribute("Date", Long.toString(this.date)); - orderElement.setAttribute("State", this.state.toString()); + orderElement.setAttribute(Tags.DATE, Long.toString(this.date)); + orderElement.setAttribute(Tags.STATE, this.state.toString()); return orderElement; } @@ -168,7 +163,7 @@ public class Order extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append("Order").append(getId()); + lb.append(Tags.ORDER).append(getId()); } @Override @@ -178,6 +173,7 @@ public class Order extends GroupedParameterizedElement { return lb.build(); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index d29d25d86..8dac2f25b 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -24,7 +24,6 @@ package li.strolch.model; import org.w3c.dom.Document; import org.w3c.dom.Element; - /** * @author Robert von Burg */ @@ -68,7 +67,7 @@ public class ParameterBag extends ParameterizedElement { @Override public Element toDom(Document doc) { - Element element = doc.createElement("ParameterBag"); + Element element = doc.createElement(Tags.PARAMETER_BAG); fillElement(element); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 318585663..313a4d26b 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -87,8 +88,11 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { * the type to set */ public void setType(String type) { - if (StringHelper.isEmpty(type)) - throw new StrolchException("Type must be set on element " + getLocator()); + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } this.type = type; } @@ -193,7 +197,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override public void fillLocator(LocatorBuilder lb) { - lb.append("ParameterizedElement").append(this.id); + lb.append(Tags.PARAMETERIZED_ELEMENT).append(this.id); } @Override @@ -208,14 +212,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { protected void fromDom(Element element) { super.fromDom(element); - String type = element.getAttribute("Type"); + String type = element.getAttribute(Tags.TYPE); setType(type); // add all the parameters - NodeList parameterElements = element.getElementsByTagName("Parameter"); + NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); for (int i = 0; i < parameterElements.getLength(); i++) { Element paramElement = (Element) parameterElements.item(i); - String paramtype = paramElement.getAttribute("Type"); + String paramtype = paramElement.getAttribute(Tags.TYPE); if (paramtype.equals(StringParameter.TYPE)) { StringParameter param = new StringParameter(paramElement); @@ -236,7 +240,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { BooleanParameter param = new BooleanParameter(paramElement); addParameter(param); } 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); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 8588431fa..8cb6b7dbf 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -32,7 +32,6 @@ import li.strolch.model.Locator.LocatorBuilder; public class Resource extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; - public static final String PREFIX_RESOURCE = "ResourcePrefix"; /** * Empty constructor @@ -64,7 +63,7 @@ public class Resource extends GroupedParameterizedElement { @Override public Element toDom(Document doc) { - Element element = doc.createElement("Resource"); + Element element = doc.createElement(Tags.RESOURCE); fillElement(element); return element; @@ -81,7 +80,7 @@ public class Resource extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append("Resource").append(getId()); + lb.append(Tags.RESOURCE).append(getId()); } @Override @@ -91,6 +90,7 @@ public class Resource extends GroupedParameterizedElement { return lb.build(); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/State.java b/src/main/java/li/strolch/model/State.java index 6fc4b0b99..8968b9786 100644 --- a/src/main/java/li/strolch/model/State.java +++ b/src/main/java/li/strolch/model/State.java @@ -26,7 +26,10 @@ package li.strolch.model; */ 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; diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index 916fff125..d30e5c034 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -28,7 +28,6 @@ import org.w3c.dom.Element; /** * @author Robert von Burg - * @param */ public interface StrolchElement extends Serializable, Comparable { diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java new file mode 100644 index 000000000..53c192074 --- /dev/null +++ b/src/main/java/li/strolch/model/Tags.java @@ -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"; + +} diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index ea4d9cdad..e6a4c9505 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -21,14 +21,18 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Document; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; 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; /** @@ -113,17 +117,17 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem @Override public Element toDom(Document doc) { - Element element = doc.createElement("Parameter"); + Element element = doc.createElement(Tags.PARAMETER); fillElement(element); - element.setAttribute("Value", getValueAsString()); + element.setAttribute(Tags.VALUE, getValueAsString()); 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)) - element.setAttribute("Uom", this.uom); + element.setAttribute(Tags.UOM, this.uom); if (this.hidden) - element.setAttribute("Hidden", Boolean.toString(this.hidden)); + element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden)); return element; } @@ -133,16 +137,20 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem super.fromDom(element); - String typeS = element.getAttribute("Type"); + String typeS = element.getAttribute(Tags.TYPE); 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())) { - 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 isHidden = element.getAttribute("Hidden"); - String uom = element.getAttribute("Uom"); + String interpretation = element.getAttribute(Tags.INTERPRETATION); + String isHidden = element.getAttribute(Tags.HIDDEN); + String uom = element.getAttribute(Tags.UOM); setInterpretation(interpretation); setUom(uom); @@ -155,15 +163,16 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) { setHidden(false); } else { - throw new StrolchException("Boolean string must be either " + Boolean.TRUE.toString() + " or " - + Boolean.FALSE.toString()); + String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString()); + throw new StrolchException(msg); } } } @Override protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append("Parameter").append(this.id); + locatorBuilder.append(Tags.PARAMETER).append(this.id); } @Override @@ -184,8 +193,11 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem * if the value is null */ protected void validateValue(T value) throws StrolchException { - if (value == null) - throw new StrolchException(getType() + " Parameter " + getId() + " may not have a null value!"); + if (value == null) { + 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 extends AbstractStrolchElement implem clone.setUom(this.uom); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 97b748a06..4975ad326 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -21,9 +21,12 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; + import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -31,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class BooleanParameter extends AbstractParameter { - public static final String TYPE = "Boolean"; + public static final String TYPE = "Boolean"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Boolean value = Boolean.FALSE; @@ -63,9 +66,10 @@ public class BooleanParameter extends AbstractParameter { public BooleanParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 1986958a8..2478fb517 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -22,10 +22,12 @@ package li.strolch.model.parameter; import java.text.DateFormat; +import java.text.MessageFormat; import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -33,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class DateParameter extends AbstractParameter { - public static final String TYPE = "Date"; + public static final String TYPE = "Date"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Long value; @@ -65,9 +67,10 @@ public class DateParameter extends AbstractParameter { public DateParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 8683a2a19..7fef5a73d 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class FloatParameter extends AbstractParameter { - public static final String TYPE = "Float"; + public static final String TYPE = "Float"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Double value = Double.MAX_VALUE; @@ -65,9 +69,10 @@ public class FloatParameter extends AbstractParameter { public FloatParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 74333fe14..6fa09c79c 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class IntegerParameter extends AbstractParameter { - public static final String TYPE = "Integer"; + public static final String TYPE = "Integer"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Integer value = Integer.MAX_VALUE; @@ -64,9 +68,10 @@ public class IntegerParameter extends AbstractParameter { public IntegerParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index 3cea4844c..f754c7fb8 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -23,13 +23,14 @@ package li.strolch.model.parameter; import java.util.List; - /** * @author Robert von Burg * */ public interface ListParameter extends Parameter> { + public static final String VALUE_SEPARATOR = ";"; //$NON-NLS-1$ + /** * Adds a single value to the {@link List} of values * diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 68059d34c..63c0af082 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -21,9 +21,12 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; + import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class LongParameter extends AbstractParameter { - public static final String TYPE = "Long"; + public static final String TYPE = "Long"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; protected Long value; @@ -64,9 +67,10 @@ public class LongParameter extends AbstractParameter { public LongParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index f6341a812..6b4abd5bc 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -35,24 +35,24 @@ public interface Parameter extends StrolchElement { /** * 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 */ - 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 * 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 * 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 @@ -99,7 +99,7 @@ public interface Parameter extends StrolchElement { /** * Set the UOM of this {@link Parameter} * - * @param hidden + * @param uom */ public void setUom(String uom); diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 77819cd42..673a59c79 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -21,6 +21,7 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -31,6 +32,7 @@ import org.w3c.dom.Element; import li.strolch.exception.StrolchException; import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -38,7 +40,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class StringListParameter extends AbstractParameter> implements ListParameter { - public static final String TYPE = "StringList"; + public static final String TYPE = "StringList"; //$NON-NLS-1$ private static final long serialVersionUID = 1L; protected List value; @@ -71,9 +73,10 @@ public class StringListParameter extends AbstractParameter> impleme public StringListParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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)); @@ -83,14 +86,14 @@ public class StringListParameter extends AbstractParameter> impleme if (value.isEmpty()) return Collections.emptyList(); - String[] valueArr = value.split(";"); + String[] valueArr = value.split(VALUE_SEPARATOR); return Arrays.asList(valueArr); } @Override public String getValueAsString() { if (this.value.isEmpty()) - return ""; + return StringHelper.EMPTY; StringBuilder sb = new StringBuilder(); Iterator iter = this.value.iterator(); @@ -99,7 +102,7 @@ public class StringListParameter extends AbstractParameter> impleme sb.append(iter.next()); if (iter.hasNext()) - sb.append(";"); + sb.append(VALUE_SEPARATOR); } return sb.toString(); diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 7f0de4e79..1ace001a1 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,10 +36,11 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class StringParameter extends AbstractParameter { + public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$ + public static final String TYPE = "String"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; - public static final String TYPE = "String"; - private String value = "-"; + private String value = UNDEFINED_VALUE; /** * Empty constructor @@ -65,9 +70,10 @@ public class StringParameter extends AbstractParameter { public StringParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); 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); diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java index f5e9e5d95..5dd75808e 100644 --- a/src/main/java/li/strolch/model/timedstate/TimedState.java +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -25,7 +25,7 @@ public class TimedState implements ITimedState, Serializabl @Override @SuppressWarnings("unchecked") public ITimeValue getNextMatch(final Long time, final T value) { - Collection> futureValues = timeVariable.getFutureValues(time); + Collection> futureValues = this.timeVariable.getFutureValues(time); for (ITimeValue iTimeValue : futureValues) { if (iTimeValue.getValue().matches(value)) { return iTimeValue; @@ -37,7 +37,7 @@ public class TimedState implements ITimedState, Serializabl @Override @SuppressWarnings("unchecked") public ITimeValue getPreviousMatch(final Long time, final T value) { - Collection> pastValues = timeVariable.getPastValues(time); + Collection> pastValues = this.timeVariable.getPastValues(time); List> asList = new ArrayList>(pastValues); Collections.reverse(asList); for (ITimeValue iTimeValue : asList) { @@ -50,17 +50,17 @@ public class TimedState implements ITimedState, Serializabl @Override public void applyChange(final IValueChange change) { - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); } @Override public ITimeValue getStateAt(final Long time) { - return timeVariable.getValueAt(time); + return this.timeVariable.getValueAt(time); } @Override public ITimeVariable getTimeEvolution() { - return timeVariable; + return this.timeVariable; } } diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index f1bc79261..682a4e773 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -12,8 +12,7 @@ import java.util.SortedSet; * @param * the backing value of the timed value object */ -@SuppressWarnings("rawtypes") -public interface ITimeVariable { +public interface ITimeVariable> { /** * set the value at a point in time to a given time value object diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index 39ae3d69d..ff6d1694c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -26,23 +26,23 @@ public class AString implements Serializable { } public String getString() { - return string; + return this.string; } public boolean isInverse() { - return inverse; + return this.inverse; } public AString getInverse() { - return new AString(string, !inverse); + return new AString(this.string, !this.inverse); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (inverse ? 1231 : 1237); - result = prime * result + ((string == null) ? 0 : string.hashCode()); + result = prime * result + (this.inverse ? 1231 : 1237); + result = prime * result + ((this.string == null) ? 0 : this.string.hashCode()); return result; } @@ -55,19 +55,26 @@ public class AString implements Serializable { if (getClass() != obj.getClass()) return false; AString other = (AString) obj; - if (inverse != other.inverse) + if (this.inverse != other.inverse) return false; - if (string == null) { + if (this.string == null) { if (other.string != null) return false; - } else if (!string.equals(other.string)) + } else if (!this.string.equals(other.string)) return false; return true; } + @SuppressWarnings("nls") @Override 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(); } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java index c8d2f29e5..e6e7b5593 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java @@ -40,18 +40,23 @@ public class DoubleValue implements IValue, Serializable { @Override public DoubleValue add(Double o) { - value += o; + this.value += o; return this; } @Override public Double getValue() { - return value; + return this.value; } + @SuppressWarnings("nls") @Override 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 @@ -66,14 +71,14 @@ public class DoubleValue implements IValue, Serializable { @Override public DoubleValue getCopy(){ - return new DoubleValue(value); + return new DoubleValue(this.value); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -86,10 +91,10 @@ public class DoubleValue implements IValue, Serializable { if (getClass() != obj.getClass()) return false; DoubleValue other = (DoubleValue) obj; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index 61b622758..b6c1842c4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -6,8 +6,7 @@ import li.strolch.model.timevalue.ITimeValue; 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 */ @@ -33,7 +32,7 @@ public class IntegerValue implements IValue, Serializable { @Override public IntegerValue add(Integer o) { - value += o; + this.value += o; return this; } @@ -44,7 +43,7 @@ public class IntegerValue implements IValue, Serializable { @Override public Integer getValue() { - return value; + return this.value; } @Override @@ -52,21 +51,26 @@ public class IntegerValue implements IValue, Serializable { return new IntegerValue(-getValue()); } + @SuppressWarnings("nls") @Override 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 public IntegerValue getCopy() { - return new IntegerValue(value); + return new IntegerValue(this.value); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -79,10 +83,10 @@ public class IntegerValue implements IValue, Serializable { if (getClass() != obj.getClass()) return false; IntegerValue other = (IntegerValue) obj; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index 6f279c7c3..37a9fc150 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -10,9 +10,8 @@ import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** - * {@link IValue} implementation to work with String valued {@link ITimeValue} - * objects. Since a java.util.String object does not define a inverse, a - * algebraic {@link AString} wrapper is used. + * {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object + * does not define a inverse, a algebraic {@link AString} wrapper is used. * * @author Martin Smock */ @@ -34,7 +33,7 @@ public class StringSetValue implements IValue>, Serializable { @Override public Set getValue() { - return aStrings; + return this.aStrings; } @Override @@ -44,7 +43,7 @@ public class StringSetValue implements IValue>, Serializable { for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { AString toAdd = iter1.next(); - for (Iterator iter = aStrings.iterator(); iter.hasNext();) { + for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { AString aString = iter.next(); boolean valueMatch = aString.getString().equals(toAdd.getString()); boolean compensate = (toAdd.isInverse() && !aString.isInverse()) @@ -55,19 +54,19 @@ public class StringSetValue implements IValue>, Serializable { } } } - aStrings.addAll(toBeAdded); + this.aStrings.addAll(toBeAdded); return this; } @Override public boolean matches(IValue> other) { - return this.getValue().equals(other.getValue()); + return getValue().equals(other.getValue()); } @Override public IValue> getInverse() { Set inverseSet = new HashSet(); - for (AString as : aStrings) { + for (AString as : this.aStrings) { inverseSet.add(as.getInverse()); } StringSetValue inverse = new StringSetValue(); @@ -77,12 +76,17 @@ public class StringSetValue implements IValue>, Serializable { @Override public StringSetValue getCopy() { - return new StringSetValue(aStrings); + return new StringSetValue(this.aStrings); } + @SuppressWarnings("nls") @Override public String toString() { - return "StringSetValue [aStrings=" + aStrings + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("StringSetValue [aStrings="); + sb.append(this.aStrings); + sb.append("]"); + return sb.toString(); } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index eca23d69e..cf83dbf1c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -9,62 +9,69 @@ import li.strolch.model.timevalue.IValue; * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class TimeValue implements ITimeValue , Serializable { - +public class TimeValue implements ITimeValue, Serializable { + private static final long serialVersionUID = 1L; - - protected final Long time; - protected T value; - + + protected final Long time; + protected T value; + /** * @param time * @param value */ - public TimeValue(final Long time, final T value){ - this.time = time; - this.value = value; + public TimeValue(final Long time, final T value) { + this.time = time; + this.value = value; } @Override @SuppressWarnings("unchecked") public T getValue() { - return (T) value.getCopy(); + return (T) this.value.getCopy(); } @Override public Long getTime() { - return time; + return this.time; } @Override public ITimeValue setValue(final T value) { this.value = value; - return this; + return this; } @SuppressWarnings("unchecked") @Override public ITimeValue add(final T change) { - this.value.add(change.getValue()); - return this; + this.value.add(change.getValue()); + return this; } - + @Override public int compareTo(final ITimeValue arg0) { return this.getTime().compareTo(arg0.getTime()); } + @SuppressWarnings("nls") @Override 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 public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((time == null) ? 0 : time.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.time == null) ? 0 : this.time.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -78,17 +85,17 @@ public class TimeValue implements ITimeValue , Serializable return false; @SuppressWarnings("unchecked") TimeValue other = (TimeValue) obj; - if (time == null) { + if (this.time == null) { if (other.time != null) return false; - } else if (!time.equals(other.time)) + } else if (!this.time.equals(other.time)) return false; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } - + } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 34af158a8..5640e06c4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -25,7 +25,7 @@ public class TimeVariable implements ITimeVariable, Seriali @Override public ITimeValue getValueAt(final Long time) { ITimeValue tmp = null; - for (ITimeValue value : container) { + for (ITimeValue value : this.container) { if (value.getTime() <= time) { tmp = value; } else { @@ -41,25 +41,25 @@ public class TimeVariable implements ITimeVariable, Seriali if (current != null && current.getTime().equals(time)) { current.setValue(targetValue); } else { - container.add(new TimeValue(time, targetValue)); + this.container.add(new TimeValue(time, targetValue)); } } @Override public SortedSet> getFutureValues(final Long time) { TimeValue picker = new TimeValue(time, null); - return new TreeSet>(container.tailSet(picker)); + return new TreeSet>(this.container.tailSet(picker)); } @Override public Collection> getPastValues(final Long time) { TimeValue picker = new TimeValue(time, null); - return new TreeSet>(container.headSet(picker)); + return new TreeSet>(this.container.headSet(picker)); } @Override public SortedSet> getValues() { - return new TreeSet>(container); + return new TreeSet>(this.container); } @Override @@ -73,11 +73,11 @@ public class TimeVariable implements ITimeVariable, Seriali ITimeValue initialValue = getValueAt(change.getTime()); if (initialValue == null) { ITimeValue newValue = new TimeValue(change.getTime(), change.getValue()); - container.add(newValue); + this.container.add(newValue); } else if (initialValue.getTime().longValue() < change.getTime().longValue()) { ITimeValue newValue = new TimeValue(change.getTime(), initialValue.getValue()); newValue.add(change.getValue()); - container.add(newValue); + this.container.add(newValue); } compact(); } @@ -86,10 +86,10 @@ public class TimeVariable implements ITimeVariable, Seriali @Override public void compact() { - if (container.size() < 2) + if (this.container.size() < 2) return; - Iterator> iterator = container.iterator(); + Iterator> iterator = this.container.iterator(); ITimeValue predecessor = iterator.next(); while (iterator.hasNext()) { diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java index 80ae72579..e2276b77f 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -12,7 +12,7 @@ import li.strolch.model.timevalue.IValueChange; public class ValueChange implements IValueChange, Serializable { private static final long serialVersionUID = 1L; - + protected final Long time; protected final T value; @@ -27,19 +27,19 @@ public class ValueChange implements IValueChange, Serializa @Override public Long getTime() { - return time; + return this.time; } @Override @SuppressWarnings("unchecked") public T getValue() { - return (T) value.getCopy(); + return (T) this.value.getCopy(); } @Override @SuppressWarnings("unchecked") public IValueChange getInverse() { - return new ValueChange(time, value.getInverse()); + return new ValueChange(this.time, this.value.getInverse()); } @Override @@ -51,15 +51,15 @@ public class ValueChange implements IValueChange, Serializa if (getClass() != obj.getClass()) return false; ValueChange other = (ValueChange) obj; - if (time == null) { + if (this.time == null) { if (other.time != null) return false; - } else if (!time.equals(other.time)) + } else if (!this.time.equals(other.time)) return false; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } @@ -68,14 +68,21 @@ public class ValueChange implements IValueChange, Serializa public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((time == null) ? 0 : time.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.time == null) ? 0 : this.time.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } + @SuppressWarnings("nls") @Override 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(); } } diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index 9ef800718..8c685ca50 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,6 +1,8 @@ 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.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; @@ -25,69 +27,69 @@ public class TimeStateTest { @Before public void before() { - final IValueChange change1 = new ValueChange(t10, expectedValue1); - state.applyChange(change1); + final IValueChange change1 = new ValueChange(this.t10, this.expectedValue1); + this.state.applyChange(change1); - final ITimeValue stateAt9 = state.getStateAt(9L); - Assert.assertNull(stateAt9); + final ITimeValue stateAt9 = this.state.getStateAt(9L); + assertNull(stateAt9); - final ITimeValue stateAt11 = state.getStateAt(11L); - Assert.assertNotNull(stateAt11); - Assert.assertEquals(true, stateAt11.getValue().matches(expectedValue1)); + final ITimeValue stateAt11 = this.state.getStateAt(11L); + assertNotNull(stateAt11); + assertEquals(true, stateAt11.getValue().matches(this.expectedValue1)); - final IValueChange change2 = new ValueChange(t30, expectedValue1); - state.applyChange(change2); + final IValueChange change2 = new ValueChange(this.t30, this.expectedValue1); + this.state.applyChange(change2); - final ITimeValue stateAt31 = state.getStateAt(31L); - Assert.assertNotNull(stateAt31); - Assert.assertEquals(true, stateAt31.getValue().matches(expectedValue2)); + final ITimeValue stateAt31 = this.state.getStateAt(31L); + assertNotNull(stateAt31); + assertEquals(true, stateAt31.getValue().matches(this.expectedValue2)); } @Test public void testGetNextMatch() { - ITimeValue nextMatch = state.getNextMatch(t0, expectedValue1); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t10, nextMatch.getTime()); + ITimeValue nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1); + assertNotNull(nextMatch); + assertEquals(this.t10, nextMatch.getTime()); - nextMatch = state.getNextMatch(t20, expectedValue1); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t20, this.expectedValue1); + assertNull(nextMatch); - nextMatch = state.getNextMatch(t20, expectedValue2); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t30, nextMatch.getTime()); + nextMatch = this.state.getNextMatch(this.t20, this.expectedValue2); + assertNotNull(nextMatch); + assertEquals(this.t30, nextMatch.getTime()); - nextMatch = state.getNextMatch(t30, expectedValue2); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t30, nextMatch.getTime()); + nextMatch = this.state.getNextMatch(this.t30, this.expectedValue2); + assertNotNull(nextMatch); + assertEquals(this.t30, nextMatch.getTime()); - nextMatch = state.getNextMatch(t100, expectedValue1); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t100, this.expectedValue1); + assertNull(nextMatch); - nextMatch = state.getNextMatch(t100, expectedValue2); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t100, this.expectedValue2); + assertNull(nextMatch); } @Test public void testGetPreviousMatch() { - ITimeValue previousMatch = state.getPreviousMatch(t100, expectedValue2); - Assert.assertNotNull(previousMatch); - Assert.assertEquals(t30, previousMatch.getTime()); + ITimeValue previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2); + assertNotNull(previousMatch); + assertEquals(this.t30, previousMatch.getTime()); - previousMatch = state.getPreviousMatch(t30, expectedValue2); - Assert.assertNull(previousMatch); - - previousMatch = state.getPreviousMatch(t20, expectedValue2); - Assert.assertNull(previousMatch); - - previousMatch = state.getPreviousMatch(t20, expectedValue1); - Assert.assertNotNull(previousMatch); - Assert.assertEquals(t10, previousMatch.getTime()); - - previousMatch = state.getPreviousMatch(t10, expectedValue1); - Assert.assertNull(previousMatch); + previousMatch = this.state.getPreviousMatch(this.t30, this.expectedValue2); + assertNull(previousMatch); + + previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue2); + assertNull(previousMatch); + + previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue1); + assertNotNull(previousMatch); + assertEquals(this.t10, previousMatch.getTime()); + + previousMatch = this.state.getPreviousMatch(this.t10, this.expectedValue1); + assertNull(previousMatch); } diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index b3bb6d2df..2a0cb99df 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -1,9 +1,12 @@ 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.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; @@ -24,16 +27,16 @@ public class FloatTimeVariableTest { */ @Before public void init() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); 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 public void testGetValueAt() { - ITimeValue valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(PICK.doubleValue(), valueAt.getValue().getValue()); + ITimeValue valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001); } /** @@ -41,12 +44,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetFutureValues() { - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; Double expectedValue = PICK.doubleValue(); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -58,12 +61,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetPastValues() { - Collection> pastValues = timeVariable.getPastValues(MAX); + Collection> pastValues = this.timeVariable.getPastValues(MAX); Long expectedTime = 0L; Double expectedValue = expectedTime.doubleValue(); for (ITimeValue value : pastValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -78,16 +81,16 @@ public class FloatTimeVariableTest { DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); IValueChange change = new ValueChange(PICK, doubleValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; IValue expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue()); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(expectedValue.matches(value.getValue())); + assertEquals(expectedTime, value.getTime()); + assertTrue(expectedValue.matches(value.getValue())); expectedTime += STEP; expectedValue = expectedValue.add(STEP.doubleValue()); } @@ -99,18 +102,18 @@ public class FloatTimeVariableTest { @Test public void testApply2Change() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); IValueChange change = new ValueChange(PICK, doubleValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - ITimeValue actual = timeVariable.getValueAt(PICK); - Assert.assertNotNull(actual); + ITimeValue actual = this.timeVariable.getValueAt(PICK); + assertNotNull(actual); IValue 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 public void testCompact() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (Long i = 0L; i < MAX; i += STEP) { - timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); + this.timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); } // call - timeVariable.compact(); + this.timeVariable.compact(); // check - SortedSet> futureValues = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, futureValues.size()); + SortedSet> futureValues = this.timeVariable.getFutureValues(0L); + assertEquals(1, futureValues.size()); } } diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index 601c8fc77..cd3156221 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -1,11 +1,13 @@ package li.strolch.model.timevalue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; @@ -32,19 +34,19 @@ public class IntegerTimeVariableTest { */ @Before public void init() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (int i = 0; i < MAX; i += STEP) { IntegerValue expectedValue = new IntegerValue(i); Long time = Long.valueOf(i); - expectedValues.put(time, expectedValue); - timeVariable.setValueAt(time, expectedValue); + this.expectedValues.put(time, expectedValue); + this.timeVariable.setValueAt(time, expectedValue); } } @Test public void testGetValueAt() { - ITimeValue valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(expectedValues.get(PICK), valueAt.getValue()); + ITimeValue valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(this.expectedValues.get(PICK), valueAt.getValue()); } /** @@ -52,29 +54,28 @@ public class IntegerTimeVariableTest { */ @Test public void testGetFutureValues() { - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; Integer expectedValue = PICK.intValue(); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.intValue(); } } /** - * test, that the past values time fields start with 0 and are strictly - * smaller than PICK + * test, that the past values time fields start with 0 and are strictly smaller than PICK */ @Test public void testGetPastValues() { - Collection> pastValues = timeVariable.getPastValues(MAX); + Collection> pastValues = this.timeVariable.getPastValues(MAX); Long expectedTime = 0L; Integer expectedValue = expectedTime.intValue(); for (ITimeValue value : pastValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.intValue(); } @@ -89,40 +90,39 @@ public class IntegerTimeVariableTest { IntegerValue integerValue = new IntegerValue(STEP.intValue()); IValueChange change = new ValueChange(PICK, integerValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; IValue expectedValue = new IntegerValue(PICK.intValue() + change.getValue().getValue()); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(expectedValue.matches(value.getValue())); + assertEquals(expectedTime, value.getTime()); + assertTrue(expectedValue.matches(value.getValue())); expectedTime += STEP; expectedValue = expectedValue.add(STEP.intValue()); } } /** - * test that successors matching the values of their predecessors are - * removed + * test that successors matching the values of their predecessors are removed */ @Test public void testCompact() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (Long i = 0L; i < MAX; i += STEP) { - timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); + this.timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); } // call - timeVariable.compact(); + this.timeVariable.compact(); // check - SortedSet> futureValues = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, futureValues.size()); + SortedSet> futureValues = this.timeVariable.getFutureValues(0L); + assertEquals(1, futureValues.size()); ITimeValue next = futureValues.iterator().next(); - Assert.assertEquals(Long.valueOf(0), next.getTime()); + assertEquals(Long.valueOf(0), next.getTime()); } } diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index 10fa4d92b..6efefa42b 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -1,5 +1,8 @@ package li.strolch.model.timevalue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -7,7 +10,6 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.TimeVariable; @@ -28,41 +30,41 @@ public class StringTimeVariableTest { @Before public void init() { - timeVariable = new TimeVariable>>(); + this.timeVariable = new TimeVariable>>(); for (Long i = 0L; i < MAX; i += STEP) { Set testSet = new HashSet(); StringSetValue testValue = new StringSetValue(testSet); - testSets.put(i, testValue); - testSet.add(new AString("string " + i)); - timeVariable.setValueAt(i, new StringSetValue(testSet)); + this.testSets.put(i, testValue); + testSet.add(new AString("string " + i)); //$NON-NLS-1$ + this.timeVariable.setValueAt(i, new StringSetValue(testSet)); } } @Test public void testGetValueAt() { - ITimeValue>> valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(true, valueAt.getValue().matches(testSets.get(PICK))); + ITimeValue>> valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(true, valueAt.getValue().matches(this.testSets.get(PICK))); } @Test public void testGetFutureValues() { - Collection>>> futureValues = timeVariable.getFutureValues(PICK); + Collection>>> futureValues = this.timeVariable.getFutureValues(PICK); for (ITimeValue>> iTimeValue : futureValues) { Long time = iTimeValue.getTime(); - Assert.assertEquals(true, time >= PICK); - Assert.assertNotNull(iTimeValue.getValue()); - Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + assertEquals(true, time >= PICK); + assertNotNull(iTimeValue.getValue()); + assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time))); } } @Test public void testGetPastValues() { - Collection>>> pastValues = timeVariable.getPastValues(PICK); + Collection>>> pastValues = this.timeVariable.getPastValues(PICK); for (ITimeValue>> iTimeValue : pastValues) { Long time = iTimeValue.getTime(); - Assert.assertEquals(true, time < PICK); - Assert.assertNotNull(iTimeValue.getValue()); - Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + assertEquals(true, time < PICK); + assertNotNull(iTimeValue.getValue()); + assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time))); } } @@ -70,45 +72,45 @@ public class StringTimeVariableTest { public void testApplyChange() { Set testSet = new HashSet(); - testSet.add(new AString("Martin")); + testSet.add(new AString("Martin")); //$NON-NLS-1$ StringSetValue testValue = new StringSetValue(testSet); - timeVariable = new TimeVariable>>(); - timeVariable.setValueAt(PICK, testValue); + this.timeVariable = new TimeVariable>>(); + this.timeVariable.setValueAt(PICK, testValue); IValue> inverseTestValue = testValue.getInverse(); IValueChange>> change = new ValueChange>>(PICK, inverseTestValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); // check the future values - Collection>>> futureValues = timeVariable.getFutureValues(0L); + Collection>>> futureValues = this.timeVariable.getFutureValues(0L); for (ITimeValue>> 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 public void testCompact() { - timeVariable = new TimeVariable>>(); + this.timeVariable = new TimeVariable>>(); for (Long i = 0L; i < MAX; i += STEP) { Set testSet = new HashSet(); StringSetValue testValue = new StringSetValue(testSet); - testSets.put(i, testValue); - testSet.add(new AString("same string")); - timeVariable.setValueAt(i, new StringSetValue(testSet)); + this.testSets.put(i, testValue); + testSet.add(new AString("same string")); //$NON-NLS-1$ + this.timeVariable.setValueAt(i, new StringSetValue(testSet)); } - SortedSet>>> valuesInitial = timeVariable.getFutureValues(0L); - Assert.assertEquals(true, valuesInitial.size() > 1); + SortedSet>>> valuesInitial = this.timeVariable.getFutureValues(0L); + assertEquals(true, valuesInitial.size() > 1); - timeVariable.compact(); + this.timeVariable.compact(); - SortedSet>>> valuesCompacted = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, valuesCompacted.size()); + SortedSet>>> valuesCompacted = this.timeVariable.getFutureValues(0L); + assertEquals(1, valuesCompacted.size()); } diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index f88a0512b..45fe25fec 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -22,10 +22,9 @@ public class ValueTests { DoubleValue value = new DoubleValue(10.0d); DoubleValue inverse = value.getInverse(); assertEquals(Double.valueOf(-10.0d), inverse.getValue()); - assertEquals(Double.valueOf(0), value.add(inverse.getValue()) - .getValue()); + assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue()); } - + /** * check, that adding the inverse results in the neutral element (=0) */ @@ -34,8 +33,7 @@ public class ValueTests { IntegerValue value = new IntegerValue(10); IntegerValue inverse = value.getInverse(); assertEquals(Integer.valueOf(-10), inverse.getValue()); - assertEquals(Integer.valueOf(0), value.add(inverse.getValue()) - .getValue()); + assertEquals(Integer.valueOf(0), value.add(inverse.getValue()).getValue()); } /** @@ -45,7 +43,7 @@ public class ValueTests { public void testStringSetInverse() { Set aStrings = new HashSet(); for (int i = 0; i < 10; i++) { - aStrings.add(new AString("string " + i)); + aStrings.add(new AString("string " + i)); //$NON-NLS-1$ } IValue> value = new StringSetValue(aStrings); IValue> inverse = value.getInverse(); @@ -61,20 +59,19 @@ public class ValueTests { Set aStrings1 = new HashSet(); for (int i = 0; i < 10; i++) { - aStrings1.add(new AString("string " + i)); + aStrings1.add(new AString("string " + i)); //$NON-NLS-1$ } IValue> value1 = new StringSetValue(aStrings1); Set aStrings2 = new HashSet(); 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> value2 = new StringSetValue(aStrings2); assertEquals(false, value1.matches(value2)); assertEquals(1, value1.add(value2.getValue()).getValue().size()); - assertEquals(10, value1.add(value2.getInverse().getValue()).getValue() - .size()); + assertEquals(10, value1.add(value2.getInverse().getValue()).getValue().size()); } } diff --git a/src/test/java/li/strolch/test/model/ModelTest.java b/src/test/java/li/strolch/test/model/ModelTest.java index d170c7d98..195957e40 100644 --- a/src/test/java/li/strolch/test/model/ModelTest.java +++ b/src/test/java/li/strolch/test/model/ModelTest.java @@ -1,8 +1,10 @@ package li.strolch.test.model; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.ArrayList; -import junit.framework.Assert; import li.strolch.model.Order; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; @@ -17,6 +19,7 @@ import li.strolch.model.parameter.StringParameter; import org.junit.Test; +@SuppressWarnings("nls") public class ModelTest { @Test @@ -38,11 +41,11 @@ public class ModelTest { public static void validateBag(ParameterBag bag) { - Assert.assertNotNull(bag); + assertNotNull(bag); - Assert.assertEquals(ModelTestHelper.BAG_ID, bag.getId()); - Assert.assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); - Assert.assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); + assertEquals(ModelTestHelper.BAG_ID, bag.getId()); + assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); + assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); validateParams(bag); } @@ -50,35 +53,35 @@ public class ModelTest { public static void validateParams(ParameterBag bag) { BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); - Assert.assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); - Assert.assertEquals(true, boolParam.getValue().booleanValue()); + assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); - Assert.assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); - Assert.assertEquals(44.3, floatParam.getValue().doubleValue()); + assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); - Assert.assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); - Assert.assertEquals(77, integerParam.getValue().intValue()); + assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); - Assert.assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); - Assert.assertEquals(4453234566L, longParam.getValue().longValue()); + assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); - Assert.assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); - Assert.assertEquals("Strolch", stringParam.getValue()); + assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); - Assert.assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); - Assert.assertEquals(1354295525628L, dateParam.getValue().longValue()); + assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().longValue()); 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 stringList = new ArrayList(); stringList.add("Hello"); stringList.add("World"); - Assert.assertEquals(stringList, stringListP.getValue()); + assertEquals(stringList, stringListP.getValue()); } } diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/test/model/ModelTestHelper.java index 20dbb24e2..33d023e7d 100644 --- a/src/test/java/li/strolch/test/model/ModelTestHelper.java +++ b/src/test/java/li/strolch/test/model/ModelTestHelper.java @@ -40,6 +40,7 @@ import li.strolch.model.parameter.StringParameter; * @author Robert von Burg * */ +@SuppressWarnings("nls") public class ModelTestHelper { public static final String PARAM_BOOLEAN_ID = "@param1";