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");
}
}
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());
}
Aggregations