Remove initial if statement by adding an early return

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

View File

@ -134,14 +134,14 @@ public static Locale toLocale(final String str) {
* @throws IllegalArgumentException if the given String can not be parsed.
*/
private static Locale parseLocale(final String str) {
if (isISO639LanguageCode(str)) {
return new Locale(str);
}
final String[] segments = str.split("_", -1);
final int segmentCount = segments.length -1;
final String language = segments[0];
if (segmentCount == 0) {
if (isISO639LanguageCode(str)) {
return new Locale(str);
}
} else if (segmentCount == 1) {
if (segmentCount == 1) {
if (isISO639LanguageCode(language) && isISO3166CountryCode(segments[1]) ||
isNumericAreaCode(segments[1])) {
return new Locale(language, segments[1]);