Search in sources :

Example 6 with ListDouble

use of org.diirt.util.array.ListDouble in project yamcs-studio by yamcs.

the class ValueFactory method wrapValue.

/**
 * Takes a java objects and wraps it into a vType. All numbers are wrapped
 * as VDouble. String is wrapped as VString. double[] and ListDouble are wrapped as
 * VDoubleArray. A List of String is wrapped to a VStringArray. Alarms
 * are alarm, time are timeNow() and display are displayNone();
 *
 * @param value the value to wrap
 * @param alarm the alarm for the value
 * @return the wrapped value
 * @deprecated use {@link #toVType(java.lang.Object, org.diirt.vtype.Alarm, org.diirt.vtype.Time, org.diirt.vtype.Display) }
 */
@Deprecated
public static VType wrapValue(Object value, Alarm alarm) {
    if (value instanceof Number) {
        // Special support for numbers
        return newVDouble(((Number) value).doubleValue(), alarm, timeNow(), displayNone());
    } else if (value instanceof String) {
        // Special support for strings
        return newVString(((String) value), alarm, timeNow());
    } else if (value instanceof double[]) {
        return newVDoubleArray(new ArrayDouble((double[]) value), alarm, timeNow(), displayNone());
    } else if (value instanceof ListDouble) {
        return newVDoubleArray((ListDouble) value, alarm, timeNow(), displayNone());
    } else if (value instanceof List) {
        boolean matches = true;
        List list = (List) value;
        for (Object object : list) {
            if (!(object instanceof String)) {
                matches = false;
            }
        }
        if (matches) {
            @SuppressWarnings("unchecked") List<String> newList = (List<String>) list;
            return newVStringArray(Collections.unmodifiableList(newList), alarm, timeNow());
        } else {
            throw new UnsupportedOperationException("Type " + value.getClass().getName() + " contains non Strings");
        }
    } else {
        // TODO: need to implement all the other arrays
        throw new UnsupportedOperationException("Type " + value.getClass().getName() + "  is not yet supported");
    }
}
Also used : ListNumber(org.diirt.util.array.ListNumber) ArrayDouble(org.diirt.util.array.ArrayDouble) ListDouble(org.diirt.util.array.ListDouble) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with ListDouble

use of org.diirt.util.array.ListDouble in project yamcs-studio by yamcs.

the class ColumnOfVTableFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VTable table = (VTable) args.get(0);
    VString columnName = (VString) args.get(1);
    if (columnName == null || table == null) {
        return null;
    }
    int index = -1;
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (Objects.equals(columnName.getValue(), table.getColumnName(i))) {
            index = i;
        }
    }
    if (index == -1) {
        throw new RuntimeException("Table does not contain column '" + columnName.getValue() + "'");
    }
    Class<?> type = table.getColumnType(index);
    if (String.class.isAssignableFrom(type)) {
        @SuppressWarnings("unchecked") List<String> data = (List<String>) table.getColumnData(index);
        return ValueFactory.newVStringArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow());
    }
    if (Double.TYPE.isAssignableFrom(type)) {
        ListDouble data = (ListDouble) table.getColumnData(index);
        return ValueFactory.newVDoubleArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), ValueFactory.displayNone());
    }
    if (Integer.TYPE.isAssignableFrom(type)) {
        ListInt data = (ListInt) table.getColumnData(index);
        return ValueFactory.newVIntArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), ValueFactory.displayNone());
    }
    throw new RuntimeException("Unsupported type " + type.getSimpleName());
}
Also used : ListInt(org.diirt.util.array.ListInt) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable) List(java.util.List) ListDouble(org.diirt.util.array.ListDouble) VString(org.diirt.vtype.VString)

Aggregations

ListDouble (org.diirt.util.array.ListDouble)7 ListNumber (org.diirt.util.array.ListNumber)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 VNumber (org.diirt.vtype.VNumber)3 ArrayDouble (org.diirt.util.array.ArrayDouble)2 Display (org.diirt.vtype.Display)2 VNumberArray (org.diirt.vtype.VNumberArray)2 VTable (org.diirt.vtype.VTable)2 Statistics (org.diirt.util.Statistics)1 ListInt (org.diirt.util.array.ListInt)1 VString (org.diirt.vtype.VString)1 ValueFactory.newDisplay (org.diirt.vtype.ValueFactory.newDisplay)1