Search in sources :

Example 11 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class VirtualPointLocatorVO method createRuntime.

@Override
public PointLocatorRT<VirtualPointLocatorVO> createRuntime() {
    ChangeTypeRT changeType = getChangeType().createRuntime();
    String startValue = getChangeType().getStartValue();
    DataValue startObject;
    if (dataTypeId == DataTypes.BINARY)
        startObject = BinaryValue.parseBinary(startValue);
    else if (dataTypeId == DataTypes.MULTISTATE) {
        try {
            startObject = MultistateValue.parseMultistate(startValue);
        } catch (NumberFormatException e) {
            startObject = new MultistateValue(0);
        }
    } else if (dataTypeId == DataTypes.NUMERIC) {
        try {
            startObject = NumericValue.parseNumeric(startValue);
        } catch (NumberFormatException e) {
            startObject = new NumericValue(0);
        }
    } else {
        if (startValue == null)
            startObject = new AlphanumericValue("");
        else
            startObject = new AlphanumericValue(startValue);
    }
    return new VirtualPointLocatorRT(this, changeType, startObject, isSettable());
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) VirtualPointLocatorRT(com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT) ChangeTypeRT(com.serotonin.m2m2.virtual.rt.ChangeTypeRT) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 12 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-core-public by infiniteautomation.

the class PointValueDaoSQL method createDataValue.

DataValue createDataValue(ResultSet rs, int firstParameter) throws SQLException {
    int dataType = rs.getInt(firstParameter);
    DataValue value;
    switch(dataType) {
        case (DataTypes.NUMERIC):
            value = new NumericValue(rs.getDouble(firstParameter + 1));
            break;
        case (DataTypes.BINARY):
            value = new BinaryValue(rs.getDouble(firstParameter + 1) == 1);
            break;
        case (DataTypes.MULTISTATE):
            value = new MultistateValue(rs.getInt(firstParameter + 1));
            break;
        case (DataTypes.ALPHANUMERIC):
            String s = rs.getString(firstParameter + 2);
            if (s == null)
                s = rs.getString(firstParameter + 3);
            value = new AlphanumericValue(s);
            break;
        case (DataTypes.IMAGE):
            value = new ImageValue(Integer.parseInt(rs.getString(firstParameter + 2)), rs.getInt(firstParameter + 1));
            break;
        default:
            value = null;
    }
    return value;
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 13 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-core-public by infiniteautomation.

the class ValueChangeCounterTest method main.

public static void main(String[] args) {
    AlphanumericValue startValue = new AlphanumericValue("asdf");
    List<PointValueTime> values = new ArrayList<PointValueTime>();
    values.add(new PointValueTime("asdf", 2000));
    values.add(new PointValueTime("zxcv", 3000));
    values.add(new PointValueTime("qwer", 4000));
    values.add(new PointValueTime("wert", 5000));
    values.add(new PointValueTime("wert", 6000));
    values.add(new PointValueTime("erty", 8000));
    validate(new ValueChangeCounter(0, 10000, startValue, values), 6, 4);
    validate(new ValueChangeCounter(0, 10000, startValue, values), 6, 4);
    validate(new ValueChangeCounter(0, 10000, (DataValue) null, values), 6, 5);
    validate(new ValueChangeCounter(0, 10000, (DataValue) null, values), 6, 5);
    validate(new ValueChangeCounter(0, 10000, (DataValue) null, new ArrayList<PointValueTime>()), 0, 0);
    validate(new ValueChangeCounter(0, 10000, startValue, new ArrayList<PointValueTime>()), 0, 0);
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Example 14 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-core-public by infiniteautomation.

the class ScriptUtils method coerce.

/**
 * Coerce an object into a DataValue
 * @param input
 * @param toDataTypeId
 * @return
 * @throws ResultTypeException
 */
public static DataValue coerce(Object input, int toDataTypeId) throws ResultTypeException {
    DataValue value;
    if (input instanceof DataValue)
        return (DataValue) input;
    if (input == null) {
        if (toDataTypeId == DataTypes.BINARY)
            value = new BinaryValue(false);
        else if (toDataTypeId == DataTypes.MULTISTATE)
            value = new MultistateValue(0);
        else if (toDataTypeId == DataTypes.NUMERIC)
            value = new NumericValue(0);
        else if (toDataTypeId == DataTypes.ALPHANUMERIC)
            value = new AlphanumericValue("");
        else
            value = null;
    } else if (input instanceof AbstractPointWrapper) {
        value = ((AbstractPointWrapper) input).getValueImpl();
        if ((value != null) && (value.getDataType() != toDataTypeId))
            return throwResultTypeException(value, toDataTypeId);
    } else // See if the type matches.
    if (toDataTypeId == DataTypes.BINARY && input instanceof Boolean)
        value = new BinaryValue((Boolean) input);
    else if (toDataTypeId == DataTypes.MULTISTATE) {
        if (input instanceof Number)
            value = new MultistateValue(((Number) input).intValue());
        else if (input instanceof String) {
            try {
                value = new MultistateValue(Integer.parseInt((String) input));
            } catch (NumberFormatException e) {
                return throwResultTypeException(input, toDataTypeId);
            }
        } else
            return throwResultTypeException(input, toDataTypeId);
    } else if (toDataTypeId == DataTypes.NUMERIC) {
        if (input instanceof Number)
            value = new NumericValue(((Number) input).doubleValue());
        else if (input instanceof NumericValue)
            value = (NumericValue) input;
        else if (input instanceof String) {
            try {
                value = new NumericValue(Double.parseDouble((String) input));
            } catch (NumberFormatException e) {
                return throwResultTypeException(input, toDataTypeId);
            }
        } else
            return throwResultTypeException(input, toDataTypeId);
    } else if (toDataTypeId == DataTypes.ALPHANUMERIC)
        value = new AlphanumericValue(input.toString());
    else
        // If not, ditch it.
        return throwResultTypeException(input, toDataTypeId);
    return value;
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Aggregations

AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)14 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)11 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)7 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)7 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)6 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)3 IOException (java.io.IOException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 ImageSaveException (com.serotonin.m2m2.ImageSaveException)1 EnhancedPointValueDao (com.serotonin.m2m2.db.dao.EnhancedPointValueDao)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 ChangeTypeRT (com.serotonin.m2m2.virtual.rt.ChangeTypeRT)1 VirtualPointLocatorRT (com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1