diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-29 11:09:09 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-29 11:09:13 +0100 |
commit | d7f6c55d9bbedb86c0addac10c39ad6b3207893e (patch) | |
tree | dc36226b541187c21126f647cde92b180aef1c4e /sonar-db | |
parent | 55e42ef7efda721085d7be809689935f385676fd (diff) | |
download | sonarqube-d7f6c55d9bbedb86c0addac10c39ad6b3207893e.tar.gz sonarqube-d7f6c55d9bbedb86c0addac10c39ad6b3207893e.zip |
SONAR-7129 WS api/components/tree leaves strategy with qualifiers fixed
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java index eb73a9627ce..01e386f91ad 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java @@ -19,8 +19,8 @@ */ package org.sonar.db.component; -import java.util.ArrayList; -import java.util.Arrays; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -29,11 +29,14 @@ import org.sonar.api.resources.ResourceType; import org.sonar.api.resources.ResourceTypeTree; import org.sonar.api.resources.ResourceTypes; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; + public class ResourceTypesRule extends ResourceTypes { - private final Set<ResourceType> allResourceTypes = new HashSet<>(); - private final Set<ResourceType> rootResourceTypes = new HashSet<>(); - private final List<String> childrenQualifiers = new ArrayList<>(); - private final List<String> leavesQualifiers = new ArrayList<>(); + private Set<ResourceType> allResourceTypes = emptySet(); + private Set<ResourceType> rootResourceTypes = emptySet(); + private List<String> childrenQualifiers = emptyList(); + private List<String> leavesQualifiers = emptyList(); @Override public Collection<ResourceType> getAll() { @@ -46,32 +49,31 @@ public class ResourceTypesRule extends ResourceTypes { } public ResourceTypesRule setRootQualifiers(String... qualifiers) { - rootResourceTypes.clear(); + Set<ResourceType> resourceTypes = new HashSet<>(); for (String qualifier : qualifiers) { - rootResourceTypes.add(ResourceType.builder(qualifier).build()); + resourceTypes.add(ResourceType.builder(qualifier).build()); } + rootResourceTypes = ImmutableSet.copyOf(resourceTypes); return this; } public ResourceTypesRule setLeavesQualifiers(String... qualifiers) { - leavesQualifiers.clear(); - leavesQualifiers.addAll(Arrays.asList(qualifiers)); + leavesQualifiers = ImmutableList.copyOf(qualifiers); return this; } public ResourceTypesRule setChildrenQualifiers(String... qualifiers) { - childrenQualifiers.clear(); - childrenQualifiers.addAll(Arrays.asList(qualifiers)); - + childrenQualifiers = ImmutableList.copyOf(qualifiers); return this; } public ResourceTypesRule setAllQualifiers(String... qualifiers) { - allResourceTypes.clear(); + Set<ResourceType> resourceTypes = new HashSet<>(); for (String qualifier : qualifiers) { - allResourceTypes.add(ResourceType.builder(qualifier).build()); + resourceTypes.add(ResourceType.builder(qualifier).build()); } + allResourceTypes = ImmutableSet.copyOf(resourceTypes); return this; } |