Skip to content

Commit

Permalink
Collect to named contributors to LinkedHashMap
Browse files Browse the repository at this point in the history
Update `NamedContributorsMapAdapter` to collect items to a
`LinkedHashMap` rather than a `HashMap`.

See gh-31676
  • Loading branch information
philwebb committed Jul 27, 2022
1 parent a4bafa8 commit 2709f77
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -18,10 +18,10 @@

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.util.Assert;

Expand All @@ -43,8 +43,9 @@ abstract class NamedContributorsMapAdapter<V, C> implements NamedContributors<C>
Assert.notNull(map, "Map must not be null");
Assert.notNull(valueAdapter, "ValueAdapter must not be null");
map.keySet().forEach(this::validateKey);
this.map = Collections.unmodifiableMap(map.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, (entry) -> adapt(entry.getValue(), valueAdapter))));
this.map = Collections.unmodifiableMap(map.entrySet().stream().collect(LinkedHashMap::new,
(result, entry) -> result.put(entry.getKey(), adapt(entry.getValue(), valueAdapter)), Map::putAll));

}

private void validateKey(String value) {
Expand Down

0 comments on commit 2709f77

Please sign in to comment.