tmf: Add a getSubAttributes() with regex to the state system
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 4 Mar 2014 21:28:42 +0000 (16:28 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 4 Mar 2014 22:16:07 +0000 (17:16 -0500)
This allows a bit more fine-grained control than getQuarks("*").

Change-Id: Ia925e98a15748eb67f7792108063c649d392e4d2
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/22885
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java

index 19644c7f7579a9fddb39c312ab3b0b6e8c13e20a..981467fe23563d416e58e069930f49d513fe591d 100644 (file)
@@ -263,6 +263,20 @@ public class StateSystem implements ITmfStateSystemBuilder {
         return getAttributeTree().getSubAttributes(quark, recursive);
     }
 
+    @Override
+    public List<Integer> getSubAttributes(int quark, boolean recursive, String pattern)
+            throws AttributeNotFoundException {
+        List<Integer> all = getSubAttributes(quark, recursive);
+        List<Integer> ret = new LinkedList<>();
+        for (Integer attQuark : all) {
+            String name = getAttributeName(attQuark.intValue());
+            if (name.matches(pattern)) {
+                ret.add(attQuark);
+            }
+        }
+        return ret;
+    }
+
     @Override
     public List<Integer> getQuarks(String... pattern) {
         List<Integer> quarks = new LinkedList<>();
index c0297ca338f65b3d895c98a450f59b552918fe36..4682c15fd4766b4597bc2fcc27143a69dfb61571 100644 (file)
@@ -178,6 +178,30 @@ public interface ITmfStateSystem {
     List<Integer> getSubAttributes(int quark, boolean recursive)
             throws AttributeNotFoundException;
 
+    /**
+     * Return the sub-attributes of the target attribute, as a List of quarks,
+     * similarly to {@link #getSubAttributes(int, boolean)}, but with an added
+     * regex pattern to filter on the return attributes.
+     *
+     * @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. Note that the returned value will
+     *            be flattened.
+     * @param pattern
+     *            The regular expression to match the attribute base name.
+     * @return A List of integers, matching the quarks of the sub-attributes
+     *         that match the regex. An empty list is returned if there is no
+     *         matching attribute.
+     * @throws AttributeNotFoundException
+     *             If the 'quark' was not existing or invalid.
+     * @since 3.0
+     */
+    List<Integer> getSubAttributes(int quark, boolean recursive, String pattern)
+            throws AttributeNotFoundException;
+
     /**
      * Batch quark-retrieving method. This method allows you to specify a path
      * pattern which includes a wildcard "*" somewhere. It will check all the
This page took 0.028292 seconds and 5 git commands to generate.