Search in sources :

Example 1 with ListShort

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

the class SimpleValueFormat method format.

/**
 * Formats a numeric array. This method can be overridden to change
 * the way numeric arrays are formatted.
 *
 * @param array the array to format
 * @param toAppendTo the buffer to append to
 * @param pos the position of the field
 * @return  the string buffer
 */
protected StringBuffer format(VNumberArray array, StringBuffer toAppendTo, FieldPosition pos) {
    NumberFormat f = nf(array);
    toAppendTo.append("[");
    boolean hasMore = false;
    ListNumber data = array.getData();
    if (data.size() > maxElements) {
        hasMore = true;
    }
    for (int i = 0; i < Math.min(data.size(), maxElements); i++) {
        if (i != 0) {
            toAppendTo.append(", ");
        }
        if (data instanceof ListByte || data instanceof ListShort || data instanceof ListInt || data instanceof ListLong) {
            toAppendTo.append(f.format(data.getLong(i)));
        } else {
            toAppendTo.append(f.format(data.getDouble(i)));
        }
    }
    if (hasMore) {
        toAppendTo.append(", ...");
    }
    toAppendTo.append("]");
    return toAppendTo;
}
Also used : ListNumber(org.diirt.util.array.ListNumber) ListByte(org.diirt.util.array.ListByte) ListInt(org.diirt.util.array.ListInt) ListLong(org.diirt.util.array.ListLong) ListShort(org.diirt.util.array.ListShort) NumberFormat(java.text.NumberFormat)

Aggregations

NumberFormat (java.text.NumberFormat)1 ListByte (org.diirt.util.array.ListByte)1 ListInt (org.diirt.util.array.ListInt)1 ListLong (org.diirt.util.array.ListLong)1 ListNumber (org.diirt.util.array.ListNumber)1 ListShort (org.diirt.util.array.ListShort)1