Replace switch statement with if-else block

This commit is contained in:
Benedikt Ritter 2017-04-17 12:31:34 +02:00
parent d3146a5456
commit 8f54030347
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
1 changed files with 15 additions and 23 deletions

View File

@ -137,31 +137,23 @@ private static Locale parseLocale(final String str) {
final String[] segments = str.split("_", -1);
final int segmentCount = segments.length -1;
final String language = segments[0];
switch (segmentCount) {
case 0:
if (segmentCount == 0) {
if (isISO639LanguageCode(str)) {
return new Locale(str);
}
throw new IllegalArgumentException("Invalid locale format: " + str);
case 1:
} else if (segmentCount == 1) {
if (isISO639LanguageCode(language) && isISO3166CountryCode(segments[1]) ||
isNumericAreaCode(segments[1])) {
return new Locale(language, segments[1]);
}
throw new IllegalArgumentException("Invalid locale format: " + str);
case 2:
} else if (segmentCount == 2) {
if (isISO639LanguageCode(language) &&
(segments[1].length() == 0 || isISO3166CountryCode(segments[1])) &&
segments[2].length() > 0) {
return new Locale(language, segments[1], segments[2]);
}
//$FALL-THROUGH$
default:
throw new IllegalArgumentException("Invalid locale format: " + str);
}
throw new IllegalArgumentException("Invalid locale format: " + str);
}
/**