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

Numerous fixes and improvements to handling of complex variable types

such as Vectors and Maps
parent b8827db6
...@@ -521,6 +521,17 @@ public class SqlExecutor extends Executor { ...@@ -521,6 +521,17 @@ public class SqlExecutor extends Executor {
variable.setValueFromObject(values[index]); variable.setValueFromObject(values[index]);
} else { } else {
LOGGER.info("Query returned no results!"); //$NON-NLS-1$ LOGGER.info("Query returned no results!"); //$NON-NLS-1$
if (variable instanceof VectorVariable) {
VectorVariable<?> vector = (VectorVariable<?>) variable;
vector.clear();
vector.notifyInputChangeListeners();
} else if (variable instanceof MapVariable) {
MapVariable<?, ?> map = (MapVariable<?, ?>) variable;
map.clear();
map.notifyInputChangeListeners();
} else {
variable.setValue(null);
}
} }
} }
} }
......
...@@ -168,7 +168,12 @@ public class MapVariable<K, V> extends Variable<Map<K, V>> implements Map<K, V> ...@@ -168,7 +168,12 @@ public class MapVariable<K, V> extends Variable<Map<K, V>> implements Map<K, V>
@Override @Override
public void setValueFromObject(Object object) { public void setValueFromObject(Object object) {
this.value = this.valueFromObject(object); if (this.value != null) {
this.value.clear();
} else {
this.value = new ConcurrentHashMap<K, V>();
}
this.value.putAll(this.valueFromObject(object));
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -186,6 +191,21 @@ public class MapVariable<K, V> extends Variable<Map<K, V>> implements Map<K, V> ...@@ -186,6 +191,21 @@ public class MapVariable<K, V> extends Variable<Map<K, V>> implements Map<K, V>
/** {@inheritDoc} */ /** {@inheritDoc} */
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder renderer = new StringBuilder(name);
if (value != null) {
renderer.append(value);
} else {
renderer.append("null"); //$NON-NLS-1$
}
return renderer.toString();
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override @Override
public Map<K, V> valueFromString(String stringValue) { public Map<K, V> valueFromString(String stringValue) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
......
...@@ -451,10 +451,13 @@ public class NumericalVariable extends Variable<Double> { ...@@ -451,10 +451,13 @@ public class NumericalVariable extends Variable<Double> {
@Override @Override
public NumericalVariable clone() { public NumericalVariable clone() {
NumericalVariable variable = new NumericalVariable(name, unit, value); NumericalVariable variable = new NumericalVariable(name, unit, value);
variable.displayName = displayName;
variable.format = format; variable.format = format;
variable.minValue = minValue; variable.minValue = minValue;
variable.maxValue = maxValue; variable.maxValue = maxValue;
variable.scale = scale; variable.scale = scale;
variable.roundingFactor = roundingFactor;
variable.epsilon = epsilon;
variable.listeners = new Vector<>(listeners); variable.listeners = new Vector<>(listeners);
return variable; return variable;
} }
......
...@@ -361,7 +361,9 @@ public abstract class Variable<V> implements Cloneable { ...@@ -361,7 +361,9 @@ public abstract class Variable<V> implements Cloneable {
public HashMap<InputChangeListener, Variable<?>> consolidateListeners(HashMap<InputChangeListener, Variable<?>> consolidated) { public HashMap<InputChangeListener, Variable<?>> consolidateListeners(HashMap<InputChangeListener, Variable<?>> consolidated) {
for (InputChangeListener listener : listeners) { for (InputChangeListener listener : listeners) {
consolidated.put(listener, this); if (!consolidated.containsKey(listener)) {
consolidated.put(listener, this);
}
} }
return consolidated; return consolidated;
} }
......
...@@ -274,8 +274,9 @@ public class VectorVariable<B> extends Variable<List<B>> implements List<B> { ...@@ -274,8 +274,9 @@ public class VectorVariable<B> extends Variable<List<B>> implements List<B> {
if (objectValue instanceof List) { if (objectValue instanceof List) {
return (List<B>) objectValue; return (List<B>) objectValue;
} }
List<B> list = new ArrayList<>();
return new ArrayList<>(); list.add((B) objectValue);
return list;
} }
......
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