diff options
author | Geneviève Bastien | 2013-06-27 15:47:17 +0000 |
---|---|---|
committer | Genevieve Bastien | 2013-07-12 18:02:26 +0000 |
commit | 90bb242d92d45bf8a669a97a638f4e3f2dbee3ab (patch) | |
tree | 1fc6b3558f1deeee7c588bc6e3af6bc55a179721 | |
parent | 9a81de068037e28095e7edfe1ff29422aa24cfe3 (diff) | |
download | org.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.tar.gz org.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.tar.xz org.eclipse.linuxtools-90bb242d92d45bf8a669a97a638f4e3f2dbee3ab.zip |
tmf: Add getSubField() method to ITmfEventField
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>
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 1b6cb64061..5278a3978b 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 ae2176e77d..f8fcb6a65f 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 14f13e8b92..4123369cc0 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 // ------------------------------------------------------------------------ |