use of org.openmuc.framework.lib.rest.objects.RestValue in project OpenMUC by isc-konstanz.
the class FromJson method convertValue.
public static Value convertValue(Object value, ValueType type) throws ClassCastException {
if (value.getClass().isInstance(new RestValue())) {
value = ((RestValue) value).getValue();
}
switch(type) {
case FLOAT:
return new FloatValue(((Double) value).floatValue());
case DOUBLE:
return new DoubleValue((Double) value);
case SHORT:
return new ShortValue(((Double) value).shortValue());
case INTEGER:
return new IntValue(((Double) value).intValue());
case LONG:
return new LongValue(((Double) value).longValue());
case BYTE:
return new ByteValue(((Double) value).byteValue());
case BOOLEAN:
return new BooleanValue((Boolean) value);
case BYTE_ARRAY:
@SuppressWarnings("unchecked") List<Double> arrayList = ((ArrayList<Double>) value);
byte[] byteArray = new byte[arrayList.size()];
for (int i = 0; i < arrayList.size(); ++i) {
byteArray[i] = arrayList.get(i).byteValue();
}
return new ByteArrayValue(byteArray);
case STRING:
return new StringValue((String) value);
default:
// should not occur
return new StringValue(value.toString());
}
}
Aggregations