Skip to content

Commit 97e7f98

Browse files
committed
Fix all split methods to return empty results if input is empty
1 parent ea49a0b commit 97e7f98

4 files changed

Lines changed: 62 additions & 23 deletions

File tree

library/src/main/java/com/proxerme/library/connection/info/entity/Entry.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,31 @@ public String getName() {
187187
*
188188
* @return The genres.
189189
*/
190+
@SuppressWarnings("WrongConstant")
190191
@NonNull
191192
@GenreParameter.Genre
192193
public String[] getGenres() {
193-
//noinspection ResourceType
194-
return genres.split(DELIMITER);
194+
if (genres.isEmpty()) {
195+
return new String[0];
196+
} else {
197+
return genres.split(DELIMITER);
198+
}
195199
}
196200

197201
/**
198202
* Returns an array of fsk names of this entry.
199203
*
200204
* @return An array of fsk names.
201205
*/
206+
@SuppressWarnings("WrongConstant")
202207
@NonNull
203208
@FskParameter.FskConstraint
204209
public String[] getFsk() {
205-
//noinspection WrongConstant
206-
return fsk.split(DELIMITER);
210+
if (fsk.isEmpty()) {
211+
return new String[0];
212+
} else {
213+
return fsk.split(DELIMITER);
214+
}
207215
}
208216

209217
/**

library/src/main/java/com/proxerme/library/connection/info/entity/EntryCore.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import com.proxerme.library.interfaces.IdItem;
1010
import com.proxerme.library.parameters.CategoryParameter.Category;
11-
import com.proxerme.library.parameters.FskParameter;
11+
import com.proxerme.library.parameters.FskParameter.FskConstraint;
1212
import com.proxerme.library.parameters.GenreParameter.Genre;
1313
import com.proxerme.library.parameters.LicenseParameter.License;
1414
import com.proxerme.library.parameters.MediumParameter.Medium;
@@ -145,23 +145,31 @@ public String getName() {
145145
*
146146
* @return The genres.
147147
*/
148+
@SuppressWarnings("WrongConstant")
148149
@NonNull
149150
@Genre
150151
public String[] getGenres() {
151-
//noinspection ResourceType
152-
return genres.split(DELIMITER);
152+
if (genres.isEmpty()) {
153+
return new String[0];
154+
} else {
155+
return genres.split(DELIMITER);
156+
}
153157
}
154158

155159
/**
156160
* Returns an array of fsk names of this entry.
157161
*
158162
* @return An array of fsk names.
159163
*/
164+
@SuppressWarnings("WrongConstant")
160165
@NonNull
161-
@FskParameter.FskConstraint
166+
@FskConstraint
162167
public String[] getFsk() {
163-
//noinspection WrongConstant
164-
return fsk.split(DELIMITER);
168+
if (fsk.isEmpty()) {
169+
return new String[0];
170+
} else {
171+
return fsk.split(DELIMITER);
172+
}
165173
}
166174

167175
/**

library/src/main/java/com/proxerme/library/connection/list/entity/MediaListEntry.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import android.support.annotation.NonNull;
88

99
import com.proxerme.library.interfaces.IdItem;
10+
import com.proxerme.library.parameters.GenreParameter.Genre;
1011
import com.proxerme.library.parameters.MediumParameter.Medium;
1112
import com.proxerme.library.parameters.StateParameter.State;
13+
import com.proxerme.library.parameters.SubDubLanguageParameter.SubDubLanguage;
1214
import com.squareup.moshi.Json;
1315

1416
/**
@@ -119,9 +121,15 @@ public String getName() {
119121
*
120122
* @return The array of genres.
121123
*/
124+
@SuppressWarnings("WrongConstant")
122125
@NonNull
126+
@Genre
123127
public String[] getGenres() {
124-
return genres.split(" ");
128+
if (genres.isEmpty()) {
129+
return new String[0];
130+
} else {
131+
return genres.split(" ");
132+
}
125133
}
126134

127135
/**
@@ -194,9 +202,15 @@ public float getRating() {
194202
*
195203
* @return An array with the languages.
196204
*/
205+
@SuppressWarnings("WrongConstant")
197206
@NonNull
207+
@SubDubLanguage
198208
public String[] getLanguages() {
199-
return languages.split(",");
209+
if (languages.isEmpty()) {
210+
return new String[0];
211+
} else {
212+
return languages.split(",");
213+
}
200214
}
201215

202216
@SuppressWarnings("SimplifiableIfStatement")

library/src/main/java/com/proxerme/library/connection/messenger/entity/Conference.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public Conference[] newArray(int size) {
3232
};
3333

3434
private static final String IMAGE_DELIMITER = ":";
35+
private static final String EMPTY_RESULT = "";
3536

3637
@Json(name = "id")
3738
private String id;
@@ -88,7 +89,7 @@ public Conference(@NonNull String id, @NonNull String topic, @NonNull String cus
8889
this.lastReadMessageId = lastReadMessageId;
8990

9091
if (imageType == null || imageType.isEmpty() || imageId == null || imageType.isEmpty()) {
91-
this.image = "";
92+
this.image = EMPTY_RESULT;
9293
} else {
9394
this.image = imageType + IMAGE_DELIMITER + imageId;
9495
}
@@ -124,12 +125,16 @@ public String getLastReadMessageId() {
124125
*/
125126
@NonNull
126127
public String getImageType() {
127-
String[] split = image.split(IMAGE_DELIMITER);
128-
129-
if (split.length == 2) {
130-
return split[0];
128+
if (image.isEmpty()) {
129+
return EMPTY_RESULT;
131130
} else {
132-
return "";
131+
String[] split = image.split(IMAGE_DELIMITER);
132+
133+
if (split.length == 2) {
134+
return split[0];
135+
} else {
136+
return EMPTY_RESULT;
137+
}
133138
}
134139
}
135140

@@ -141,12 +146,16 @@ public String getImageType() {
141146
@Override
142147
@NonNull
143148
public String getImageId() {
144-
String[] split = image.split(IMAGE_DELIMITER);
145-
146-
if (split.length == 2) {
147-
return split[1];
149+
if (image.isEmpty()) {
150+
return EMPTY_RESULT;
148151
} else {
149-
return "";
152+
String[] split = image.split(IMAGE_DELIMITER);
153+
154+
if (split.length == 2) {
155+
return split[1];
156+
} else {
157+
return EMPTY_RESULT;
158+
}
150159
}
151160
}
152161

0 commit comments

Comments
 (0)