Skip to content

Commit 206d87f

Browse files
christophstroblmp911de
authored andcommitted
Preserve order in SetConverter.
This commit fixes an issue where the order of elements in a set is not preserved when converting elements of the set. Closes #1969. Original pull request: #1968.
1 parent 443e37d commit 206d87f

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.redis.connection.convert;
1717

18-
import java.util.HashSet;
1918
import java.util.LinkedHashSet;
2019
import java.util.Set;
2120
import java.util.stream.Collectors;
@@ -24,7 +23,7 @@
2423
import org.springframework.util.Assert;
2524

2625
/**
27-
* Converts a Set of values of one type to a Set of values of another type
26+
* Converts a Set of values of one type to a Set of values of another type preserving item order.
2827
*
2928
* @author Jennifer Hickey
3029
* @author Christoph Strobl
@@ -50,9 +49,7 @@ public SetConverter(Converter<S, T> itemConverter) {
5049
*/
5150
@Override
5251
public Set<T> convert(Set<S> source) {
53-
54-
return source.stream().map(itemConverter::convert)
55-
.collect(Collectors.toCollection(source instanceof LinkedHashSet ? LinkedHashSet::new : HashSet::new));
52+
return source.stream().map(itemConverter::convert).collect(Collectors.toCollection(LinkedHashSet::new));
5653
}
5754

5855
}

0 commit comments

Comments
 (0)