Search in sources :

Example 6 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class LastValuesComparator method compareValue.

/**
 * Compare DCI values taking data type into consideration
 *
 * @param v1
 * @param v2
 * @return
 */
private int compareValue(DciValue dci1, DciValue dci2) {
    DataType dt1, dt2;
    String v1, v2;
    if (showErrors && (dci1.getErrorCount() > 0)) {
        dt1 = DataType.STRING;
        v1 = Messages.get().LastValuesLabelProvider_Error;
    } else if (dci1.getDcObjectType() == DataCollectionObject.DCO_TYPE_TABLE) {
        dt1 = DataType.STRING;
        v1 = Messages.get().LastValuesLabelProvider_Table;
    } else {
        dt1 = dci1.getDataType();
        v1 = dci1.getValue();
    }
    if (showErrors && (dci2.getErrorCount() > 0)) {
        dt2 = DataType.STRING;
        v2 = Messages.get().LastValuesLabelProvider_Error;
    } else if (dci2.getDcObjectType() == DataCollectionObject.DCO_TYPE_TABLE) {
        dt2 = DataType.STRING;
        v2 = Messages.get().LastValuesLabelProvider_Table;
    } else {
        dt2 = dci2.getDataType();
        v2 = dci2.getValue();
    }
    DataType dataType = DataType.getTypeForCompare(dt1, dt2);
    try {
        switch(dataType) {
            case INT32:
                return Integer.signum(Integer.parseInt(v1) - Integer.parseInt(v2));
            case UINT32:
            case INT64:
            case UINT64:
            case COUNTER32:
            case COUNTER64:
                return Long.signum(Long.parseLong(v1) - Long.parseLong(v2));
            case FLOAT:
                return (int) Math.signum(Double.parseDouble(v1) - Double.parseDouble(v2));
            default:
                return v1.compareToIgnoreCase(v2);
        }
    } catch (NumberFormatException e) {
        return v1.compareToIgnoreCase(v2);
    }
}
Also used : DataType(org.netxms.client.constants.DataType)

Aggregations

DataType (org.netxms.client.constants.DataType)6 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1