Commit ca7ca039 authored by maquil's avatar maquil

Merge branch 'dev-nico' of https://git.list.lu/nui/TULIP-CPS.git into dev-nico

parents 6cb56c6b 13665e57
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>lu.list.itis.dkd.tui</groupId> <groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId> <artifactId>tulip-cps</artifactId>
<version>1.3.1</version> <version>1.4.0</version>
<name>TULIP Complex Problem Solving</name> <name>TULIP Complex Problem Solving</name>
<licenses> <licenses>
...@@ -59,6 +59,27 @@ ...@@ -59,6 +59,27 @@
<artifactId>jython-standalone</artifactId> <artifactId>jython-standalone</artifactId>
<version>2.7.1b3</version> <version>2.7.1b3</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.23</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
......
...@@ -27,9 +27,10 @@ import lu.list.itis.dkd.tui.cps.variable.Variable; ...@@ -27,9 +27,10 @@ import lu.list.itis.dkd.tui.cps.variable.Variable;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
...@@ -49,7 +50,7 @@ public class Equation { ...@@ -49,7 +50,7 @@ public class Equation {
private Executor scriptExecutor; private Executor scriptExecutor;
private String script; private String script;
private static Logger LOGGER = Logger.getLogger(Equation.class.getSimpleName()); private static Logger LOGGER = LoggerFactory.getLogger(Equation.class.getSimpleName());
/** /**
* Constructor * Constructor
...@@ -103,7 +104,7 @@ public class Equation { ...@@ -103,7 +104,7 @@ public class Equation {
scriptExecutor.eval(this.script); scriptExecutor.eval(this.script);
} catch (Exception exception) { } catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Error while evaluating script " + this.script, exception); //$NON-NLS-1$ LOGGER.error("Error while evaluating script {}", this.script, exception); //$NON-NLS-1$
} }
dependentVariables = mapping.getDependentVariables(); dependentVariables = mapping.getDependentVariables();
...@@ -111,18 +112,18 @@ public class Equation { ...@@ -111,18 +112,18 @@ public class Equation {
try { try {
variable = scriptExecutor.get(variable); variable = scriptExecutor.get(variable);
} catch (Exception exception) { } catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Error while retrieving variable " + variable.getName(), exception); //$NON-NLS-1$ LOGGER.error("Error while retrieving variable {}", variable.getName(), exception); //$NON-NLS-1$
} }
} }
evaluationErrors = scriptExecutor.getExecutionErrors(); evaluationErrors = scriptExecutor.getExecutionErrors();
if (evaluationErrors.length() > 0) { if (evaluationErrors.length() > 0) {
LOGGER.log(Level.WARNING, "Error while evaluating equation :" + evaluationErrors); //$NON-NLS-1$ LOGGER.warn("Error while evaluating equation : {}", evaluationErrors); //$NON-NLS-1$
LOGGER.log(Level.WARNING, "Script =" + this.script); //$NON-NLS-1$ LOGGER.warn("Script = {}", this.script); //$NON-NLS-1$
LinkedHashSet<Variable> independentVariables = mapping.getIndependentVariables(); LinkedHashSet<Variable> independentVariables = mapping.getIndependentVariables();
for (Variable variable : independentVariables) { for (Variable variable : independentVariables) {
LOGGER.log(Level.INFO, variable.getName() + " = " + variable.getValue()); //$NON-NLS-1$ LOGGER.trace("{} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
} }
} }
} }
......
...@@ -3,15 +3,17 @@ package lu.list.itis.dkd.tui.cps.system.executor; ...@@ -3,15 +3,17 @@ package lu.list.itis.dkd.tui.cps.system.executor;
import lu.list.itis.dkd.tui.cps.system.Import; import lu.list.itis.dkd.tui.cps.system.Import;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.CharArrayWriter; import java.io.CharArrayWriter;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger;
abstract public class Executor { abstract public class Executor {
protected CharArrayWriter executionErrors; protected CharArrayWriter executionErrors;
private static Logger LOGGER = Logger.getLogger(Executor.class.getSimpleName()); private static Logger LOGGER = LoggerFactory.getLogger(Executor.class.getSimpleName());
public Executor() { public Executor() {
executionErrors = new CharArrayWriter(); executionErrors = new CharArrayWriter();
...@@ -32,7 +34,7 @@ abstract public class Executor { ...@@ -32,7 +34,7 @@ abstract public class Executor {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void resolve(List<Import> imports) { public void resolve(List<Import> imports) {
LOGGER.warning("Imports not supported by Executor!"); //$NON-NLS-1$ LOGGER.warn("Imports not supported by Executor!"); //$NON-NLS-1$
} }
abstract public void set(Variable variable); abstract public void set(Variable variable);
......
...@@ -2,8 +2,10 @@ package lu.list.itis.dkd.tui.cps.system.executor; ...@@ -2,8 +2,10 @@ package lu.list.itis.dkd.tui.cps.system.executor;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
...@@ -13,7 +15,7 @@ public class JavascriptExecutor extends Executor { ...@@ -13,7 +15,7 @@ public class JavascriptExecutor extends Executor {
private ScriptEngine engine; private ScriptEngine engine;
private Object result; private Object result;
private static Logger LOGGER = Logger.getLogger(JavascriptExecutor.class.getSimpleName()); private static Logger LOGGER = LoggerFactory.getLogger(JavascriptExecutor.class.getSimpleName());
public JavascriptExecutor() { public JavascriptExecutor() {
engine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$ engine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
...@@ -28,14 +30,24 @@ public class JavascriptExecutor extends Executor { ...@@ -28,14 +30,24 @@ public class JavascriptExecutor extends Executor {
@Override @Override
public void set(Variable variable) { public void set(Variable variable) {
engine.put(variable.getName(), variable.getValue()); engine.put(variable.getName(), variable.getValue());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
} }
@Override @Override
public boolean eval(String script) { public boolean eval(String script) {
try { try {
long elapsed = System.currentTimeMillis();
result = engine.eval(script); result = engine.eval(script);
elapsed = System.currentTimeMillis() - elapsed;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$
}
} catch (ScriptException exception) { } catch (ScriptException exception) {
this.executionErrors.append(exception.toString()); this.executionErrors.append(exception.toString());
LOGGER.warn("Failed to eval script => {}", script); //$NON-NLS-1$
LOGGER.warn("Caused by...", exception); //$NON-NLS-1$
return false; return false;
} }
return true; return true;
...@@ -44,6 +56,9 @@ public class JavascriptExecutor extends Executor { ...@@ -44,6 +56,9 @@ public class JavascriptExecutor extends Executor {
@Override @Override
public Variable get(Variable variable) { public Variable get(Variable variable) {
variable.setValue(result); variable.setValue(result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Result {} = {}", variable.getName(), result); //$NON-NLS-1$
}
return variable; return variable;
} }
} }
...@@ -2,6 +2,9 @@ package lu.list.itis.dkd.tui.cps.system.executor; ...@@ -2,6 +2,9 @@ package lu.list.itis.dkd.tui.cps.system.executor;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.util.Properties; import java.util.Properties;
...@@ -16,14 +19,25 @@ public class OctaveExecutor extends Executor { ...@@ -16,14 +19,25 @@ public class OctaveExecutor extends Executor {
private static final String SCRIPT_ENGINE_EXECUTABLE = "octave.executable"; //$NON-NLS-1$ private static final String SCRIPT_ENGINE_EXECUTABLE = "octave.executable"; //$NON-NLS-1$
private static final String SCRIPT_ENGINE_WORKING_DIR = "octave.workingDir"; //$NON-NLS-1$ private static final String SCRIPT_ENGINE_WORKING_DIR = "octave.workingDir"; //$NON-NLS-1$
// private static Logger LOGGER = Logger.getLogger(OctaveExecutor.class.getSimpleName()); private static final String DEFAULT_EXECUTABLE = "/opt/local/bin/octave"; //$NON-NLS-1$
private static final String DEFAULT_WORKING_DIR = "octave"; //$NON-NLS-1$
private static Logger LOGGER = LoggerFactory.getLogger(OctaveExecutor.class.getSimpleName());
public OctaveExecutor(Properties properties) { public OctaveExecutor(Properties properties) {
super(properties); super(properties);
OctaveEngineFactory engineFactory = new OctaveEngineFactory(); OctaveEngineFactory engineFactory = new OctaveEngineFactory();
engineFactory.setOctaveProgram(new File(properties.getProperty(SCRIPT_ENGINE_EXECUTABLE, "/opt/local/bin/octave"))); //$NON-NLS-1$ String executable = properties.getProperty(SCRIPT_ENGINE_EXECUTABLE, DEFAULT_EXECUTABLE);
engineFactory.setWorkingDir(new File(properties.getProperty(SCRIPT_ENGINE_WORKING_DIR, "octave"))); //$NON-NLS-1$ String workingDir = properties.getProperty(SCRIPT_ENGINE_WORKING_DIR, DEFAULT_WORKING_DIR);
engineFactory.setOctaveProgram(new File(executable));
engineFactory.setWorkingDir(new File(workingDir));
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Octave Executable : {}", executable); //$NON-NLS-1$
LOGGER.info("Octave Working Dir : {}", workingDir); //$NON-NLS-1$
}
engine = engineFactory.getScriptEngine(); engine = engineFactory.getScriptEngine();
engine.setErrorWriter(this.executionErrors); engine.setErrorWriter(this.executionErrors);
...@@ -33,11 +47,19 @@ public class OctaveExecutor extends Executor { ...@@ -33,11 +47,19 @@ public class OctaveExecutor extends Executor {
public void set(Variable variable) { public void set(Variable variable) {
Double numericValue = Double.valueOf(variable.getValue().toString()); Double numericValue = Double.valueOf(variable.getValue().toString());
engine.put(variable.getName(), Octave.scalar(numericValue)); engine.put(variable.getName(), Octave.scalar(numericValue));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
} }
@Override @Override
public boolean eval(String script) { public boolean eval(String script) {
long elapsed = System.currentTimeMillis();
engine.eval(script); engine.eval(script);
elapsed = System.currentTimeMillis() - elapsed;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$
}
return true; return true;
} }
...@@ -45,6 +67,10 @@ public class OctaveExecutor extends Executor { ...@@ -45,6 +67,10 @@ public class OctaveExecutor extends Executor {
public Variable get(Variable variable) { public Variable get(Variable variable) {
OctaveDouble result = engine.get(OctaveDouble.class, variable.getName()); OctaveDouble result = engine.get(OctaveDouble.class, variable.getName());
variable.setValue(result.get(1)); variable.setValue(result.get(1));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Result {} = {}", variable.getName(), result.get(1)); //$NON-NLS-1$
}
return variable; return variable;
} }
......
...@@ -7,11 +7,11 @@ import org.python.core.PyFloat; ...@@ -7,11 +7,11 @@ import org.python.core.PyFloat;
import org.python.core.PyObject; import org.python.core.PyObject;
import org.python.core.PyTuple; import org.python.core.PyTuple;
import org.python.util.PythonInterpreter; import org.python.util.PythonInterpreter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -22,7 +22,7 @@ public class PythonExecutor extends Executor { ...@@ -22,7 +22,7 @@ public class PythonExecutor extends Executor {
private static final Pattern TUPLE_PATTERN = Pattern.compile("^([a-z0-9_]+)\\.([a-z0-9_]+)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ private static final Pattern TUPLE_PATTERN = Pattern.compile("^([a-z0-9_]+)\\.([a-z0-9_]+)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Logger LOGGER = Logger.getLogger(PythonExecutor.class.getSimpleName()); private static Logger LOGGER = LoggerFactory.getLogger(PythonExecutor.class.getSimpleName());
public PythonExecutor(Properties properties) { public PythonExecutor(Properties properties) {
super(properties); super(properties);
...@@ -41,8 +41,7 @@ public class PythonExecutor extends Executor { ...@@ -41,8 +41,7 @@ public class PythonExecutor extends Executor {
StringBuilder importBuilder = new StringBuilder("from "); //$NON-NLS-1$ StringBuilder importBuilder = new StringBuilder("from "); //$NON-NLS-1$
importBuilder.append(declaration.getFrom()).append(" import ").append(declaration.getFunction()); //$NON-NLS-1$ importBuilder.append(declaration.getFrom()).append(" import ").append(declaration.getFunction()); //$NON-NLS-1$
engine.exec(importBuilder.toString()); engine.exec(importBuilder.toString());
LOGGER.info(importBuilder.toString());
LOGGER.log(Level.INFO, importBuilder.toString());
} }
} }
...@@ -50,11 +49,19 @@ public class PythonExecutor extends Executor { ...@@ -50,11 +49,19 @@ public class PythonExecutor extends Executor {
public void set(Variable variable) { public void set(Variable variable) {
Double numericValue = Double.valueOf(variable.getValue().toString()); Double numericValue = Double.valueOf(variable.getValue().toString());
engine.set(variable.getName(), new PyFloat(numericValue)); engine.set(variable.getName(), new PyFloat(numericValue));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parameter {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
} }
@Override @Override
public boolean eval(String script) { public boolean eval(String script) {
long elapsed = System.currentTimeMillis();
engine.exec(script); engine.exec(script);
elapsed = System.currentTimeMillis() - elapsed;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Eval => {} | took {} ms!", script, elapsed); //$NON-NLS-1$
}
return true; return true;
} }
...@@ -67,9 +74,16 @@ public class PythonExecutor extends Executor { ...@@ -67,9 +74,16 @@ public class PythonExecutor extends Executor {
if (tupleMatcher.matches()) { if (tupleMatcher.matches()) {
PyTuple tuple = (PyTuple) engine.get(tupleMatcher.group(1)); PyTuple tuple = (PyTuple) engine.get(tupleMatcher.group(1));
result = tuple.__getattr__(tupleMatcher.group(2)); result = tuple.__getattr__(tupleMatcher.group(2));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Result {} = {}.{} = {}", variable.getName(), tupleMatcher.group(1), tupleMatcher.group(2), result); //$NON-NLS-1$
}
} }
} else { } else {
result = engine.get(variable.getName()); result = engine.get(variable.getName());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Result {} = {}", variable.getName(), result); //$NON-NLS-1$
}
} }
variable.setValue((result != null) ? result.__tojava__(Double.class) : null); variable.setValue((result != null) ? result.__tojava__(Double.class) : null);
return variable; return variable;
......
...@@ -32,12 +32,13 @@ public class Externalization extends NLS { ...@@ -32,12 +32,13 @@ public class Externalization extends NLS {
private static final String BUNDLE_NAME = "lu.list.itis.dkd.tui.cps.utility.externalization"; private static final String BUNDLE_NAME = "lu.list.itis.dkd.tui.cps.utility.externalization";
public static String EXECUTOR_CLASS; public static String EXECUTOR_CLASS;
public static String VARIABLE_CLASS; public static String NUMERIC_VARIABLE_CLASS;
public static String LOGIC_VARIABLE_CLASS;
public static String EQUATION_ELEMENT; public static String EQUATION_ELEMENT;
public static String EQUATIONS_ELEMENT; public static String EQUATIONS_ELEMENT;
public static String INVOKE_ELEMENT; public static String INVOKE_ELEMENT;
public static String NAME_ELEMENT; public static String NAME_ATTRIBUTE;
public static String OUTPUT_ELEMENT; public static String OUTPUT_ELEMENT;
public static String OUTPUTS_ELEMENT; public static String OUTPUTS_ELEMENT;
public static String PARAMETER_ELEMENT; public static String PARAMETER_ELEMENT;
...@@ -52,8 +53,15 @@ public class Externalization extends NLS { ...@@ -52,8 +53,15 @@ public class Externalization extends NLS {
public static String FROM_ATTRIBUTE; public static String FROM_ATTRIBUTE;
public static String IMPORTS_ELEMENT; public static String IMPORTS_ELEMENT;
public static String SYSTEM_ELEMENT; public static String SYSTEM_ELEMENT;
public static String TYPE_ATTRIBUTE;
public static String UNIT_ATTRIBUTE; public static String UNIT_ATTRIBUTE;
public static String UNIT_ELEMENT; public static String MINIMUM_ATTRIBUTE;
public static String MAXIMUM_ATTRIBUTE;
public static String SCALE_ATTRIBUTE;
public static String DECIMALS_ATTRIBUTE;
public static final String LOGIC_TYPE = "logic";
public static final String NUMERIC_TYPE = "numeric";
static { static {
// initialize resource bundle // initialize resource bundle
......
EXECUTOR_CLASS=executor.class EXECUTOR_CLASS=executor.class
VARIABLE_CLASS=variable.class NUMERIC_VARIABLE_CLASS=numeric.variable.class
EQUATION_ELEMENT=equation LOGIC_VARIABLE_CLASS=logic.variable.class
EQUATIONS_ELEMENT=equations EQUATIONS_ELEMENT=equations
EQUATION_ELEMENT=equation
INVOKE_ELEMENT=invoke INVOKE_ELEMENT=invoke
NAME_ELEMENT=name NAME_ATTRIBUTE=name
OUTPUT_ELEMENT=output
OUTPUTS_ELEMENT=outputs OUTPUTS_ELEMENT=outputs
OUTPUT_ELEMENT=output
PARAMETER_ELEMENT=parameter PARAMETER_ELEMENT=parameter
TYPE_ATTRIBUTE=type
INITIAL_ATTRIBUTE=initial INITIAL_ATTRIBUTE=initial
MINIMUM_ATTRIBUTE=minimum
MAXIMUM_ATTRIBUTE=maximum
SCALE_ATTRIBUTE=scale
DECIMALS_ATTRIBUTE=decimals
PARAMETERS_ELEMENT=parameters PARAMETERS_ELEMENT=parameters
PERIODIC_ATTRIBUTE=periodic PERIODIC_ATTRIBUTE=periodic
RESULT_ELEMENT=result RESULT_ELEMENT=result
EQUATE_ATTRIBUTE=equate EQUATE_ATTRIBUTE=equate
RESULTS_ELEMENT=results RESULTS_ELEMENT=results
IMPORTS_ELEMENT=imports
IMPORT_ELEMENT=import IMPORT_ELEMENT=import
FUNCTION_ATTRIBUTE=function FUNCTION_ATTRIBUTE=function
FROM_ATTRIBUTE=from FROM_ATTRIBUTE=from
IMPORTS_ELEMENT=imports
SYSTEM_ELEMENT=system SYSTEM_ELEMENT=system
UNIT_ATTRIBUTE=unit UNIT_ATTRIBUTE=unit
UNIT_ELEMENT=unit \ No newline at end of file
\ No newline at end of file
...@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.cps.variable; ...@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.cps.variable;
import lu.list.itis.dkd.tui.cps.InputChangeListener; import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent; import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.utility.Externalization;
import java.util.Vector; import java.util.Vector;
...@@ -39,7 +40,7 @@ public class BooleanVariable extends Variable { ...@@ -39,7 +40,7 @@ public class BooleanVariable extends Variable {
* @param value * @param value
*/ */
public BooleanVariable(String name, boolean value) { public BooleanVariable(String name, boolean value) {
super(name, "boolean"); //$NON-NLS-1$ super(Externalization.LOGIC_TYPE, name, "boolean"); //$NON-NLS-1$
this.value = value; this.value = value;
} }
...@@ -56,7 +57,7 @@ public class BooleanVariable extends Variable { ...@@ -56,7 +57,7 @@ public class BooleanVariable extends Variable {
if (value instanceof Boolean) { if (value instanceof Boolean) {
this.value = (Boolean) value; this.value = (Boolean) value;
} else { } else {
this.value = Boolean.parseBoolean(value.toString()); this.value = (Boolean) valueFromString(value.toString());
} }
for (InputChangeListener listener : listeners) { for (InputChangeListener listener : listeners) {
...@@ -71,4 +72,10 @@ public class BooleanVariable extends Variable { ...@@ -71,4 +72,10 @@ public class BooleanVariable extends Variable {
variable.listeners = new Vector<>(listeners); variable.listeners = new Vector<>(listeners);
return variable; return variable;
} }
/** {@inheritDoc} */
@Override
public Object valueFromString(String stringValue) {
return Boolean.parseBoolean(stringValue);
}
} }
\ No newline at end of file
...@@ -24,13 +24,14 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; ...@@ -24,13 +24,14 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable; import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.cps.InputChangeListener; import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent; import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.utility.Externalization;
import org.jdom2.Element; import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Vector; import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Class implementing numerical variables as handled by the {@link System}. * Class implementing numerical variables as handled by the {@link System}.
...@@ -38,12 +39,19 @@ import java.util.logging.Logger; ...@@ -38,12 +39,19 @@ import java.util.logging.Logger;
* @author Eric Tobias [eric.tobias@list.lu] * @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0 * @since 1.0
* @version 1.3.0 * @version 1.3.0
* @param <T>
*/ */
@NonNullByDefault @NonNullByDefault
public class NumericalVariable extends Variable { public class NumericalVariable extends Variable {
protected double value; protected double value;
protected double minValue;
protected double maxValue;
protected double scale;
private DecimalFormat format; private DecimalFormat format;
private static final Logger logger = LoggerFactory.getLogger(NumericalVariable.class.getSimpleName());
/** /**
* Constructor resorting to the super constructor to initialise the name and unit and locally * Constructor resorting to the super constructor to initialise the name and unit and locally
* initialising the numerical value. * initialising the numerical value.
...@@ -55,13 +63,17 @@ public class NumericalVariable extends Variable { ...@@ -55,13 +63,17 @@ public class NumericalVariable extends Variable {
* @param value * @param value
* The value held by the variable. * The value held by the variable.
*/ */
public NumericalVariable(String name, String unit, double value) { public NumericalVariable(String name, String unit, Double value) {
super(name, unit); super(Externalization.NUMERIC_TYPE, name, unit);
this.value = value; this.value = value;
format = new DecimalFormat(); format = new DecimalFormat();
format.setDecimalSeparatorAlwaysShown(false); format.setDecimalSeparatorAlwaysShown(false);
format.setGroupingUsed(false); format.setGroupingUsed(false);
minValue = Double.MIN_VALUE;
maxValue = Double.MAX_VALUE;
scale = 1;
} }
/** /**
...@@ -73,7 +85,7 @@ public class NumericalVariable extends Variable { ...@@ -73,7 +85,7 @@ public class NumericalVariable extends Variable {
* necessary information to initialize the variable. * necessary information to initialize the variable.
*/ */
public NumericalVariable(Element rootElement) { public NumericalVariable(Element rootElement) {