Better local variable names

This commit is contained in:
Benedikt Ritter 2017-04-17 12:01:54 +02:00
parent cd05fddd4f
commit 3c89994355
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
1 changed files with 19 additions and 18 deletions

View File

@ -123,33 +123,34 @@ public static Locale toLocale(final String str) {
return new Locale(StringUtils.EMPTY, str.substring(1, 3), str.substring(4));
}
final String[] split = str.split("_", -1);
final int occurrences = split.length -1;
switch (occurrences) {
final String[] segments = str.split("_", -1);
final int segmentCount = segments.length -1;
final String country = segments[0];
switch (segmentCount) {
case 0:
if (StringUtils.isAllLowerCase(str) && (len == 2 || len == 3)) {
return new Locale(str);
}
throw new IllegalArgumentException("Invalid locale format: " + str);
throw new IllegalArgumentException("Invalid locale format: " + str);
case 1:
if (StringUtils.isAllLowerCase(split[0]) &&
(split[0].length() == 2 || split[0].length() == 3) &&
(split[1].length() == 2 && StringUtils.isAllUpperCase(split[1])) ||
(split[1].length() == 3 && StringUtils.isNumeric(split[1]))) {
return new Locale(split[0], split[1]);
if (StringUtils.isAllLowerCase(country) &&
(country.length() == 2 || country.length() == 3) &&
(segments[1].length() == 2 && StringUtils.isAllUpperCase(segments[1])) ||
(segments[1].length() == 3 && StringUtils.isNumeric(segments[1]))) {
return new Locale(country, segments[1]);
}
throw new IllegalArgumentException("Invalid locale format: " + str);
throw new IllegalArgumentException("Invalid locale format: " + str);
case 2:
if (StringUtils.isAllLowerCase(split[0]) &&
(split[0].length() == 2 || split[0].length() == 3) &&
(split[1].length() == 0 || split[1].length() == 2 && StringUtils.isAllUpperCase(split[1])) &&
split[2].length() > 0) {
return new Locale(split[0], split[1], split[2]);
if (StringUtils.isAllLowerCase(country) &&
(country.length() == 2 || country.length() == 3) &&
(segments[1].length() == 0 || segments[1].length() == 2 && StringUtils.isAllUpperCase(segments[1])) &&
segments[2].length() > 0) {
return new Locale(country, segments[1], segments[2]);
}
//$FALL-THROUGH$
//$FALL-THROUGH$
default:
throw new IllegalArgumentException("Invalid locale format: " + str);
}