aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-08 22:46:49 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-08 22:46:49 +0200
commit22c56a89235eaa229af5d88e93bdbc26628a07ec (patch)
treec740399ecb19ec9c6b7a373881de75dc174d722b
parent36f0201f8f94e88a897ebcb879eb54710d176660 (diff)
downloadsonarqube-22c56a89235eaa229af5d88e93bdbc26628a07ec.tar.gz
sonarqube-22c56a89235eaa229af5d88e93bdbc26628a07ec.zip
Fix some quality flaws
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/ApplyProjectRolesDecorator.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java59
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java2
3 files changed, 45 insertions, 17 deletions
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<ResourceType> {
+ 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<ResourceType> getAllWithPropertyKey(final String propertyKey) {
- return Collections2.filter(typeByQualifier.values(), new Predicate<ResourceType>() {
- 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<ResourceType> {
+ 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<ResourceType> getAllWithPropertyValue(final String propertyKey, final String propertyValue) {
- return Collections2.filter(typeByQualifier.values(), new Predicate<ResourceType>() {
- 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<ResourceType> {
+ 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<ResourceType> getAllWithPropertyValue(final String propertyKey, final boolean propertyValue) {
- return Collections2.filter(typeByQualifier.values(), new Predicate<ResourceType>() {
- public boolean apply(@Nullable ResourceType input) {
- return input != null && input.getBooleanProperty(propertyKey) == propertyValue;
- }
- });
+ return Collections2.filter(typeByQualifier.values(), new BooleanPropertyValuePredicate(propertyKey, propertyValue));
}
public List<String> 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<String, String> TYPE_MAP = typeMapWithDeprecatedValues();
+ private static final Map<String, String> TYPE_MAP = typeMapWithDeprecatedValues();
public List<Rule> parse(File file) {
Reader reader = null;