|
17 | 17 |
|
18 | 18 | import java.nio.file.Path;
|
19 | 19 | import java.util.ArrayList;
|
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.LinkedHashMap; |
20 | 22 | import java.util.List;
|
21 | 23 | import java.util.Objects;
|
22 | 24 | import java.util.Optional;
|
@@ -121,36 +123,34 @@ static ProfileFileSupplier aggregate(ProfileFileSupplier... suppliers) {
|
121 | 123 | return new ProfileFileSupplier() {
|
122 | 124 |
|
123 | 125 | final AtomicReference<ProfileFile> currentAggregateProfileFile = new AtomicReference<>();
|
124 |
| - final ConcurrentHashMap<Supplier<ProfileFile>, ProfileFile> currentValuesBySupplier = new ConcurrentHashMap<>(); |
| 126 | + final HashMap<Supplier<ProfileFile>, ProfileFile> currentValuesBySupplier = new LinkedHashMap<>(); |
125 | 127 |
|
126 | 128 | @Override
|
127 | 129 | public ProfileFile get() {
|
128 | 130 | boolean refreshAggregate = false;
|
129 |
| - List<ProfileFile> nextValues = new ArrayList<>(suppliers.length); |
130 | 131 | for (ProfileFileSupplier supplier : suppliers) {
|
131 |
| - if (didSuppliedValueChange(supplier, nextValues)) { |
| 132 | + if (didSuppliedValueChange(supplier)) { |
132 | 133 | refreshAggregate = true;
|
133 | 134 | }
|
134 | 135 | }
|
135 | 136 |
|
136 | 137 | if (refreshAggregate) {
|
137 |
| - refreshCurrentAggregate(nextValues); |
| 138 | + refreshCurrentAggregate(); |
138 | 139 | }
|
139 | 140 |
|
140 | 141 | return currentAggregateProfileFile.get();
|
141 | 142 | }
|
142 | 143 |
|
143 |
| - private boolean didSuppliedValueChange(Supplier<ProfileFile> supplier, List<ProfileFile> nextValues) { |
| 144 | + private synchronized boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) { |
144 | 145 | ProfileFile next = supplier.get();
|
145 |
| - nextValues.add(next); |
146 | 146 | ProfileFile current = currentValuesBySupplier.put(supplier, next);
|
147 | 147 |
|
148 | 148 | return !Objects.equals(next, current);
|
149 | 149 | }
|
150 | 150 |
|
151 |
| - private void refreshCurrentAggregate(List<ProfileFile> nextValues) { |
| 151 | + private void refreshCurrentAggregate() { |
152 | 152 | ProfileFile.Aggregator aggregator = ProfileFile.aggregator();
|
153 |
| - nextValues.forEach(aggregator::addFile); |
| 153 | + currentValuesBySupplier.values().forEach(aggregator::addFile); |
154 | 154 | ProfileFile current = currentAggregateProfileFile.get();
|
155 | 155 | ProfileFile next = aggregator.build();
|
156 | 156 | if (!Objects.equals(current, next)) {
|
|
0 commit comments