Better local variable names
This commit is contained in:
parent
cd05fddd4f
commit
3c89994355
|
@ -122,34 +122,35 @@ public class LocaleUtils {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue