Merge branch 'dev'
diff --git a/build.gradle b/build.gradle
index 494531b..d06161b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@
description = 'MDM API - Base Model'
group = 'org.eclipse.mdm'
-version = '5.0.0M3'
+version = '5.0.0M4-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
diff --git a/src/main/java/org/eclipse/mdm/api/base/BaseEntityManager.java b/src/main/java/org/eclipse/mdm/api/base/BaseEntityManager.java
index ab88b56..268e387 100644
--- a/src/main/java/org/eclipse/mdm/api/base/BaseEntityManager.java
+++ b/src/main/java/org/eclipse/mdm/api/base/BaseEntityManager.java
@@ -30,8 +30,6 @@
* Provides business layer CRUD operations and services (CREATE, READ, UPDATE,
* INSERT).
*
- * @param <S>
- * Concrete type of the provided entity factory.
* @since 1.0.0
* @author Viktor Stoehr, Gigatronik Ingolstadt GmbH
* @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
diff --git a/src/main/java/org/eclipse/mdm/api/base/adapter/Attribute.java b/src/main/java/org/eclipse/mdm/api/base/adapter/Attribute.java
index a9539b9..6c98f43 100644
--- a/src/main/java/org/eclipse/mdm/api/base/adapter/Attribute.java
+++ b/src/main/java/org/eclipse/mdm/api/base/adapter/Attribute.java
@@ -12,6 +12,9 @@
import org.eclipse.mdm.api.base.model.Value;
import org.eclipse.mdm.api.base.model.ValueType;
+import javax.xml.ws.Service;
+import java.lang.reflect.Field;
+
/**
* Represents a modeled attribute.
*
@@ -118,12 +121,27 @@
* @return Created {@code Value} is returned.
*/
default Value createValueSeq(String unit, Object input) {
- ValueType<?> valueType = getValueType().toSequenceType();
- if (valueType.isEnumerationType()) {
- return valueType.create(getName(), unit, true, input, getEnumObj().getName());
- } else {
- return valueType.create(getName(), unit, true, input);
+ if(getValueType().isEnumerationType()) {
+ return createEnumerationSequence(unit, input);
}
+ return createValueSequence(unit, input);
+ }
+
+ default Value createValueSequence(String unit, Object input) {
+ ValueType valueType = getValueType();
+ try {
+ Field field = valueType.getClass().getField(valueType.name() + "_SEQUENCE");
+ ValueType<?> sequenceValueType = (ValueType<?>) field.get(valueType);
+ return sequenceValueType.create(getName(), unit, true, input);
+
+ } catch (NoSuchFieldException | ClassCastException | IllegalAccessException e) {
+ throw new RuntimeException("Can't figure out sequence type for " + valueType.name());
+ }
+ }
+
+ default Value createEnumerationSequence(String unit, Object input) {
+ ValueType valueType = getValueType().toSequenceType();
+ return valueType.create(getName(), unit, true, input, getEnumObj().getName());
}
/**
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/AxisType.java b/src/main/java/org/eclipse/mdm/api/base/model/AxisType.java
index 7df7446..9a9ebef 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/AxisType.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/AxisType.java
@@ -21,17 +21,25 @@
/**
* A {@link Channel} of this type may be displayed as the x-axis.
*/
- public static final AxisType X_AXIS = new AxisType(0);
+ public static final AxisType X_AXIS = new AxisType("X_AXIS", 0);
/**
* A {@link Channel} of this type may be displayed as the y-axis.
*/
- public static final AxisType Y_AXIS = new AxisType(1);
+ public static final AxisType Y_AXIS = new AxisType("Y_AXIS", 1);
/**
* A {@link Channel} of this type may be displayed as the x- or y-axis.
*/
- public static final AxisType XY_AXIS = new AxisType(2);
+ public static final AxisType XY_AXIS = new AxisType("XY_AXIS", 2);
+
+ private AxisType(String name, int ordinal) {
+ super(name, ordinal);
+ }
+
+ // ======================================================================
+ // Public methods
+ // ======================================================================
/**
* Returns true if this axis type is {@link #X_AXIS}.
@@ -63,11 +71,4 @@
return XY_AXIS == this;
}
- /**
- * Constructor, makes sure that the order matches the order of the static
- * fields
- */
- AxisType(int ord) {
- super(ord);
- }
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/EnumerationValue.java b/src/main/java/org/eclipse/mdm/api/base/model/EnumerationValue.java
index dc5e799..f9228ea 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/EnumerationValue.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/EnumerationValue.java
@@ -8,6 +8,8 @@
package org.eclipse.mdm.api.base.model;
+import java.util.Objects;
+
/**
* This class emulates the behaviour of a java enum. The reason for its
* existence is that classic enums can't be extended by new values. This class
@@ -32,17 +34,15 @@
/**
* explicitly set the name of this element.
- *
+ *
* @param name
*/
protected void setName(String name) {
- this.name = name;
+ this.name = Objects.requireNonNull(name);
}
/**
* explicitly set the ordinal of this element.
- *
- * @param name
*/
protected void setOrdinal(int ordinal) {
this.ordinal = ordinal;
@@ -68,25 +68,12 @@
}
/**
- *
- * This Constructor is protected to avoid accidental misuse.
- *
- * be sure to initialize the enumeration fully, by either adding it as a
- * static field in an extending class, or setting name and ordinal by hand.
- * You'll also have to add the resulting object to a DynamiEnumeration for
- * it to be completely usable.
- */
- protected EnumerationValue() {
- this(null, null);
- }
-
- /**
* This Constructor is protected to avoid accidental misuse.
*
* be sure to initialize the enumeration fully, by either adding it as a
* static field in an extending class, or setting the ordinal by hand.
- * You'll also have to add the resulting object to a Enumeration for it to
- * be completely usable.
+ * You'll also have to add the resulting object to a DynamicEnumeration for
+ * it to be completely usable.
*
* @param name
*/
@@ -103,26 +90,12 @@
* @param name
*/
protected EnumerationValue(String name, Integer ordinal) {
- this.name = name;
+ this.name = Objects.requireNonNull(name, "Name of an EnumerationValue can never be null!");
this.ordinal = ordinal;
this.owner = null;
}
/**
- * This Constructor is protected to avoid accidental misuse.
- *
- * be sure to initialize the enumeration fully, by either adding it as a
- * static field in an extending class, or setting the name by hand and
- * adding the resulting object to a Enumeration for it to be completely
- * usable.
- *
- * @param name
- */
- protected EnumerationValue(int ordinal) {
- this(null, ordinal);
- }
-
- /**
* @return the name of this enumeration value
*/
public String name() {
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/Interpolation.java b/src/main/java/org/eclipse/mdm/api/base/model/Interpolation.java
index 7ea14fb..46c99da 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/Interpolation.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/Interpolation.java
@@ -20,17 +20,21 @@
/**
* No interpolation is used.
*/
- public static final Interpolation NONE = new Interpolation(0);
+ public static final Interpolation NONE = new Interpolation("NONE", 0);
/**
* Interpolation is linear.
*/
- public static final Interpolation LINEAR = new Interpolation(1);
+ public static final Interpolation LINEAR = new Interpolation("LINEAR", 1);
/**
* Interpolation is application specific.
*/
- public static final Interpolation SPECIFIC = new Interpolation(2);
+ public static final Interpolation SPECIFIC = new Interpolation("SPECIFIC", 2);
+
+ private Interpolation(String name, int ordinal) {
+ super(name, ordinal);
+ }
/**
* Returns true if this interpolation is {@link #NONE}.
@@ -62,11 +66,4 @@
return SPECIFIC == this;
}
- /**
- * Constructor, sets the order
- */
- Interpolation(int ord) {
- super(ord);
- }
-
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/ScalarType.java b/src/main/java/org/eclipse/mdm/api/base/model/ScalarType.java
index ac0fe95..6ffa8f4 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/ScalarType.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/ScalarType.java
@@ -24,126 +24,118 @@
public final class ScalarType extends EnumerationValue {
- // ======================================================================
- // Enumerations
- // ======================================================================
-
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code String} values.
*/
- public static final ScalarType STRING = new ScalarType(0, ValueType.STRING_SEQUENCE, String.class);
+ public static final ScalarType STRING = new ScalarType(0, "STRING", ValueType.STRING_SEQUENCE, String.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code LocalDateTime} values.
*/
- public static final ScalarType DATE = new ScalarType(1, ValueType.DATE_SEQUENCE, LocalDateTime.class);
+ public static final ScalarType DATE = new ScalarType(1, "DATE", ValueType.DATE_SEQUENCE, LocalDateTime.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code boolean} values.
*/
- public static final ScalarType BOOLEAN = new ScalarType(2, ValueType.BOOLEAN_SEQUENCE, boolean.class);
+ public static final ScalarType BOOLEAN = new ScalarType(2, "BOOLEAN", ValueType.BOOLEAN_SEQUENCE, boolean.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code byte} values.
*/
- public static final ScalarType BYTE = new ScalarType(3, ValueType.BYTE_SEQUENCE, byte.class);
+ public static final ScalarType BYTE = new ScalarType(3, "BYTE", ValueType.BYTE_SEQUENCE, byte.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code short} values.
*/
- public static final ScalarType SHORT = new ScalarType(4, ValueType.SHORT_SEQUENCE, short.class);
+ public static final ScalarType SHORT = new ScalarType(4, "SHORT", ValueType.SHORT_SEQUENCE, short.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code int} values.
*/
- public static final ScalarType INTEGER = new ScalarType(5, ValueType.INTEGER_SEQUENCE, int.class);
+ public static final ScalarType INTEGER = new ScalarType(5, "INTEGER", ValueType.INTEGER_SEQUENCE, int.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code long} values.
*/
- public static final ScalarType LONG = new ScalarType(6, ValueType.LONG_SEQUENCE, long.class);
+ public static final ScalarType LONG = new ScalarType(6, "LONG", ValueType.LONG_SEQUENCE, long.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code float} values.
*/
- public static final ScalarType FLOAT = new ScalarType(7, ValueType.FLOAT_SEQUENCE, float.class);
+ public static final ScalarType FLOAT = new ScalarType(7, "FLOAT", ValueType.FLOAT_SEQUENCE, float.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code double} values.
*/
- public static final ScalarType DOUBLE = new ScalarType(8, ValueType.DOUBLE_SEQUENCE, double.class);
+ public static final ScalarType DOUBLE = new ScalarType(8, "DOUBLE", ValueType.DOUBLE_SEQUENCE, double.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code byte[]} values.
*/
- public static final ScalarType BYTE_STREAM = new ScalarType(9, ValueType.BYTE_STREAM_SEQUENCE, byte[].class);
+ public static final ScalarType BYTE_STREAM = new ScalarType(9, "BYTE_STREAM", ValueType.BYTE_STREAM_SEQUENCE, byte[].class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code FloatComplex} values.
*/
- public static final ScalarType FLOAT_COMPLEX = new ScalarType(10, ValueType.FLOAT_COMPLEX_SEQUENCE,
+ public static final ScalarType FLOAT_COMPLEX = new ScalarType(10, "FLOAT_COMPLEX", ValueType.FLOAT_COMPLEX_SEQUENCE,
FloatComplex.class);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code DoubleComplex} values.
*/
- public static final ScalarType DOUBLE_COMPLEX = new ScalarType(11, ValueType.DOUBLE_COMPLEX_SEQUENCE,
+ public static final ScalarType DOUBLE_COMPLEX = new ScalarType(11, "DOUBLE_COMPLEX", ValueType.DOUBLE_COMPLEX_SEQUENCE,
DoubleComplex.class);
/**
* {@link MeasuredValues} are not allowed to be of this type. This constant
* may be used in other contexts.
*/
- public static final ScalarType ENUMERATION = new ScalarType(12, ValueType.ENUMERATION_SEQUENCE);
+ public static final ScalarType ENUMERATION = new ScalarType(12, "ENUMERATION", ValueType.ENUMERATION_SEQUENCE);
/**
* A {@link MeasuredValues} with this type contains an array sequence of
* {@code FileLink} values.
*/
- public static final ScalarType FILE_LINK = new ScalarType(13, ValueType.FILE_LINK_SEQUENCE, FileLink.class);
+ public static final ScalarType FILE_LINK = new ScalarType(13, "FILE_LINK", ValueType.FILE_LINK_SEQUENCE, FileLink.class);
/**
* TODO ...
*/
- public static final ScalarType BLOB = new ScalarType(14, ValueType.BLOB, Object.class);
+ public static final ScalarType BLOB = new ScalarType(14, "BLOB", ValueType.BLOB, Object.class);
/**
* {@link MeasuredValues} are not allowed to be of this type. This constant
* may be used in other contexts.
*/
- public static final ScalarType UNKNOWN = new ScalarType(15, ValueType.UNKNOWN);
-
- // ======================================================================
- // Instance variables
- // ======================================================================
+ public static final ScalarType UNKNOWN = new ScalarType(15, "UNKNOWN", ValueType.UNKNOWN);
private final ValueType valueType;
private final Class<?> arrayType;
- // ======================================================================
- // Constructors
- // ======================================================================
-
/**
* Constructor.
- *
+ *
+ * @param ord
+ * ordinal number of the enum value
+ * @param name
+ * name of the enum value
* @param valueType
* The associated {@link ValueType}.
*/
- private ScalarType(int ord, ValueType valueType) {
- super(ord);
+ private ScalarType(int ord, String name, ValueType valueType) {
+ super(name, ord);
this.valueType = valueType;
arrayType = null;
}
@@ -151,22 +143,22 @@
/**
* Constructor.
*
+ * @param ord
+ * ordinal number of the enum value
+ * @param name
+ * name of the enum value
* @param valueType
* The associated {@link ValueType}.
* @param componentType
* The component type of the array held by instances of
* {@link MeasuredValues}.
*/
- private ScalarType(int ord, ValueType valueType, Class<?> componentType) {
- super(ord);
+ private ScalarType(int ord, String name, ValueType valueType, Class<?> componentType) {
+ super(name, ord);
this.valueType = valueType;
arrayType = Array.newInstance(componentType, 0).getClass();
}
- // ======================================================================
- // Public methods
- // ======================================================================
-
/**
* Creates a new {@link MeasuredValues} initialized with given name, unit
* and values including the related validity flags.
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/SequenceRepresentation.java b/src/main/java/org/eclipse/mdm/api/base/model/SequenceRepresentation.java
index 48579a8..72e972b 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/SequenceRepresentation.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/SequenceRepresentation.java
@@ -26,14 +26,14 @@
* Measured values are stored as is and values are therefore immediately
* available.
*/
- public static final SequenceRepresentation EXPLICIT = new SequenceRepresentation(0);
+ public static final SequenceRepresentation EXPLICIT = new SequenceRepresentation("EXPLICIT", 0);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> = p for i
* ∈ [1, n], n is the total number of values and generation parameter p
* (offset).
*/
- public static final SequenceRepresentation IMPLICIT_CONSTANT = new SequenceRepresentation(1);
+ public static final SequenceRepresentation IMPLICIT_CONSTANT = new SequenceRepresentation("IMPLICIT_CONSTANT", 1);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -41,7 +41,7 @@
* number of values and generation parameters p<sub>1</sub> (start value)
* and p<sub>2</sub> (increment).
*/
- public static final SequenceRepresentation IMPLICIT_LINEAR = new SequenceRepresentation(2);
+ public static final SequenceRepresentation IMPLICIT_LINEAR = new SequenceRepresentation("IMPLICIT_LINEAR", 2);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -52,7 +52,7 @@
* (p<sub>3</sub>-p<sub>1</sub>)/p<sub>2</sub> must be truncated to integer
* to start each saw curve cycle at p<sub>1</sub>.
*/
- public static final SequenceRepresentation IMPLICIT_SAW = new SequenceRepresentation(3);
+ public static final SequenceRepresentation IMPLICIT_SAW = new SequenceRepresentation("IMPLICIT_SAW", 3);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -60,7 +60,7 @@
* total number of values and generation parameters p<sub>1</sub> (offset),
* p<sub>2</sub> (factor) and the raw value r at position i.
*/
- public static final SequenceRepresentation RAW_LINEAR = new SequenceRepresentation(4);
+ public static final SequenceRepresentation RAW_LINEAR = new SequenceRepresentation("RAW_LINEAR", 4);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> = ∑
@@ -70,19 +70,18 @@
* p<sub>j</sub> for j ∈ [1, p<sub>1</sub>] and the raw value r at
* position i.
*/
- public static final SequenceRepresentation RAW_POLYNOMIAL = new SequenceRepresentation(5);
+ public static final SequenceRepresentation RAW_POLYNOMIAL = new SequenceRepresentation("RAW_POLYNOMIAL", 5);
/*
- * Not used. Do not remove, because this changes the ordinal numbers of the
- * enumeration.
+ * Not used. But keep here to show ordinal sequence.
*/
- public static final SequenceRepresentation FORMULA = new SequenceRepresentation(6);
-
+ public static final SequenceRepresentation FORMULA = new SequenceRepresentation("FORMULA", 6);
+
/**
* Measured values are stored as is in an external file and values are
* therefore immediately available.
*/
- public static final SequenceRepresentation EXPLICIT_EXTERNAL = new SequenceRepresentation(7);
+ public static final SequenceRepresentation EXPLICIT_EXTERNAL = new SequenceRepresentation("EXPLICIT_EXTERNAL", 7);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -91,7 +90,7 @@
* p<sub>2</sub> (factor) and the raw value r at position i read from an
* external file.
*/
- public static final SequenceRepresentation RAW_LINEAR_EXTERNAL = new SequenceRepresentation(8);
+ public static final SequenceRepresentation RAW_LINEAR_EXTERNAL = new SequenceRepresentation("RAW_LINEAR_EXTERNAL", 8);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> = ∑
@@ -101,7 +100,7 @@
* p<sub>j</sub> for j ∈ [1, p<sub>1</sub>] and the raw value r at
* position i read from an external file.
*/
- public static final SequenceRepresentation RAW_POLYNOMIAL_EXTERNAL = new SequenceRepresentation(9);
+ public static final SequenceRepresentation RAW_POLYNOMIAL_EXTERNAL = new SequenceRepresentation("RAW_POLYNOMIAL_EXTERNAL", 9);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -110,7 +109,7 @@
* p<sub>1</sub> (offset), p<sub>2</sub> (factor), p<sub>2</sub>
* (calibration) and the raw value r at position i.
*/
- public static final SequenceRepresentation RAW_LINEAR_CALIBRATED = new SequenceRepresentation(10);
+ public static final SequenceRepresentation RAW_LINEAR_CALIBRATED = new SequenceRepresentation("RAW_LINEAR_CALIBRATED", 10);
/**
* Each value x<sub>i</sub> is generated as follows: x<sub>i</sub> =
@@ -120,7 +119,11 @@
* (calibration) and the raw value r at position i read from an external
* file.
*/
- public static final SequenceRepresentation RAW_LINEAR_CALIBRATED_EXTERNAL = new SequenceRepresentation(11);
+ public static final SequenceRepresentation RAW_LINEAR_CALIBRATED_EXTERNAL = new SequenceRepresentation("RAW_LINEAR_CALIBRATED_EXTERNAL", 11);
+
+ private SequenceRepresentation(String name, int ordinal) {
+ super(name, ordinal);
+ }
// ======================================================================
// Public methods
@@ -247,10 +250,4 @@
return name().startsWith("RAW");
}
- /**
- * Constructor, ensures the correct order
- */
- SequenceRepresentation(int ord) {
- super(ord);
- }
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/TypeSpecification.java b/src/main/java/org/eclipse/mdm/api/base/model/TypeSpecification.java
index 8d24763..4c81861 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/TypeSpecification.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/TypeSpecification.java
@@ -18,90 +18,83 @@
*/
public class TypeSpecification extends EnumerationValue {
- // ======================================================================
- // Enumerations
- // ======================================================================
+ public static final TypeSpecification BOOLEAN = new TypeSpecification("BOOLEAN", 0);
- final static TypeSpecification BOOLEAN = new TypeSpecification(0);
+ public static final TypeSpecification BYTE = new TypeSpecification("BYTE", 1);
- final static TypeSpecification BYTE = new TypeSpecification(1);
+ public static final TypeSpecification SHORT = new TypeSpecification("SHORT", 2);
- final static TypeSpecification SHORT = new TypeSpecification(2);
+ public static final TypeSpecification INTEGER = new TypeSpecification("INTEGER", 3);
- final static TypeSpecification INTEGER = new TypeSpecification(3);
+ public static final TypeSpecification LONG = new TypeSpecification("LONG", 4);
- final static TypeSpecification LONG = new TypeSpecification(4);
+ public static final TypeSpecification FLOAT = new TypeSpecification("FLOAT", 5);
- final static TypeSpecification FLOAT = new TypeSpecification(5);
+ public static final TypeSpecification DOUBLE = new TypeSpecification("DOUBLE", 6);
- final static TypeSpecification DOUBLE = new TypeSpecification(6);
+ public static final TypeSpecification SHORT_BEO = new TypeSpecification("SHORT_BEO", 7);
- final static TypeSpecification SHORT_BEO = new TypeSpecification(7);
+ public static final TypeSpecification INTEGER_BEO = new TypeSpecification("INTEGER_BEO", 8);
- final static TypeSpecification INTEGER_BEO = new TypeSpecification(8);
+ public static final TypeSpecification LONG_BEO = new TypeSpecification("LONG_BEO", 9);
- final static TypeSpecification LONG_BEO = new TypeSpecification(9);
+ public static final TypeSpecification FLOAT_BEO = new TypeSpecification("FLOAT_BEO", 10);
- final static TypeSpecification FLOAT_BEO = new TypeSpecification(10);
+ public static final TypeSpecification DOUBLE_BEO = new TypeSpecification("DOUBLE_BEO", 11);
- final static TypeSpecification DOUBLE_BEO = new TypeSpecification(11);
+ public static final TypeSpecification STRING = new TypeSpecification("STRING", 12);
- final static TypeSpecification STRING = new TypeSpecification(12);
+ public static final TypeSpecification BYTE_STREAM = new TypeSpecification("BYTE_STREAM", 13);
- final static TypeSpecification BYTE_STREAM = new TypeSpecification(13);
+ public static final TypeSpecification BLOB = new TypeSpecification("BLOB", 14);
- final static TypeSpecification BLOB = new TypeSpecification(14);
+ public static final TypeSpecification BOOLEAN_FLAGS_BEO = new TypeSpecification("BOOLEAN_FLAGS_BEO", 15);
- final static TypeSpecification BOOLEAN_FLAGS_BEO = new TypeSpecification(15);
+ public static final TypeSpecification BYTE_FLAGS_BEO = new TypeSpecification("BYTE_FLAGS_BEO", 16);
- final static TypeSpecification BYTE_FLAGS_BEO = new TypeSpecification(16);
+ public static final TypeSpecification STRING_FLAGS_BEO = new TypeSpecification("STRING_FLAGS_BEO", 17);
- final static TypeSpecification STRING_FLAGS_BEO = new TypeSpecification(17);
-
- final static TypeSpecification BYTE_STREAM_BEO = new TypeSpecification(18);
+ public static final TypeSpecification BYTE_STREAM_BEO = new TypeSpecification("BYTE_STREAM_BEO", 18);
// SBYTE,
- final static TypeSpecification SIGNED_BYTE = new TypeSpecification(19);
+ public static final TypeSpecification SIGNED_BYTE = new TypeSpecification("SIGNED_BYTE", 19);
// SBYTE_FLAGS_BEO,
- final static TypeSpecification SIGNED_BYTE_FLAGS_BEO = new TypeSpecification(20);
+ public static final TypeSpecification SIGNED_BYTE_FLAGS_BEO = new TypeSpecification("SIGNED_BYTE_FLAGS_BEO", 20);
// USHORT,
- final static TypeSpecification UNSIGNED_SHORT = new TypeSpecification(21);
+ public static final TypeSpecification UNSIGNED_SHORT = new TypeSpecification("UNSIGNED_SHORT", 21);
// USHORT_BEO,
- final static TypeSpecification UNSIGNED_SHORT_BEO = new TypeSpecification(22);
+ public static final TypeSpecification UNSIGNED_SHORT_BEO = new TypeSpecification("UNSIGNED_SHORT_BEO", 22);
// UINTEGER,
- final static TypeSpecification UNSIGNED_INTEGER = new TypeSpecification(23);
+ public static final TypeSpecification UNSIGNED_INTEGER = new TypeSpecification("UNSIGNED_INTEGER", 23);
// UINTEGER_BEO,
- final static TypeSpecification UNSIGNED_INTEGER_BEO = new TypeSpecification(24);
+ public static final TypeSpecification UNSIGNED_INTEGER_BEO = new TypeSpecification("UNSIGNED_INTEGER_BEO", 24);
- final static TypeSpecification STRING_UTF8 = new TypeSpecification(25);
+ public static final TypeSpecification STRING_UTF8 = new TypeSpecification("STRING_UTF8", 25);
- final static TypeSpecification STRING_UTF8_FLAGS_BEO = new TypeSpecification(26);
+ public static final TypeSpecification STRING_UTF8_FLAGS_BEO = new TypeSpecification("STRING_UTF8_FLAGS_BEO", 26);
// BIT_INT,
- final static TypeSpecification BIT_INTEGER = new TypeSpecification(27);
+ public static final TypeSpecification BIT_INTEGER = new TypeSpecification("BIT_INTEGER", 27);
// BIT_INT_BEO,
- final static TypeSpecification BIT_INTEGER_BEO = new TypeSpecification(28);
+ public static final TypeSpecification BIT_INTEGER_BEO = new TypeSpecification("BIT_INTEGER_BEO", 28);
// BIT_UINT,
- final static TypeSpecification BIT_UNSIGNED_INTEGER = new TypeSpecification(29);
+ public static final TypeSpecification BIT_UNSIGNED_INTEGER = new TypeSpecification("BIT_UNSIGNED_INTEGER", 29);
// BIT_UINT_BEO,
- final static TypeSpecification BIT_UNSIGNED_INTEGER_BEO = new TypeSpecification(30);
+ public static final TypeSpecification BIT_UNSIGNED_INTEGER_BEO = new TypeSpecification("BIT_UNSIGNED_INTEGER_BEO", 30);
- final static TypeSpecification BIT_FLOAT = new TypeSpecification(31);
+ public static final TypeSpecification BIT_FLOAT = new TypeSpecification("BIT_FLOAT", 31);
- final static TypeSpecification BIT_FLOAT_BEO = new TypeSpecification(32);
+ public static final TypeSpecification BIT_FLOAT_BEO = new TypeSpecification("BIT_FLOAT_BEO", 32);
- /**
- * Constructor, sets the order
- */
- TypeSpecification(int ord) {
- super(ord);
+ private TypeSpecification(String name, int ordinal) {
+ super(name, ordinal);
}
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/ValueType.java b/src/main/java/org/eclipse/mdm/api/base/model/ValueType.java
index 3a2e511..e29e7c3 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/ValueType.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/ValueType.java
@@ -9,6 +9,7 @@
package org.eclipse.mdm.api.base.model;
import java.lang.reflect.Array;
+import java.lang.reflect.Field;
import java.time.LocalDateTime;
/**
@@ -18,206 +19,190 @@
* @author Viktor Stoehr, Gigatronik Ingolstadt GmbH
* @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
*/
-public final class ValueType<T> extends EnumerationValue {
-
- // ======================================================================
- // Enumerations
- // ======================================================================
+public class ValueType<T> extends EnumerationValue {
/**
* A {@link Value} with this type contains a {@code String} value and
* replaces {@code null} with an empty {@code String}.
*/
- public static final ValueType<String> STRING = new ValueType<>(0, String.class, "");
+ public static final ValueType<String> STRING = new ValueType<>(String.class, "STRING", "");
/**
* A {@link Value} with this type contains a {@code String[]} value replaces
* {@code null} with an empty {@code String} array.
*/
- public static final ValueType<String[]> STRING_SEQUENCE = new ValueType<>(1, String[].class, new String[0]);
+ public static final ValueType<String[]> STRING_SEQUENCE = new ValueType<>(String[].class, "STRING_SEQUENCE", new String[0]);
/**
* A {@link Value} with this type contains a {@link LocalDateTime} value and
* does not replace {@code null}.
*/
- public static final ValueType<LocalDateTime> DATE = new ValueType<>(2, LocalDateTime.class, null);
+ public static final ValueType<LocalDateTime> DATE = new ValueType<>(LocalDateTime.class, "DATE", null);
/**
* A {@link Value} with this type contains a {@code LocalDateTime[]} value
* and replaces {@code null} with an empty {@code LocalDateTime} array.
*/
- public static final ValueType<LocalDateTime[]> DATE_SEQUENCE = new ValueType<>(3, LocalDateTime[].class,
- new LocalDateTime[0]);
+ public static final ValueType<LocalDateTime[]> DATE_SEQUENCE = new ValueType<>(LocalDateTime[].class, "DATE_SEQUENCE", new LocalDateTime[0]);
/**
* A {@link Value} with this type contains a {@link Boolean} value and
* replaces {@code null} with {@link Boolean#FALSE}.
*/
- public static final ValueType<Boolean> BOOLEAN = new ValueType<>(4, Boolean.class, Boolean.FALSE);
+ public static final ValueType<Boolean> BOOLEAN = new ValueType<>(Boolean.class, "BOOLEAN", Boolean.FALSE);
/**
* A {@link Value} with this type contains a {@code boolean[]} value and
* replaces {@code null} with an empty {@code boolean} array.
*/
- public static final ValueType<boolean[]> BOOLEAN_SEQUENCE = new ValueType<>(5, boolean[].class, new boolean[0]);
+ public static final ValueType<boolean[]> BOOLEAN_SEQUENCE = new ValueType<>(boolean[].class, "BOOLEAN_SEQUENCE", new boolean[0]);
/**
* A {@link Value} with this type contains a {@link Byte} value and replaces
* {@code null} with a {@code Byte} containing zero.
*/
- public static final ValueType<Byte> BYTE = new ValueType<>(6, Byte.class, Byte.valueOf((byte) 0));
+ public static final ValueType<Byte> BYTE = new ValueType<>(Byte.class, "BYTE", Byte.valueOf((byte) 0));
/**
* A {@link Value} with this type contains a {@code byte[]} value and
* replaces {@code null} with an empty {@code byte} array.
*/
- public static final ValueType<byte[]> BYTE_SEQUENCE = new ValueType<>(7, byte[].class, new byte[0]);
+ public static final ValueType<byte[]> BYTE_SEQUENCE = new ValueType<>(byte[].class, "BYTE_SEQUENCE", new byte[0]);
/**
* A {@link Value} with this type contains a {@link Short} value and
* replaces {@code null} with a {@code Short} containing zero.
*/
- public static final ValueType<Short> SHORT = new ValueType<>(8, Short.class, Short.valueOf((short) 0));
+ public static final ValueType<Short> SHORT = new ValueType<>(Short.class, "SHORT", Short.valueOf((short) 0));
/**
* A {@link Value} with this type contains a {@code short[]} value and
* replaces {@code null} with an empty {@code short} array.
*/
- public static final ValueType<short[]> SHORT_SEQUENCE = new ValueType<>(9, short[].class, new short[0]);
+ public static final ValueType<short[]> SHORT_SEQUENCE = new ValueType<>(short[].class, "SHORT_SEQUENCE", new short[0]);
/**
* A {@link Value} with this type contains a {@link Integer} value and
* replaces {@code null} with a {@code Integer} containing zero.
*/
- public static final ValueType<Integer> INTEGER = new ValueType<>(10, Integer.class, Integer.valueOf(0));
+ public static final ValueType<Integer> INTEGER = new ValueType<>(Integer.class, "INTEGER", Integer.valueOf(0));
/**
* A {@link Value} with this type contains a {@code int[]} value and
* replaces {@code null} with an empty {@code int} array.
*/
- public static final ValueType<int[]> INTEGER_SEQUENCE = new ValueType<>(11, int[].class, new int[0]);
+ public static final ValueType<int[]> INTEGER_SEQUENCE = new ValueType<>(int[].class, "INTEGER_SEQUENCE", new int[0]);
/**
* A {@link Value} with this type contains a {@link Long} value and replaces
* {@code null} with a {@code Long} containing zero.
*/
- public static final ValueType<Long> LONG = new ValueType<>(12, Long.class, Long.valueOf(0));
+ public static final ValueType<Long> LONG = new ValueType<>(Long.class, "LONG", Long.valueOf(0));
/**
* A {@link Value} with this type contains a {@code long[]} value and
* replaces {@code null} with an empty {@code long} array.
*/
- public static final ValueType<long[]> LONG_SEQUENCE = new ValueType<>(13, long[].class, new long[0]);
+ public static final ValueType<long[]> LONG_SEQUENCE = new ValueType<>(long[].class, "LONG_SEQUENCE", new long[0]);
/**
* A {@link Value} with this type contains a {@link Float} value and
* replaces {@code null} with a {@code Float} containing zero.
*/
- public static final ValueType<Float> FLOAT = new ValueType<>(14, Float.class, Float.valueOf(0));
+ public static final ValueType<Float> FLOAT = new ValueType<>(Float.class, "FLOAT", Float.valueOf(0));
/**
* A {@link Value} with this type contains a {@code float[]} value and
* replaces {@code null} with an empty {@code float} array.
*/
- public static final ValueType<float[]> FLOAT_SEQUENCE = new ValueType<>(15, float[].class, new float[0]);
+ public static final ValueType<float[]> FLOAT_SEQUENCE = new ValueType<>(float[].class, "FLOAT_SEQUENCE", new float[0]);
/**
* A {@link Value} with this type contains a {@link Double} value and
* replaces {@code null} with a {@code Double} containing zero.
*/
- public static final ValueType<Double> DOUBLE = new ValueType<>(16, Double.class, Double.valueOf(0));
+ public static final ValueType<Double> DOUBLE = new ValueType<>(Double.class, "DOUBLE", Double.valueOf(0));
/**
* A {@link Value} with this type contains a {@code double[]} value and
* replaces {@code null} with an empty {@code double} array.
*/
- public static final ValueType<double[]> DOUBLE_SEQUENCE = new ValueType<>(17, double[].class, new double[0]);
+ public static final ValueType<double[]> DOUBLE_SEQUENCE = new ValueType<>(double[].class, "DOUBLE_SEQUENCE", new double[0]);
/**
* A {@link Value} with this type contains a {@code byte[]} value and
* replaces {@code null} with an empty {@code byte} array.
*/
- public static final ValueType<byte[]> BYTE_STREAM = new ValueType<>(18, byte[].class, new byte[0]);
+ public static final ValueType<byte[]> BYTE_STREAM = new ValueType<>(byte[].class, "BYTE_STREAM", new byte[0]);
/**
* A {@link Value} with this type contains a {@code byte[][]} value and
* replaces {@code null} with an empty {@code byte[][]} array.
*/
- public static final ValueType<byte[][]> BYTE_STREAM_SEQUENCE = new ValueType<>(19, byte[][].class, new byte[0][]);
+ public static final ValueType<byte[][]> BYTE_STREAM_SEQUENCE = new ValueType<>(byte[][].class, "BYTE_STREAM_SEQUENCE", new byte[0][]);
/**
* A {@link Value} with this type contains a {@link FloatComplex} value and
* does not replaces {@code null}.
*/
- public static final ValueType<FloatComplex> FLOAT_COMPLEX = new ValueType<>(22, FloatComplex.class, null);
+ public static final ValueType<FloatComplex> FLOAT_COMPLEX = new ValueType<>(FloatComplex.class, "FLOAT_COMPLEX", null);
/**
* A {@link Value} with this type contains a {@code FloatComplex[]} value
* and replaces {@code null} with an empty {@code FloatComplex[]} array.
*/
- public static final ValueType<FloatComplex[]> FLOAT_COMPLEX_SEQUENCE = new ValueType<>(21, FloatComplex[].class,
- new FloatComplex[0]);
+ public static final ValueType<FloatComplex[]> FLOAT_COMPLEX_SEQUENCE = new ValueType<>(FloatComplex[].class, "FLOAT_COMPLEX_SEQUENCE", new FloatComplex[0]);
/**
* A {@link Value} with this type contains a {@link DoubleComplex} value and
* does not replaces {@code null}.
*/
- public static final ValueType<DoubleComplex> DOUBLE_COMPLEX = new ValueType<>(22, DoubleComplex.class, null);
+ public static final ValueType<DoubleComplex> DOUBLE_COMPLEX = new ValueType<>(DoubleComplex.class, "DOUBLE_COMPLEX", null);
/**
* A {@link Value} with this type contains a {@code DoubleComplex[]} value
* and replaces {@code null} with an empty {@code DoubleComplex[]} array.
*/
- public static final ValueType<DoubleComplex[]> DOUBLE_COMPLEX_SEQUENCE = new ValueType<>(23, DoubleComplex[].class,
- new DoubleComplex[0]);
+ public static final ValueType<DoubleComplex[]> DOUBLE_COMPLEX_SEQUENCE = new ValueType<>(DoubleComplex[].class, "DOUBLE_COMPLEX_SEQUENCE" , new DoubleComplex[0]);
/**
* A {@link Value} with this type contains a modeled enumeration constant
* value and does not replace {@code null}.
*
- * @see #create(Class, String)
- * @see #create(Class, String, String, boolean, Object)
*/
- public static final ValueType<EnumerationValue> ENUMERATION = new ValueType<>(24);
+ public static final ValueType<EnumerationValue> ENUMERATION = new ValueType<>("ENUMERATION");
/**
* A {@link Value} with this type contains a modeled enumeration constant
* array value and replaces {@code null} with an empty array with defined
* component type.
*
- * @see #create(Class, String)
- * @see #create(Class, String, String, boolean, Object)
*/
- public static final ValueType<EnumerationValue[]> ENUMERATION_SEQUENCE = new ValueType<>(25);
+ public static final ValueType<EnumerationValue[]> ENUMERATION_SEQUENCE = new ValueType<>("ENUMERATION_SEQUENCE");
/**
* A {@link Value} with this type contains a {@link FileLink} value and does
* not replace {@code null}.
*/
- public static final ValueType<FileLink> FILE_LINK = new ValueType<>(26, FileLink.class, null);
+ public static final ValueType<FileLink> FILE_LINK = new ValueType<>(FileLink.class, "FILE_LINK" , null);
/**
* A {@link Value} with this type contains a {@code FileLink[]} value and
* replaces {@code null} with an empty {@code FileLink} array.
*/
- public static final ValueType<FileLink[]> FILE_LINK_SEQUENCE = new ValueType<>(27, FileLink[].class,
- new FileLink[0]);
+ public static final ValueType<FileLink[]> FILE_LINK_SEQUENCE = new ValueType<>(FileLink[].class, "FILE_LINK_SEQUENCE" , new FileLink[0]);
/**
* TODO ...
*/
- public static final ValueType<Object> BLOB = new ValueType<>(28, Object.class, null);
+ public static final ValueType<Object> BLOB = new ValueType<>(Object.class, "", null);
/**
* A {@link Value} with this type contains a {@link Object} value and does
* not replace {@code null}. This value type does not have a corresponding
* sequence type.
*/
- public static final ValueType<Object> UNKNOWN = new ValueType<>(29, Object.class, null);
-
- // ======================================================================
- // Instance variables
- // ======================================================================
+ public static final ValueType<Object> UNKNOWN = new ValueType<>(Object.class, "UNKNOWN", null);
/**
* The type is used to check assignment compatibility of non {@code null}
@@ -234,33 +219,29 @@
/**
* Constructor - May only be used to create {@link #ENUMERATION},
* {@link #ENUMERATION_SEQUENCE} or {@link #UNKNOWN} types.
+ *
+ * @param name
*/
- private ValueType(int ordinal) {
- this(ordinal, null, null);
+ private ValueType(String name) {
+ this(null, name, null);
}
/**
* Constructor.
- *
- * @param ordinal
- * The ordinal value of a {@link Value} with this value type.
* @param type
* The type of value a {@link Value} with this value type will
* accept.
+ * @param name
* @param defaultValue
* Will be used as {@code null} replacement in
* {@link Value#set(Object)}.
*/
- private ValueType(int ordinal, Class<T> type, T defaultValue) {
- super(ordinal);
+ private ValueType(Class<T> type, String name, T defaultValue) {
+ super(name);
this.type = type;
this.defaultValue = defaultValue;
}
- // ======================================================================
- // Public methods
- // ======================================================================
-
/**
* Creates a new {@link Value} initialized with given name. The {@code
* Value}'s initial validity flag will be set to {@code true}, the unit name
@@ -342,8 +323,6 @@
*
* @param <E>
* Modeled enumeration type.
- * @param enumClass
- * The enumeration class type will be used for validity checking.
* @param name
* The name of the attribute.
* @return The created {@code Value} is returned.
@@ -363,8 +342,6 @@
*
* @param <E>
* Modeled enumeration type.
- * @param enumClass
- * The enumeration class type will be used for validity checking.
* @param name
* The name of the attribute.
* @param unit
@@ -377,8 +354,7 @@
* @throws IllegalStateException
* Thrown if {@link #isEnumerationType()} returns {@code false}.
*/
- public <E extends EnumerationValue> Value create(String name, String unit, boolean valid, Object input,
- String valueTypeDescr) {
+ public <E extends EnumerationValue> Value create(String name, String unit, boolean valid, Object input, String valueTypeDescr) {
if (isEnumerationType()) {
Object nullReplacement = null;
Class<?> valueClass = EnumerationValue.class;
@@ -988,15 +964,16 @@
* @return Returns {@code true} in the cases listed above.
*/
public boolean isSequence() {
- return name().endsWith("SEQUENCE");
+ return name() != null && name().endsWith("SEQUENCE");
}
/**
* Returns the sequence version of this value type. This method returns
* itself, if this value type is a sequence type.
*
- * If you extend the class ValueType, you have to ensure that T contains a
- * field of the correct name and type, otherwise a runtime error will occur.
+ * If you extend the class ValueType, you have to ensure that T contains a field
+ * of the correct name and type,
+ * otherwise a runtime error will occur.
*
* @return The sequence version of this value type is returned.
*/
@@ -1013,18 +990,32 @@
* Returns the scalar version of this value type. This method returns
* itself, if this value type is a scalar type.
*
- * If you extend the class ValueType, you have to ensure that T contains a
- * field of the correct name and type, otherwise a runtime error will occur.
+ * If you extend the class ValueType, you have to ensure that T
+ * contains a field of the correct name and type,
+ * otherwise a runtime error will occur.
*
* @return The sequence version of this value type is returned.
*/
@SuppressWarnings("unchecked")
public <S extends ValueType<?>> S toSingleType() {
- if (isSequence()) {
- return (S) valueOf(name().replace("_SEQUENCE", ""));
- }
- return (S) this;
+ if(isEnumerationType()) {
+ if (isSequence()) {
+ return (S) valueOf(name().replace("_SEQUENCE", ""));
+ }
+
+ return (S) this;
+ } else {
+ try {
+ if(isSequence()) {
+ Field field = getClass().getField(name().replace("_SEQUENCE", ""));
+ return (S) field.get(this);
+ }
+ return (S) this;
+ } catch (NoSuchFieldException | ClassCastException | IllegalAccessException e) {
+ throw new RuntimeException("Can't figure out single type for " + name());
+ }
+ }
}
/**
@@ -1038,7 +1029,8 @@
if (isEnumerationType()) {
throw new IllegalStateException("");
}
-
return type;
}
+
+
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/VersionState.java b/src/main/java/org/eclipse/mdm/api/base/model/VersionState.java
index 6416f4d..05e2e5b 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/VersionState.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/VersionState.java
@@ -26,7 +26,7 @@
* An entity with this version state is still editable and hence not allowed
* be used when creating new entities.
*/
- public static final VersionState EDITABLE = new VersionState(0);
+ public static final VersionState EDITABLE = new VersionState("EDITABLE", 0);
/**
* An entity with this version state is no longer editable and is allowed to
@@ -36,21 +36,21 @@
* <b>Note:</b> If an entity's version state is this state, then its version
* state is only allowed to be changed to {@link #ARCHIVED}.
*/
- public static final VersionState VALID = new VersionState(1);
+ public static final VersionState VALID = new VersionState("VALID", 1);
/**
* An entity with this version state is neither editable nor is it allowed
- * to use it when creating new entities.
+ * to use it when creating new entities
*
* <p>
* <b>Note:</b> If an entity's version state is this state, then its version
* state is no longer allowed to be changed.
*/
- public static final VersionState ARCHIVED = new VersionState(2);
+ public static final VersionState ARCHIVED = new VersionState("ARCHIVED", 2);
- // ======================================================================
- // Public methods
- // ======================================================================
+ private VersionState(String name, int ordinal) {
+ super(name, ordinal);
+ }
/**
* Returns true if this version state is {@link #EDITABLE}.
@@ -82,10 +82,4 @@
return ARCHIVED == this;
}
- /**
- * Constructor, ensures the correct order
- */
- VersionState(int ord) {
- super(ord);
- }
}
diff --git a/src/main/test/org/eclipse/mdm/api/base/BaseEntityManagerTest.java b/src/test/java/org/eclipse/mdm/api/base/BaseEntityManagerTest.java
similarity index 87%
rename from src/main/test/org/eclipse/mdm/api/base/BaseEntityManagerTest.java
rename to src/test/java/org/eclipse/mdm/api/base/BaseEntityManagerTest.java
index e05b4d5..85ca0d8 100644
--- a/src/main/test/org/eclipse/mdm/api/base/BaseEntityManagerTest.java
+++ b/src/test/java/org/eclipse/mdm/api/base/BaseEntityManagerTest.java
@@ -7,16 +7,15 @@
*/
package org.eclipse.mdm.api.base;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import org.eclipse.mdm.api.base.model.TestStep;
+import org.eclipse.mdm.api.base.query.DataAccessException;
+import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
-import org.eclipse.mdm.api.base.model.BaseEntityFactory;
-import org.eclipse.mdm.api.base.model.TestStep;
-import org.eclipse.mdm.api.base.query.DataAccessException;
-import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.*;
public class BaseEntityManagerTest {
@@ -25,7 +24,7 @@
public void loadShouldReturnEntity() throws DataAccessException {
@SuppressWarnings("unchecked")
- BaseEntityManager<BaseEntityFactory> entityManager = mock(BaseEntityManager.class);
+ BaseEntityManager entityManager = mock(BaseEntityManager.class);
TestStep mockedTestStep = mock(TestStep.class);
when(entityManager.load(any(), anyString())).thenCallRealMethod();
@@ -39,7 +38,7 @@
public void loadNotExistingIdShouldThrowDataAccessException() throws DataAccessException {
@SuppressWarnings("unchecked")
- BaseEntityManager<BaseEntityFactory> entityManager = mock(BaseEntityManager.class);
+ BaseEntityManager entityManager = mock(BaseEntityManager.class);
when(entityManager.load(any(), anyString())).thenCallRealMethod();
when(entityManager.load(eq(TestStep.class), anyCollection())).thenReturn(Collections.<TestStep>emptyList());
@@ -53,7 +52,7 @@
public void loadNotUniqueIdShouldThrowDataAccessException() throws DataAccessException {
@SuppressWarnings("unchecked")
- BaseEntityManager<BaseEntityFactory> entityManager = mock(BaseEntityManager.class);
+ BaseEntityManager entityManager = mock(BaseEntityManager.class);
TestStep mockedTestStep1 = mock(TestStep.class);
TestStep mockedTestStep2 = mock(TestStep.class);
diff --git a/src/test/java/org/eclipse/mdm/api/base/model/ModelTest.java b/src/test/java/org/eclipse/mdm/api/base/model/ModelTest.java
index f214ca2..ffe19c4 100755
--- a/src/test/java/org/eclipse/mdm/api/base/model/ModelTest.java
+++ b/src/test/java/org/eclipse/mdm/api/base/model/ModelTest.java
@@ -34,19 +34,9 @@
*/
public class ModelTest {
- /**
- * Quick and dirty comparison of two numbers for approximate equality
- *
- * @param a
- * @param b
- * @return
- */
- private <T extends Number> boolean fpEquals(T a, T b) {
- double eps = 0.00005d;
- double ad = a.doubleValue();
- double bd = b.doubleValue();
- return (Math.abs(ad - bd) < eps * Math.abs(Math.max(ad, bd)));
- }
+ // compare doubles up to this accuracy
+ private static final double EPSILON = 0.00005d;
+
/**
* basic test for reading the value of a parameter.The intialization via
@@ -54,7 +44,7 @@
*/
@org.junit.Test
public void parameterValue() {
- Map<String, Value> map = new HashMap<String, Value>();
+ Map<String, Value> map = new HashMap<>();
map.put("DataType", new Value(ValueType.STRING, "DataType", null, true, ScalarType.FLOAT, ScalarType.class,
ScalarType.FLOAT, EnumRegistry.SCALAR_TYPE));
map.put("Value", ValueType.STRING.create("Value", null, true, "5.7"));
@@ -62,8 +52,8 @@
Core core = new CoreImpl(map);
Parameter tp = new Parameter(core);
Value vv = tp.getVirtualValue();
- Float extracted = vv.<Float>extract();
- assertTrue(fpEquals(new Float(5.7f), extracted));
+ Float extracted = vv.extract();
+ assertEquals(5.7f, extracted, EPSILON);
}
/**
@@ -79,7 +69,7 @@
while (valueIterator.hasNext()) {
boolean isCurrentValid = valueIterator.isValid();
Float currentValue = valueIterator.next();
- assertTrue(fpEquals(vals[i], currentValue));
+ assertEquals(vals[i], currentValue, EPSILON);
assertEquals(flags[i], isCurrentValid);
i++;
}
@@ -99,7 +89,7 @@
while (valueIterator.hasNext()) {
boolean isCurrentValid = valueIterator.isValid();
Double currentValue = valueIterator.next();
- assertTrue(fpEquals(vals[i], currentValue));
+ assertEquals(vals[i], currentValue, EPSILON);
assertEquals(flags[i], isCurrentValid);
i++;
}
@@ -141,8 +131,8 @@
Channel ch = new Channel(core);
Double min = ch.getMinimum();
Double max = ch.getMaximum();
- assertTrue(fpEquals(min, min_src));
- assertTrue(fpEquals(max, max_src));
+ assertEquals(min, min_src, EPSILON);
+ assertEquals(max, max_src, EPSILON);
}
/**
@@ -166,8 +156,7 @@
@org.junit.Test
public void writeRequest() {
AxisType axisType = AxisType.X_AXIS;
- Map<String, Value> map = new HashMap<String, Value>();
- Core core = new CoreImpl(map);
+ Core core = new CoreImpl(new HashMap<>());
ChannelGroup channelGroup = new ChannelGroup(core);
Channel channel = new Channel(core);
WriteRequestBuilder wrb = WriteRequest.create(channelGroup, channel, axisType);
@@ -373,7 +362,7 @@
@org.junit.Test
public void enumRegistry() {
EnumRegistry er = EnumRegistry.getInstance();
- assertTrue(er.get("Interpolation") instanceof Enumeration<?>);
+ assertTrue(er.get("Interpolation") != null);
}
}