import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
-
/**
* Filter node for the comparison operation
*
* @param result the compare result (-1, 0 or 1)
*/
public void setResult(int result) {
- this.fResult = result;
+ this.fResult = (int) Math.signum(result);
}
/**
return;
}
if (fType == Type.NUM) {
- try {
- fValueNumber = NumberFormat.getInstance().parse(value).doubleValue();
- } catch (ParseException e) {
- }
+ fValueNumber = toNumber(value);
} else if (fType == Type.TIMESTAMP) {
- try {
- fValueTimestamp = new TmfNanoTimestamp(fTimestampFormat.parseValue(value.toString()));
- } catch (ParseException e) {
- }
+ fValueTimestamp = toTimestamp(value);
}
}
@Override
public boolean matches(ITmfEvent event) {
if (event == null || fEventAspect == null) {
- return false ^ fNot;
+ return false;
}
Object value = fEventAspect.resolve(event);
if (value == null) {
- return false ^ fNot;
+ return false;
}
if (fType == Type.NUM) {
- if (fValueNumber != null) {
- if (value instanceof Number) {
- double valueDouble = ((Number) value).doubleValue();
- return (Double.compare(valueDouble, fValueNumber.doubleValue()) == fResult) ^ fNot;
+ if (fValueNumber instanceof Double) {
+ Number valueNumber = toNumber(value);
+ if (valueNumber != null) {
+ return (Double.compare(valueNumber.doubleValue(), fValueNumber.doubleValue()) == fResult) ^ fNot;
}
- try {
- double valueDouble = NumberFormat.getInstance().parse(value.toString()).doubleValue();
- return (Double.compare(valueDouble, fValueNumber.doubleValue()) == fResult) ^ fNot;
- } catch (ParseException e) {
+ } else if (fValueNumber != null) {
+ Number valueNumber = toNumber(value);
+ if (valueNumber instanceof Double || valueNumber instanceof Float) {
+ return (Double.compare(valueNumber.doubleValue(), fValueNumber.doubleValue()) == fResult) ^ fNot;
+ } else if (valueNumber != null) {
+ return (Long.compare(valueNumber.longValue(), fValueNumber.longValue()) == fResult) ^ fNot;
}
}
} else if (fType == Type.ALPHA) {
return (comp == fResult) ^ fNot;
} else if (fType == Type.TIMESTAMP) {
if (fValueTimestamp != null) {
- if (value instanceof ITmfTimestamp) {
- ITmfTimestamp valueTimestamp = (ITmfTimestamp) value;
- return (valueTimestamp.compareTo(fValueTimestamp) == fResult) ^ fNot;
- }
- try {
- ITmfTimestamp valueTimestamp = new TmfNanoTimestamp(fTimestampFormat.parseValue(value.toString()));
- return (valueTimestamp.compareTo(fValueTimestamp) == fResult) ^ fNot;
- } catch (ParseException e) {
+ ITmfTimestamp valueTimestamp = toTimestamp(value);
+ if (valueTimestamp != null) {
+ int comp = (int) Math.signum(valueTimestamp.compareTo(fValueTimestamp));
+ return (comp == fResult) ^ fNot;
}
}
}
- return false ^ fNot;
+ return false;
+ }
+
+ private static Number toNumber(Object value) {
+ if (value instanceof Number) {
+ return (Number) value;
+ }
+ try {
+ return Long.decode(value.toString());
+ } catch (NumberFormatException e) {
+ }
+ try {
+ return NumberFormat.getInstance().parse(value.toString());
+ } catch (ParseException e) {
+ }
+ return null;
+ }
+
+ private ITmfTimestamp toTimestamp(Object value) {
+ if (value instanceof ITmfTimestamp) {
+ return (ITmfTimestamp) value;
+ }
+ try {
+ return new TmfNanoTimestamp(fTimestampFormat.parseValue(value.toString()));
+ } catch (ParseException e) {
+ }
+ return null;
}
@Override
}
@Override
- public String toString() {
+ public String toString(boolean explicit) {
String result = (fResult == 0 ? "= " : fResult < 0 ? "< " : "> "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String open = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "["); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String close = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- String aspectName = fEventAspect != null ? fEventAspect.getName() : ""; //$NON-NLS-1$
- return aspectName + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$
+ return getAspectLabel(explicit) + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
clone.setValue(fValue);
return clone;
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + (fNot ? 1231 : 1237);
- result = prime * result + fResult;
- result = prime * result + ((fType == null) ? 0 : fType.hashCode());
- result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- TmfFilterCompareNode other = (TmfFilterCompareNode) obj;
- if (fNot != other.fNot) {
- return false;
- }
- if (fResult != other.fResult) {
- return false;
- }
- if (fType != other.fType) {
- return false;
- }
- if (fValue == null) {
- if (other.fValue != null) {
- return false;
- }
- } else if (!fValue.equals(other.fValue)) {
- return false;
- }
- return true;
- }
}