| author | Alexandre Montplaisir | 2012-03-20 14:30:06 (EDT) |
|---|---|---|
| committer | Francois Chouinard | 2012-03-27 13:52:21 (EDT) |
| commit | 7e5945e9f37805b4e29b8873a736564a3359e5ac (patch) (side-by-side diff) | |
| tree | fffec9e566bc6a9380cce4d1d4e05fb2e806ba6a | |
| parent | b3a1756d657675294e3e1eb4c0c458237f73271a (diff) | |
| download | org.eclipse.linuxtools-7e5945e9f37805b4e29b8873a736564a3359e5ac.zip org.eclipse.linuxtools-7e5945e9f37805b4e29b8873a736564a3359e5ac.tar.gz org.eclipse.linuxtools-7e5945e9f37805b4e29b8873a736564a3359e5ac.tar.bz2 | |
Add option to retrieve sub-attributes recursively
Signed-off-by: Alexandre Montplaisir <alexandre.montplaisir@polymtl.ca>
2 files changed, 30 insertions, 13 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AttributeTree.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AttributeTree.java index baa4528..9c5d8fc 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AttributeTree.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AttributeTree.java @@ -285,34 +285,43 @@ final class AttributeTree { * Returns the sub-attributes of the quark passed in parameter * * @param attributeQuark + * @param recursive * @return * @throws AttributeNotFoundException */ - List<Integer> getSubAttributes(int attributeQuark) + List<Integer> getSubAttributes(int attributeQuark, boolean recursive) throws AttributeNotFoundException { List<Integer> listOfChildren = new ArrayList<Integer>(); Attribute startingAttribute; - + /* Check if the quark is valid */ - if ( attributeQuark < 0 || attributeQuark >= attributeList.size()) { + if (attributeQuark < 0 || attributeQuark >= attributeList.size()) { throw new AttributeNotFoundException(); } - + /* Set up the node from which we'll start the search */ - if ( attributeQuark == -1 ) { + if (attributeQuark == -1) { startingAttribute = attributeTreeRoot; } else { startingAttribute = attributeList.get(attributeQuark); } - + /* Iterate through the sub-attributes and add them to the list */ - for (Attribute childNode : startingAttribute.getSubAttributesList()) { - listOfChildren.add(childNode.getQuark()); - } + addSubAttributes(listOfChildren, startingAttribute, recursive); return listOfChildren; } + private void addSubAttributes(List<Integer> list, Attribute curAttribute, + boolean recursive) { + for (Attribute childNode : curAttribute.getSubAttributesList()) { + list.add(childNode.getQuark()); + if (recursive) { + addSubAttributes(list, childNode, true); + } + } + } + String getFullAttributeName(int quark) { if (quark >= attributeList.size() || quark < 0) { return null; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystem.java index 5608e34..30edbb3 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystem.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystem.java @@ -141,13 +141,16 @@ public class StateSystem { * @param quark * The attribute of which you want to sub-attributes. You can use * "-1" here to specify the root node. + * @param recursive + * True if you want all recursive sub-attributes, false if you + * only want the first level. * @return A List of integers, matching the quarks of the sub-attributes. * @throws AttributeNotFoundException * If the quark was not existing or invalid. */ - public List<Integer> getSubAttributes(int quark) + public List<Integer> getSubAttributes(int quark, boolean recursive) throws AttributeNotFoundException { - return attributeTree.getSubAttributes(quark); + return attributeTree.getSubAttributes(quark, recursive); } /** @@ -337,8 +340,13 @@ public class StateSystem { public void removeAttribute(long t, int attributeQuark) throws TimeRangeException, AttributeNotFoundException { assert (attributeQuark >= 0); - /* "Nullify our children first, recursively */ - List<Integer> childAttributes = attributeTree.getSubAttributes(attributeQuark); + List<Integer> childAttributes; + + /* + * "Nullify our children first, recursively. We pass 'false' because we + * handle the recursion ourselves. + */ + childAttributes = attributeTree.getSubAttributes(attributeQuark, false); for (Integer childNodeQuark : childAttributes) { assert (attributeQuark != childNodeQuark); removeAttribute(t, childNodeQuark); |

