Search in sources :

Example 1 with RestValue

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());
    }
}
Also used : ByteValue(org.openmuc.framework.data.ByteValue) ShortValue(org.openmuc.framework.data.ShortValue) DoubleValue(org.openmuc.framework.data.DoubleValue) RestValue(org.openmuc.framework.lib.rest.objects.RestValue) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) FloatValue(org.openmuc.framework.data.FloatValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) StringValue(org.openmuc.framework.data.StringValue) IntValue(org.openmuc.framework.data.IntValue)

Aggregations

BooleanValue (org.openmuc.framework.data.BooleanValue)1 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)1 ByteValue (org.openmuc.framework.data.ByteValue)1 DoubleValue (org.openmuc.framework.data.DoubleValue)1 FloatValue (org.openmuc.framework.data.FloatValue)1 IntValue (org.openmuc.framework.data.IntValue)1 LongValue (org.openmuc.framework.data.LongValue)1 ShortValue (org.openmuc.framework.data.ShortValue)1 StringValue (org.openmuc.framework.data.StringValue)1 RestValue (org.openmuc.framework.lib.rest.objects.RestValue)1