File tree 2 files changed +23
-2
lines changed
main/java/ru/mystamps/web/service
test/groovy/ru/mystamps/web/service
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 24
24
import java .util .regex .Matcher ;
25
25
import java .util .regex .Pattern ;
26
26
import java .util .stream .Collectors ;
27
+ import java .util .stream .Stream ;
27
28
28
29
import org .apache .commons .lang3 .StringUtils ;
29
30
@@ -145,8 +146,18 @@ protected List<Integer> extractCountry(String fragment) {
145
146
146
147
log .debug ("Determining country from a fragment: '{}'" , fragment );
147
148
148
- String [] names = StringUtils .split (fragment , "\n \t ,." );
149
- List <String > candidates = Arrays .stream (names )
149
+ String [] words = StringUtils .split (fragment , "\n \t ,." );
150
+
151
+ Stream <String > names = Arrays .stream (words );
152
+
153
+ // Generate more candidates by split their names by a hyphen.
154
+ // For example: "Minerals-Maldives" becomes [ "Minerals", "Maldives" ]
155
+ Stream <String > additionalNames = Arrays .stream (words )
156
+ .filter (el -> el .contains ("-" ))
157
+ .map (el -> StringUtils .split (el , '-' ))
158
+ .flatMap (Arrays ::stream );
159
+
160
+ List <String > candidates = Stream .concat (names , additionalNames )
150
161
.filter (SeriesInfoExtractorServiceImpl ::validCountryName )
151
162
.distinct ()
152
163
.limit (MAX_CANDIDATES_FOR_LOOKUP )
Original file line number Diff line number Diff line change @@ -149,6 +149,16 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
149
149
1 * countryService. findIdsByNames(expectedCandidates) >> Random . listOfIntegers()
150
150
}
151
151
152
+ def ' extractCountry() should generate additional candidates by split words by a hyphen' () {
153
+ given :
154
+ String fragment = ' foo-bar'
155
+ List<String > expectedCandidates = [ ' foo-bar' , ' foo' , ' bar' ]
156
+ when :
157
+ service. extractCountry(fragment)
158
+ then :
159
+ 1 * countryService. findIdsByNames(expectedCandidates) >> Random . listOfIntegers()
160
+ }
161
+
152
162
def ' extractCountry() should try to search country names with candidate as a prefix' () {
153
163
given :
154
164
List<Integer > expectedResult = Random . listOfIntegers()
You can’t perform that action at this time.
0 commit comments