aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeneviève Bastien2013-06-27 11:47:17 (EDT)
committerGenevieve Bastien2013-07-12 14:02:26 (EDT)
commit90bb242d92d45bf8a669a97a638f4e3f2dbee3ab (patch)
tree1fc6b3558f1deeee7c588bc6e3af6bc55a179721
parent9a81de068037e28095e7edfe1ff29422aa24cfe3 (diff)
downloadorg.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.zip
org.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.tar.gz
org.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.tar.bz2
tmf: Add getSubField() method to ITmfEventFieldrefs/changes/81/14281/5
This function allows to directly get a subfield, recursively for struct and variant fields with many levels of embedded fields. Null is returned if any level of field is not available. Change-Id: I46691f62036f4e9826ee5f704efda74e71725acc Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/14281 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java20
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java11
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java15
3 files changed, 46 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java
index 1b6cb64..5278a39 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java
@@ -126,6 +126,26 @@ public class CtfTmfEventTest {
}
/**
+ * Run the ITmfEventField getSubFieldValue(String[]) method test.
+ */
+ @Test
+ public void testGetSubFieldValue() {
+ /* Field exists */
+ String[] names = { "pid" };
+ assertNotNull(fixture.getContent().getSubField(names));
+
+ /* First field exists, not the second */
+ String[] names2 = { "pid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names2));
+
+ /* Both field do not exist */
+ String[] names3 = { "pfid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names3));
+
+ /* TODO Missing case of embedded field, need event for it */
+ }
+
+ /**
* Run the long getID() method test.
*/
@Test
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java
index ae2176e..f8fcb6a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java
@@ -81,4 +81,15 @@ public interface ITmfEventField {
*/
ITmfEventField getField(int index);
+ /**
+ * Gets the a sub-field of this field, which may be multiple levels down.
+ *
+ * @param path
+ * Array of field names to recursively go through
+ * @return The field at the end, or null if a field in the path cannot be
+ * found
+ * @since 3.0
+ */
+ ITmfEventField getSubField(String[] path);
+
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java
index 14f13e8..4123369 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java
@@ -135,6 +135,21 @@ public class TmfEventField implements ITmfEventField {
return null;
}
+ /**
+ * @since 3.0
+ */
+ @Override
+ public ITmfEventField getSubField(final String[] names) {
+ ITmfEventField field = this;
+ for (String name : names) {
+ field = field.getField(name);
+ if (field == null) {
+ return null;
+ }
+ }
+ return field;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------