commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r619137 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
Date Wed, 06 Feb 2008 20:10:07 GMT
Author: ggregory
Date: Wed Feb  6 12:10:05 2008
New Revision: 619137

URL: http://svn.apache.org/viewvc?rev=619137&view=rev
Log:
Simplify code paths where a statement is unnecessarily nested within an else clause. Also
flip some if/else statements when tests can be expressed more clearly.

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=619137&r1=619136&r2=619137&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Wed Feb  6
12:10:05 2008
@@ -1204,9 +1204,8 @@
     public static boolean containsAny(String str, String searchChars) {
         if (searchChars == null) {
             return false;
-        } else {
-            return containsAny(str, searchChars.toCharArray());
         }
+        return containsAny(str, searchChars.toCharArray());
     }
 
     // IndexOfAnyBut chars
@@ -1665,9 +1664,8 @@
         }
         if (str.length() <= len) {
             return str;
-        } else {
-            return str.substring(0, len);
         }
+        return str.substring(0, len);
     }
 
     /**
@@ -1699,9 +1697,8 @@
         }
         if (str.length() <= len) {
             return str;
-        } else {
-            return str.substring(str.length() - len);
         }
+        return str.substring(str.length() - len);
     }
 
     /**
@@ -1740,9 +1737,8 @@
         }
         if (str.length() <= (pos + len)) {
             return str.substring(pos);
-        } else {
-            return str.substring(pos, pos + len);
         }
+        return str.substring(pos, pos + len);
     }
 
     // SubStringAfter/SubStringBefore
@@ -2018,11 +2014,10 @@
             list.add(str.substring(start, end));
             pos = end + closeLen;
         }
-        if (list.size() > 0) {
-            return (String[]) list.toArray(new String [list.size()]);
-        } else {
+        if (list.isEmpty()) {
             return null;
-        }
+        } 
+        return (String[]) list.toArray(new String [list.size()]);
     }
 
     // Nested extraction
@@ -2507,9 +2502,8 @@
                 }
                 start = ++i;
                 continue;
-            } else {
-                lastMatch = false;
             }
+            lastMatch = false;
             match = true;
             i++;
         }
@@ -2642,9 +2636,8 @@
                     }
                     start = ++i;
                     continue;
-                } else {
-                    lastMatch = false;
                 }
+                lastMatch = false;
                 match = true;
                 i++;
             }
@@ -2664,9 +2657,8 @@
                     }
                     start = ++i;
                     continue;
-                } else {
-                    lastMatch = false;
                 }
+                lastMatch = false;
                 match = true;
                 i++;
             }
@@ -2685,9 +2677,8 @@
                     }
                     start = ++i;
                     continue;
-                } else {
-                    lastMatch = false;
                 }
+                lastMatch = false;
                 match = true;
                 i++;
             }
@@ -3876,9 +3867,8 @@
         }
         if (modified) {
             return buf.toString();
-        } else {
-            return str;
         }
+        return str;
     }
 
     // Overlay
@@ -4013,9 +4003,8 @@
             char ch = str.charAt(0);
             if (ch == CharUtils.CR || ch == CharUtils.LF) {
                 return EMPTY;
-            } else {
-                return str;
             }
+            return str;
         }
 
         int lastIdx = str.length() - 1;
@@ -4098,9 +4087,8 @@
         String sub = str.substring(str.length() - sep.length());
         if (sep.equals(sub)) {
             return str.substring(0, str.length() - sep.length());
-        } else {
-            return str;
         }
+        return str;
     }
 
     /**
@@ -4139,11 +4127,10 @@
      */
     public static String prechomp(String str, String sep) {
         int idx = str.indexOf(sep);
-        if (idx != -1) {
-            return str.substring(idx + sep.length());
-        } else {
+        if (idx == -1) {
             return str;
-        }
+        }             
+        return str.substring(idx + sep.length());
     }
 
     /**
@@ -4160,11 +4147,10 @@
      */
     public static String getPrechomp(String str, String sep) {
         int idx = str.indexOf(sep);
-        if (idx != -1) {
-            return str.substring(0, idx + sep.length());
-        } else {
+        if (idx == -1) {
             return EMPTY;
-        }
+        } 
+        return str.substring(0, idx + sep.length());
     }
 
     // Chopping
@@ -5629,9 +5615,8 @@
             // shortest string and didn't find a match, but the string lengths 
             // vary, so return the length of the shortest string.
             return shortestStrLen;
-        } else {
-            return firstDiff;
         }
+        return firstDiff;
     }
     
     /**
@@ -5676,9 +5661,8 @@
             // all strings were identical
             if (strs[0] == null) {
                 return EMPTY;
-            } else {
-                return strs[0];
             }
+            return strs[0];
         } else if (smallestIndexOfDiff == 0) {
             // there were no common initial characters
             return EMPTY;



Mime
View raw message