You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/04/17 10:52:05 UTC

[5/6] [lang] Remove initial if statement by adding an early return

Remove initial if statement by adding an early return


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

Branch: refs/heads/master
Commit: f059e5f7fa1ac4a906b5d2e18d72d410bf28fa2d
Parents: 8f54030
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Apr 17 12:33:17 2017 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Apr 17 12:33:17 2017 +0200

----------------------------------------------------------------------
 src/main/java/org/apache/commons/lang3/LocaleUtils.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f059e5f7/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 515443d..861b25d 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -134,14 +134,14 @@ public class LocaleUtils {
      * @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]);