From b3a1756d657675294e3e1eb4c0c458237f73271a Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 20 Mar 2012 13:00:34 -0400 Subject: Expose the getSubAttributes() method through the StateSystem Signed-off-by: Alexandre Montplaisir --- .../tmf/core/statesystem/AttributeTree.java | 33 ++++++++++++++++++---- .../tmf/core/statesystem/StateSystem.java | 15 ++++++++++ 2 files changed, 43 insertions(+), 5 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 7cbb7a0797..baa45280b5 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 @@ -64,7 +64,7 @@ final class AttributeTree { /* Message for exceptions, shouldn't be externalized */ final String errorMessage = "The attribute tree file section is either invalid or corrupted."; //$NON-NLS-1$ - + ArrayList list = new ArrayList(); byte[] curByteArray; String curFullString; @@ -281,12 +281,35 @@ final class AttributeTree { return attributeList.get(quark).getSubAttributesList().size(); } - ArrayList getSubAttributes(int attributeQuark) { - ArrayList listOfChildren = new ArrayList(); - - for (Attribute childNode : attributeList.get(attributeQuark).getSubAttributesList()) { + /** + * Returns the sub-attributes of the quark passed in parameter + * + * @param attributeQuark + * @return + * @throws AttributeNotFoundException + */ + List getSubAttributes(int attributeQuark) + throws AttributeNotFoundException { + List listOfChildren = new ArrayList(); + Attribute startingAttribute; + + /* Check if the quark is valid */ + if ( attributeQuark < 0 || attributeQuark >= attributeList.size()) { + throw new AttributeNotFoundException(); + } + + /* Set up the node from which we'll start the search */ + 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()); } + return listOfChildren; } 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 0d24cb7631..5608e34437 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 @@ -135,6 +135,21 @@ public class StateSystem { return attributeTree.getQuarkAndAdd(startingNodeQuark, subPath); } + /** + * Return the sub-attributes of the target attribute, as a List of quarks. + * + * @param quark + * The attribute of which you want to sub-attributes. You can use + * "-1" here to specify the root node. + * @return A List of integers, matching the quarks of the sub-attributes. + * @throws AttributeNotFoundException + * If the quark was not existing or invalid. + */ + public List getSubAttributes(int quark) + throws AttributeNotFoundException { + return attributeTree.getSubAttributes(quark); + } + /** * @name External methods related to insertions in the history - */ -- cgit v1.2.3