|
17 | 17 | */
|
18 | 18 | package ru.mystamps.web.service;
|
19 | 19 |
|
| 20 | +import java.util.Arrays; |
20 | 21 | import java.util.Collections;
|
21 |
| -import java.util.HashSet; |
22 | 22 | import java.util.List;
|
23 | 23 | import java.util.Set;
|
24 | 24 | import java.util.regex.Matcher;
|
25 | 25 | import java.util.regex.Pattern;
|
| 26 | +import java.util.stream.Collectors; |
26 | 27 |
|
27 | 28 | import org.apache.commons.lang3.StringUtils;
|
28 | 29 |
|
@@ -82,8 +83,9 @@ protected List<Integer> extractCategory(String fragment) {
|
82 | 83 | log.debug("Determining category from a fragment: '{}'", fragment);
|
83 | 84 |
|
84 | 85 | String[] candidates = StringUtils.split(fragment, "\n\t ,");
|
85 |
| - Set<String> uniqueCandidates = new HashSet<>(); |
86 |
| - Collections.addAll(uniqueCandidates, candidates); |
| 86 | + Set<String> uniqueCandidates = Arrays.stream(candidates) |
| 87 | + .distinct() |
| 88 | + .collect(Collectors.toSet()); |
87 | 89 |
|
88 | 90 | log.debug("Possible candidates: {}", uniqueCandidates);
|
89 | 91 |
|
@@ -115,8 +117,9 @@ protected List<Integer> extractCountry(String fragment) {
|
115 | 117 | log.debug("Determining country from a fragment: '{}'", fragment);
|
116 | 118 |
|
117 | 119 | String[] candidates = StringUtils.split(fragment, "\n\t ,");
|
118 |
| - Set<String> uniqueCandidates = new HashSet<>(); |
119 |
| - Collections.addAll(uniqueCandidates, candidates); |
| 120 | + Set<String> uniqueCandidates = Arrays.stream(candidates) |
| 121 | + .distinct() |
| 122 | + .collect(Collectors.toSet()); |
120 | 123 |
|
121 | 124 | log.debug("Possible candidates: {}", uniqueCandidates);
|
122 | 125 |
|
|
0 commit comments