From: Simon Brandhof Date: Sun, 8 Jul 2012 20:46:49 +0000 (+0200) Subject: Fix some quality flaws X-Git-Tag: 3.2~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=22c56a89235eaa229af5d88e93bdbc26628a07ec;p=sonarqube.git Fix some quality flaws --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/ApplyProjectRolesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/ApplyProjectRolesDecorator.java index 4e6fc53d52b..332014b1bd0 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/ApplyProjectRolesDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/ApplyProjectRolesDecorator.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.DecoratorContext; import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceTypes; import org.sonar.api.security.ResourcePermissioning; import java.util.Set; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java index 5eb933c725b..4821187385f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java @@ -84,28 +84,56 @@ public final class ResourceTypes implements BatchComponent, ServerComponent { return Collections2.filter(typeByQualifier.values(), predicate); } + private static class PropertyKeyPredicate implements Predicate { + private final String propertyKey; + + public PropertyKeyPredicate(String propertyKey) { + this.propertyKey = propertyKey; + } + + public boolean apply(@Nullable ResourceType input) { + return input != null && input.hasProperty(propertyKey); + } + } + public Collection getAllWithPropertyKey(final String propertyKey) { - return Collections2.filter(typeByQualifier.values(), new Predicate() { - public boolean apply(@Nullable ResourceType input) { - return input != null && input.hasProperty(propertyKey); - } - }); + return Collections2.filter(typeByQualifier.values(), new PropertyKeyPredicate(propertyKey)); + } + + private static class StringPropertyValuePredicate implements Predicate { + private final String propertyValue; + private final String propertyKey; + + public StringPropertyValuePredicate(String propertyValue, String propertyKey) { + this.propertyValue = propertyValue; + this.propertyKey = propertyKey; + } + + public boolean apply(@Nullable ResourceType input) { + return input != null && Objects.equal(propertyValue, input.getStringProperty(propertyKey)); + } } public Collection getAllWithPropertyValue(final String propertyKey, final String propertyValue) { - return Collections2.filter(typeByQualifier.values(), new Predicate() { - public boolean apply(@Nullable ResourceType input) { - return input != null && Objects.equal(propertyValue, input.getStringProperty(propertyKey)); - } - }); + return Collections2.filter(typeByQualifier.values(), new StringPropertyValuePredicate(propertyValue, propertyKey)); + } + + private static class BooleanPropertyValuePredicate implements Predicate { + private final String propertyKey; + private final boolean propertyValue; + + public BooleanPropertyValuePredicate(String propertyKey, boolean propertyValue) { + this.propertyKey = propertyKey; + this.propertyValue = propertyValue; + } + + public boolean apply(@Nullable ResourceType input) { + return input != null && input.getBooleanProperty(propertyKey) == propertyValue; + } } public Collection getAllWithPropertyValue(final String propertyKey, final boolean propertyValue) { - return Collections2.filter(typeByQualifier.values(), new Predicate() { - public boolean apply(@Nullable ResourceType input) { - return input != null && input.getBooleanProperty(propertyKey) == propertyValue; - } - }); + return Collections2.filter(typeByQualifier.values(), new BooleanPropertyValuePredicate(propertyKey, propertyValue)); } public List getChildrenQualifiers(String qualifier) { @@ -135,4 +163,5 @@ public final class ResourceTypes implements BatchComponent, ServerComponent { public ResourceTypeTree getTree(String qualifier) { return treeByQualifier.get(qualifier); } + } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java index b4faa05c679..8339d272ce9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java @@ -49,7 +49,7 @@ import java.util.Map; * @since 2.3 */ public final class XMLRuleParser implements ServerComponent { - private final static Map TYPE_MAP = typeMapWithDeprecatedValues(); + private static final Map TYPE_MAP = typeMapWithDeprecatedValues(); public List parse(File file) { Reader reader = null;