diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-12 14:53:59 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-12 17:10:56 +0100 |
commit | e93851854a5ab728fba5e83b81b7a4a24208481a (patch) | |
tree | 02e3450c14a1061733da258c1e669aae671a4195 | |
parent | 9e5166d40483c1dd7815edc76f91468c144ebbe3 (diff) | |
download | sonarqube-e93851854a5ab728fba5e83b81b7a4a24208481a.tar.gz sonarqube-e93851854a5ab728fba5e83b81b7a4a24208481a.zip |
Refactor a bit ComponentContainer
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java index 3d01d8f482e..6e7d1161bb4 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java @@ -22,6 +22,7 @@ package org.sonar.core.platform; import com.google.common.collect.Iterables; import java.lang.annotation.Annotation; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import javax.annotation.Nullable; import org.picocontainer.Characteristics; @@ -41,6 +42,9 @@ import org.sonar.api.server.ServerSide; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; +import static com.google.common.collect.ImmutableList.copyOf; +import static java.util.Objects.requireNonNull; + @BatchSide @ServerSide public class ComponentContainer implements ContainerPopulator.Container { @@ -270,10 +274,14 @@ public class ComponentContainer implements ContainerPopulator.Container { } public ComponentContainer removeChild(ComponentContainer childToBeRemoved) { - for (ComponentContainer child : children) { + requireNonNull(childToBeRemoved); + Iterator<ComponentContainer> childrenIterator = children.iterator(); + while (childrenIterator.hasNext()) { + ComponentContainer child = childrenIterator.next(); if (child == childToBeRemoved) { - pico.removeChildContainer(child.pico); - children.remove(child); + if (pico.removeChildContainer(child.pico)) { + childrenIterator.remove(); + } break; } } @@ -281,10 +289,13 @@ public class ComponentContainer implements ContainerPopulator.Container { } private ComponentContainer removeChildren() { - for (ComponentContainer child : children) { - pico.removeChildContainer(child.pico); + Iterator<ComponentContainer> childrenIterator = children.iterator(); + while (childrenIterator.hasNext()) { + ComponentContainer child = childrenIterator.next(); + if (pico.removeChildContainer(child.pico)) { + childrenIterator.remove(); + } } - children.clear(); return this; } @@ -310,7 +321,7 @@ public class ComponentContainer implements ContainerPopulator.Container { } public List<ComponentContainer> getChildren() { - return children; + return copyOf(children); } public MutablePicoContainer getPicoContainer() { |