/**
* Sends a new value for the given paintables given variable to the server.
- * <p>
+ *
* The update is actually queued to be sent at a suitable time. If immediate
* is true, the update is sent as soon as possible. If immediate is false,
* the update will be sent along with the next immediate update.
- * </p>
+ *
+ * A null array is sent as an empty array.
*
* @param paintableId
* the id of the paintable that owns the variable
public void updateVariable(String paintableId, String variableName,
String[] values, boolean immediate) {
final StringBuffer buf = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- if (i > 0) {
- buf.append(VAR_ARRAYITEM_SEPARATOR);
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ if (i > 0) {
+ buf.append(VAR_ARRAYITEM_SEPARATOR);
+ }
+ buf.append(values[i]);
}
- buf.append(values[i]);
}
addVariableToQueue(paintableId, variableName, buf.toString(),
immediate, 'c');
/**
* Sends a new value for the given paintables given variable to the server.
- * <p>
+ *
* The update is actually queued to be sent at a suitable time. If immediate
* is true, the update is sent as soon as possible. If immediate is false,
- * the update will be sent along with the next immediate update.
- * </p>
+ * the update will be sent along with the next immediate update. </p>
+ *
+ * A null array is sent as an empty array.
+ *
*
* @param paintableId
* the id of the paintable that owns the variable
public void updateVariable(String paintableId, String variableName,
Object[] values, boolean immediate) {
final StringBuffer buf = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- if (i > 0) {
- buf.append(VAR_ARRAYITEM_SEPARATOR);
- }
- Object value = values[i];
- char transportType = getTransportType(value);
- // first char tells the type in array
- buf.append(transportType);
- if (transportType == 'p') {
- buf.append(getPid((Paintable) value));
- } else {
- buf.append(value);
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ if (i > 0) {
+ buf.append(VAR_ARRAYITEM_SEPARATOR);
+ }
+ Object value = values[i];
+ char transportType = getTransportType(value);
+ // first char tells the type in array
+ buf.append(transportType);
+ if (transportType == 'p') {
+ buf.append(getPid((Paintable) value));
+ } else {
+ buf.append(value);
+ }
}
}
addVariableToQueue(paintableId, variableName, buf.toString(),
HashMap<String, Object> map = new HashMap<String, Object>();
for (int i = 0; i < parts.length; i += 2) {
String key = parts[i];
- char variabletype = key.charAt(0);
- Object value = convertVariableValue(variabletype, parts[i + 1]);
- map.put(key.substring(1), value);
+ if (key.length() > 0) {
+ char variabletype = key.charAt(0);
+ Object value = convertVariableValue(variabletype, parts[i + 1]);
+ map.put(key.substring(1), value);
+ }
}
return map;
}
private Object convertArray(String strValue) {
String[] val = strValue.split(VAR_ARRAYITEM_SEPARATOR);
+ if (val.length == 0 || (val.length == 1 && val[0].length() == 0)) {
+ return new Object[0];
+ }
Object[] values = new Object[val.length];
for (int i = 0; i < values.length; i++) {
String string = val[i];
- // first char of string is typ
+ // first char of string is type
char variableType = string.charAt(0);
values[i] = convertVariableValue(variableType, string.substring(1));
}