Skip to content

Commit 8e532ae

Browse files
committed
Update solution to use LinkedHashMap
1 parent e45585b commit 8e532ae

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFileSupplier.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.nio.file.Path;
1919
import java.util.ArrayList;
20+
import java.util.HashMap;
21+
import java.util.LinkedHashMap;
2022
import java.util.List;
2123
import java.util.Objects;
2224
import java.util.Optional;
@@ -121,36 +123,34 @@ static ProfileFileSupplier aggregate(ProfileFileSupplier... suppliers) {
121123
return new ProfileFileSupplier() {
122124

123125
final AtomicReference<ProfileFile> currentAggregateProfileFile = new AtomicReference<>();
124-
final ConcurrentHashMap<Supplier<ProfileFile>, ProfileFile> currentValuesBySupplier = new ConcurrentHashMap<>();
126+
final HashMap<Supplier<ProfileFile>, ProfileFile> currentValuesBySupplier = new LinkedHashMap<>();
125127

126128
@Override
127129
public ProfileFile get() {
128130
boolean refreshAggregate = false;
129-
List<ProfileFile> nextValues = new ArrayList<>(suppliers.length);
130131
for (ProfileFileSupplier supplier : suppliers) {
131-
if (didSuppliedValueChange(supplier, nextValues)) {
132+
if (didSuppliedValueChange(supplier)) {
132133
refreshAggregate = true;
133134
}
134135
}
135136

136137
if (refreshAggregate) {
137-
refreshCurrentAggregate(nextValues);
138+
refreshCurrentAggregate();
138139
}
139140

140141
return currentAggregateProfileFile.get();
141142
}
142143

143-
private boolean didSuppliedValueChange(Supplier<ProfileFile> supplier, List<ProfileFile> nextValues) {
144+
private synchronized boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) {
144145
ProfileFile next = supplier.get();
145-
nextValues.add(next);
146146
ProfileFile current = currentValuesBySupplier.put(supplier, next);
147147

148148
return !Objects.equals(next, current);
149149
}
150150

151-
private void refreshCurrentAggregate(List<ProfileFile> nextValues) {
151+
private void refreshCurrentAggregate() {
152152
ProfileFile.Aggregator aggregator = ProfileFile.aggregator();
153-
nextValues.forEach(aggregator::addFile);
153+
currentValuesBySupplier.values().forEach(aggregator::addFile);
154154
ProfileFile current = currentAggregateProfileFile.get();
155155
ProfileFile next = aggregator.build();
156156
if (!Objects.equals(current, next)) {

0 commit comments

Comments
 (0)