commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [40/50] [lang] Replace switch statement with if-else block
Date Mon, 17 Apr 2017 12:20:03 GMT
Replace switch statement with if-else block


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

Branch: refs/heads/release
Commit: 8f54030347e31e0b1492fe874a1f1b67b89b836a
Parents: d3146a5
Author: Benedikt Ritter <britter@apache.org>
Authored: Mon Apr 17 12:31:34 2017 +0200
Committer: Benedikt Ritter <britter@apache.org>
Committed: Mon Apr 17 12:31:34 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/LocaleUtils.java   | 38 ++++++++------------
 1 file changed, 15 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8f540303/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 58eb21b..515443d 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -137,31 +137,23 @@ public class LocaleUtils {
         final String[] segments = str.split("_", -1);
         final int segmentCount = segments.length -1;
         final String language = segments[0];
-        switch (segmentCount) {
-            case 0:
-                if (isISO639LanguageCode(str)) {
-                    return new Locale(str);
-                }
-                throw new IllegalArgumentException("Invalid locale format: " + str);
-
-            case 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:
-                if (isISO639LanguageCode(language) &&
+        if (segmentCount == 0) {
+            if (isISO639LanguageCode(str)) {
+                return new Locale(str);
+            }
+        } else if (segmentCount == 1) {
+            if (isISO639LanguageCode(language) && isISO3166CountryCode(segments[1])
||
+                    isNumericAreaCode(segments[1])) {
+                return new Locale(language, segments[1]);
+            }
+        } 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);
+                    segments[2].length() > 0) {
+                return new Locale(language, segments[1], segments[2]);
+            }
         }
+        throw new IllegalArgumentException("Invalid locale format: " + str);
     }
 
     /**


Mime
View raw message