Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/lttng
diff options
context:
space:
mode:
authorPatrick Tasse2015-01-21 22:28:39 +0000
committerPatrick Tasse2015-01-27 18:06:56 +0000
commitd36de10dd8f3c70d128dcb5f96a5dac40464d060 (patch)
tree8254fde05f77fea9a160f8b34afd758d97ef0ac1 /lttng
parent2dfe9a9f693dbb67f0b240579c4554e7d5a498d3 (diff)
downloadorg.eclipse.linuxtools-d36de10dd8f3c70d128dcb5f96a5dac40464d060.tar.gz
org.eclipse.linuxtools-d36de10dd8f3c70d128dcb5f96a5dac40464d060.tar.xz
org.eclipse.linuxtools-d36de10dd8f3c70d128dcb5f96a5dac40464d060.zip
tmf: Bug 458085: Incorrect parsing of timestamps in TmfFilterCompareNode
Change-Id: I1a5902c7928e477ee7ed155262cd4cbd3d6930cf Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/40081 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Diffstat (limited to 'lttng')
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java43
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java2
2 files changed, 22 insertions, 23 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java
index 5561e1462a..45f4f1d6a4 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java
@@ -18,7 +18,9 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
/**
* Filter node for the comparison operation
@@ -51,7 +53,8 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
private Type fType = Type.NUM;
private String fValue;
private transient Number fValueNumber;
- private transient TmfTimestamp fValueTimestamp;
+ private transient ITmfTimestamp fValueTimestamp;
+ private transient TmfTimestampFormat fTimestampFormat = new TmfTimestampFormat("T.SSSSSSSSS"); //$NON-NLS-1$
/**
* @param parent the parent node
@@ -89,17 +92,17 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
}
/**
- * @return the compare result
+ * @return the compare result (-1, 0 or 1)
*/
public int getResult() {
return fResult;
}
/**
- * @param result the compare result
+ * @param result the compare result (-1, 0 or 1)
*/
public void setResult(int result) {
- this.fResult = result;
+ this.fResult = (int) Math.signum(result);
}
/**
@@ -118,14 +121,14 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
}
/**
- * @return the comparison value
+ * @return the comparison value (in seconds for the TIMESTAMP type)
*/
public String getValue() {
return fValue;
}
/**
- * @param value the comparison value
+ * @param value the comparison value (in seconds for the TIMESTAMP type)
*/
public void setValue(String value) {
this.fValue = value;
@@ -141,7 +144,7 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
}
} else if (fType == Type.TIMESTAMP) {
try {
- fValueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat.getInstance().parse(value.toString()).doubleValue()));
+ fValueTimestamp = new TmfNanoTimestamp(fTimestampFormat.parseValue(value.toString()));
} catch (ParseException e) {
}
}
@@ -156,7 +159,7 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
public boolean matches(ITmfEvent event) {
Object value = getFieldValue(event, fField);
if (value == null) {
- return false ^ fNot;
+ return false;
}
if (fType == Type.NUM) {
if (fValueNumber != null) {
@@ -172,28 +175,24 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
}
} else if (fType == Type.ALPHA) {
String valueString = value.toString();
- int comp = valueString.compareTo(fValue.toString());
- if (comp < -1) {
- comp = -1;
- } else if (comp > 1) {
- comp = 1;
- }
+ int comp = (int) Math.signum(valueString.compareTo(fValue.toString()));
return (comp == fResult) ^ fNot;
} else if (fType == Type.TIMESTAMP) {
if (fValueTimestamp != null) {
- if (value instanceof TmfTimestamp) {
- TmfTimestamp valueTimestamp = (TmfTimestamp) value;
- return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;
+ if (value instanceof ITmfTimestamp) {
+ ITmfTimestamp valueTimestamp = (ITmfTimestamp) value;
+ int comp = (int) Math.signum(valueTimestamp.compareTo(fValueTimestamp, false));
+ return (comp == fResult) ^ fNot;
}
try {
- TmfTimestamp valueTimestamp = new TmfTimestamp((long) (1E9 * NumberFormat
- .getInstance().parse(value.toString()).doubleValue()));
- return (valueTimestamp.compareTo(fValueTimestamp, false) == fResult) ^ fNot;
+ ITmfTimestamp valueTimestamp = new TmfNanoTimestamp(fTimestampFormat.parseValue(value.toString()));
+ int comp = (int) Math.signum(valueTimestamp.compareTo(fValueTimestamp, false));
+ return (comp == fResult) ^ fNot;
} catch (ParseException e) {
}
}
}
- return false ^ fNot;
+ return false;
}
@Override
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java
index f2703e6597..3e96d3b13f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java
@@ -141,7 +141,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable
value = event.getType().getName();
}
else if (ITmfEvent.EVENT_FIELD_TIMESTAMP.equals(field)) {
- value = event.getTimestamp().toString();
+ value = event.getTimestamp();
}
else if (ITmfEvent.EVENT_FIELD_SOURCE.equals(field)) {
value = event.getSource();

Back to the top