|
35 | 35 | import java.util.Collections; |
36 | 36 | import java.util.Comparator; |
37 | 37 | import java.util.HashSet; |
| 38 | +import java.util.LinkedHashSet; |
38 | 39 | import java.util.List; |
39 | 40 | import java.util.Map; |
40 | 41 | import java.util.Optional; |
| 42 | +import java.util.Set; |
41 | 43 | import java.util.concurrent.ExecutorService; |
42 | 44 | import java.util.concurrent.Executors; |
43 | 45 | import java.util.concurrent.Future; |
@@ -124,11 +126,10 @@ public Channel index(Channel channel) { |
124 | 126 | * @return the created channels |
125 | 127 | */ |
126 | 128 | public List<Channel> indexAll(List<Channel> channels) { |
127 | | - |
128 | 129 | List<Future<List<Channel>>> futures = new ArrayList<>(); |
129 | 130 |
|
130 | 131 | for (int i = 0; i < channels.size(); i += chunkSize) { |
131 | | - List<Channel> chunk = channels.stream().skip(i).limit(chunkSize).collect(Collectors.toList()); |
| 132 | + List<Channel> chunk = channels.stream().skip(i).limit(chunkSize).toList(); |
132 | 133 | futures.add( |
133 | 134 | executor.submit( |
134 | 135 | () -> { |
@@ -232,16 +233,13 @@ public Channel save(Channel channel) { |
232 | 233 | @Override |
233 | 234 | public <S extends Channel> Iterable<S> saveAll(Iterable<S> channels) { |
234 | 235 | List<Future<List<Channel>>> futures = new ArrayList<>(); |
235 | | - List<Channel> channelList = |
236 | | - StreamSupport.stream(channels.spliterator(), false).collect(Collectors.toList()); |
| 236 | + Set<Channel> channelList = |
| 237 | + StreamSupport.stream(channels.spliterator(), false).collect(Collectors.toCollection(LinkedHashSet::new)); |
237 | 238 |
|
238 | 239 | for (int i = 0; i < channelList.size(); i += chunkSize) { |
239 | 240 | List<Channel> chunk = channelList.stream().skip(i).limit(chunkSize).toList(); |
240 | 241 | // Create a list of all channel names |
241 | | - List<String> ids = |
242 | | - StreamSupport.stream(chunk.spliterator(), false) |
243 | | - .map(Channel::getName) |
244 | | - .collect(Collectors.toList()); |
| 242 | + Set<String> ids = chunk.stream().map(Channel::getName).collect(Collectors.toCollection(LinkedHashSet::new)); |
245 | 243 | Map<String, Channel> existingChannels = |
246 | 244 | findAllById(ids).stream().collect(Collectors.toMap(Channel::getName, c -> c)); |
247 | 245 |
|
|
0 commit comments