commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [1/6] [lang] Better local variable names
Date Mon, 17 Apr 2017 10:52:01 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master cd05fddd4 -> dfecbe970


Better local variable names


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/3c899943
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/3c899943
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/3c899943

Branch: refs/heads/master
Commit: 3c89994355f3574078c832b2dcacba0e65e87ed1
Parents: cd05fdd
Author: Benedikt Ritter <britter@apache.org>
Authored: Mon Apr 17 12:01:54 2017 +0200
Committer: Benedikt Ritter <britter@apache.org>
Committed: Mon Apr 17 12:01:54 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/LocaleUtils.java   | 37 ++++++++++----------
 1 file changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/3c899943/src/main/java/org/apache/commons/lang3/LocaleUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
index f13b52f..a2f01ec 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -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);
         }


Mime
View raw message