|
16 | 16 | import static org.junit.platform.commons.meta.API.Usage.Internal; |
17 | 17 |
|
18 | 18 | import java.util.Collection; |
19 | | -import java.util.LinkedHashMap; |
| 19 | +import java.util.Collections; |
20 | 20 | import java.util.LinkedHashSet; |
21 | 21 | import java.util.Map; |
22 | 22 | import java.util.Optional; |
23 | 23 | import java.util.Set; |
| 24 | +import java.util.concurrent.ConcurrentHashMap; |
24 | 25 | import java.util.function.Predicate; |
25 | 26 |
|
26 | 27 | import org.junit.platform.commons.meta.API; |
|
53 | 54 | @API(Experimental) |
54 | 55 | public final class TestPlan { |
55 | 56 |
|
56 | | - private final Set<TestIdentifier> roots = new LinkedHashSet<>(); |
57 | | - private final Map<String, LinkedHashSet<TestIdentifier>> children = new LinkedHashMap<>(); |
58 | | - private final Map<String, TestIdentifier> allIdentifiers = new LinkedHashMap<>(); |
| 57 | + private final Set<TestIdentifier> roots = Collections.synchronizedSet(new LinkedHashSet<>(4)); |
| 58 | + |
| 59 | + private final Map<String, Set<TestIdentifier>> children = new ConcurrentHashMap<>(32); |
| 60 | + |
| 61 | + private final Map<String, TestIdentifier> allIdentifiers = new ConcurrentHashMap<>(32); |
59 | 62 |
|
60 | 63 | /** |
61 | 64 | * Construct a new {@code TestPlan} from the supplied collection of |
@@ -91,7 +94,8 @@ public void add(TestIdentifier testIdentifier) { |
91 | 94 | allIdentifiers.put(testIdentifier.getUniqueId(), testIdentifier); |
92 | 95 | if (testIdentifier.getParentId().isPresent()) { |
93 | 96 | String parentId = testIdentifier.getParentId().get(); |
94 | | - Set<TestIdentifier> directChildren = children.computeIfAbsent(parentId, key -> new LinkedHashSet<>()); |
| 97 | + Set<TestIdentifier> directChildren = children.computeIfAbsent(parentId, |
| 98 | + key -> Collections.synchronizedSet(new LinkedHashSet<>(16))); |
95 | 99 | directChildren.add(testIdentifier); |
96 | 100 | } |
97 | 101 | else { |
@@ -186,7 +190,7 @@ public long countTestIdentifiers(Predicate<? super TestIdentifier> predicate) { |
186 | 190 | */ |
187 | 191 | public Set<TestIdentifier> getDescendants(TestIdentifier parent) { |
188 | 192 | Preconditions.notNull(parent, "parent must not be null"); |
189 | | - Set<TestIdentifier> result = new LinkedHashSet<>(); |
| 193 | + Set<TestIdentifier> result = new LinkedHashSet<>(16); |
190 | 194 | Set<TestIdentifier> children = getChildren(parent); |
191 | 195 | result.addAll(children); |
192 | 196 | for (TestIdentifier child : children) { |
|
0 commit comments