Commit 2b7a81bd authored by Nico Mack's avatar Nico Mack

Adaptations required by Messaging System in tulip-iot

parent 119f65ff
......@@ -78,17 +78,25 @@ public class Mapping {
String separator = ""; //$NON-NLS-1$
StringBuilder renderer = new StringBuilder();
for (Variable<?> variable : independentVariables) {
renderer.append(separator).append(variable.getName());
separator = ", "; //$NON-NLS-1$
if (independentVariables != null) {
for (Variable<?> variable : independentVariables) {
renderer.append(separator).append(variable.getName());
separator = ", "; //$NON-NLS-1$
}
} else {
renderer.append("n/a"); //$NON-NLS-1$
}
renderer.append(" => "); //$NON-NLS-1$
separator = ""; //$NON-NLS-1$
for (Variable<?> variable : dependentVariables) {
renderer.append(separator).append(variable.getName());
separator = ", "; //$NON-NLS-1$
if (dependentVariables != null) {
for (Variable<?> variable : dependentVariables) {
renderer.append(separator).append(variable.getName());
separator = ", "; //$NON-NLS-1$
}
} else {
renderer.append("n/a"); //$NON-NLS-1$
}
return renderer.toString();
......@@ -154,8 +162,10 @@ public class Mapping {
clonedIndependentVariables.add(variable.clone());
}
LinkedHashSet<Variable<?>> clonedDependentVariables = new LinkedHashSet<>();
for (Variable<?> variable : dependentVariables) {
clonedDependentVariables.add(variable.clone());
if (dependentVariables != null) {
for (Variable<?> variable : dependentVariables) {
clonedDependentVariables.add(variable.clone());
}
}
return new Mapping(clonedIndependentVariables, clonedDependentVariables);
......
......@@ -33,7 +33,9 @@ public class Interpolator {
// * Constants *
// ***************************************************************************
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([a-z0-9\\-_]+)(\\.(%[bhscxegat\\+\\.0-9]+))?\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([a-z0-9\\-_]+)(\\.(%[bhscxoegat\\+\\.0-9]+))?\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern INTEGER_FORMAT = Pattern.compile("\\%(\\d*(\\.\\d+)?)([xod])", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -67,7 +69,14 @@ public class Interpolator {
if ((variable != null) && (!variable.isEmpty())) {
if (parameters.containsKey(variable)) {
if (!format.isEmpty()) {
interpolated.append(String.format(format, parameters.get(variable)));
if (INTEGER_FORMAT.matcher(format).matches()) {
Object value = parameters.get(variable);
if (value instanceof Number) {
interpolated.append(String.format(format, ((Number) value).intValue()));
}
} else {
interpolated.append(String.format(format, parameters.get(variable)));
}
} else {
interpolated.append(parameters.get(variable));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment