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