]> source.dussan.org Git - sonarqube.git/commitdiff
add the methods Characteristic.getChildren(boolean onlyEnabled)
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 18 Oct 2010 14:20:25 +0000 (14:20 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 18 Oct 2010 14:20:25 +0000 (14:20 +0000)
sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java

index 27b6bce4402d560c76d248030fa97b8c9347e89e..f36a61c6c5268ce6156f4ae27fd89a0fc879f0aa 100644 (file)
@@ -115,6 +115,7 @@ public final class Characteristic implements Comparable<Characteristic> {
   public Characteristic setName(String s) {
     return setName(s, false);
   }
+
   public Characteristic setName(String s, boolean asKey) {
     this.name = StringUtils.trimToNull(s);
     if (asKey) {
@@ -138,7 +139,7 @@ public final class Characteristic implements Comparable<Characteristic> {
   }
 
   public boolean hasRule() {
-    return rule!=null;
+    return rule != null;
   }
 
   public Characteristic setRule(Rule r) {
@@ -205,10 +206,26 @@ public final class Characteristic implements Comparable<Characteristic> {
   }
 
   /**
-   * Children sorted by insertion order
+   * Enabled children sorted by insertion order
    */
   public List<Characteristic> getChildren() {
-    return children;
+    return getChildren(true);
+  }
+
+  /**
+   * Enabled children sorted by insertion order
+   */
+  public List<Characteristic> getChildren(boolean onlyEnabled) {
+    if (onlyEnabled) {
+      return children;
+    }
+    List<Characteristic> result = Lists.newArrayList();
+    for (Characteristic child : children) {
+      if (child.getEnabled()) {
+        result.add(child);
+      }
+    }
+    return result;
   }
 
   public Characteristic getChild(String name) {
@@ -283,7 +300,7 @@ public final class Characteristic implements Comparable<Characteristic> {
   public Double getPropertyValue(String key, Double defaultValue) {
     CharacteristicProperty property = getProperty(key);
     Double value = (property != null ? property.getValue() : null);
-    return value==null ? defaultValue : value;
+    return value == null ? defaultValue : value;
   }
 
   public List<CharacteristicProperty> getProperties() {