File tree 4 files changed +113
-7
lines changed
main/java/fr/free/nrw/commons
test/kotlin/fr/free/nrw/commons
4 files changed +113
-7
lines changed Original file line number Diff line number Diff line change @@ -235,11 +235,8 @@ public Single<Media> getPictureOfTheDay() {
235
235
236
236
return Single .fromCallable (() -> {
237
237
Response response = okHttpClient .newCall (request ).execute ();
238
- if (response != null && response .body () != null && response .isSuccessful ()) {
238
+ if (response .body () != null && response .isSuccessful ()) {
239
239
String json = response .body ().string ();
240
- if (json == null ) {
241
- return null ;
242
- }
243
240
MwQueryResponse mwQueryPage = gson .fromJson (json , MwQueryResponse .class );
244
241
return Media .from (mwQueryPage .query ().firstPage ());
245
242
}
Original file line number Diff line number Diff line change 1
1
package fr .free .nrw .commons .utils ;
2
2
3
3
import java .util .ArrayList ;
4
- import java .util .Arrays ;
5
4
import java .util .List ;
6
5
import java .util .regex .Matcher ;
7
6
import java .util .regex .Pattern ;
@@ -34,8 +33,17 @@ public static ArrayList<String> extractCategories(String source) {
34
33
* @return
35
34
*/
36
35
public static List <String > extractCategoriesFromList (String source ) {
37
- String [] categories = source .split ("\\ |" );
38
- return Arrays .asList (categories );
36
+ if (StringUtils .isNullOrWhiteSpace (source )) {
37
+ return new ArrayList <>();
38
+ }
39
+ String [] cats = source .split ("\\ |" );
40
+ List <String > categories = new ArrayList <>();
41
+ for (String category : cats ) {
42
+ if (!StringUtils .isNullOrWhiteSpace (category .trim ())) {
43
+ categories .add (category );
44
+ }
45
+ }
46
+ return categories ;
39
47
}
40
48
41
49
}
You can’t perform that action at this time.
0 commit comments